Consider the following example using the REST API (the Mayan EDMS frontend is not used to modify anything in the following example):
- Add one document type
"Default"
usingPOST /document_types/
(should exist already after default installation). - Add two metadata types
"Required Relation"
(name:"mdt_required"
), “Optional Relation” (name:"mdt_optional"
) and"Unused Relation"
(name:"mdt_unused"
) usingPOST /metadata_types/
. - Add the relations between the document type and the metadata types using
POST /document_types/1/metadata_types/
"mdt_required"
is set to the relation “Required”."mdt_optional"
is set to the relation “Optional”."mdt_unused"
is set to the relation “Required”.
- Create a document with
"document_type_id": 1
and upload a document file usingPOST /documents/upload/
.
One could state that the uploaded document is in an invalid state now, because the following metadata type constraints of the document type are violated:
"mdt_required"
is not assigned (and therefore has no value)."mdt_unused"
is not assigned (and therefore has no value).
The same could be stated for "mdt_optional
" if an optional relation translates to “This metadata type must be assigned to a document of this document type but its value can be empty.” (which is not the case, as far as I understand).
Let us ignore this uncertainty for a moment and proceed to assign and set the metadata type values for the created document.
- Assign the metadata type
"mdt_required"
(a value must be set for it since it is set as “Required”) for the document usingPOST /documents/1/metadata/
- Assign the metadata type
"mdt_optional"
(ommit a value for it, this is possible since it is set as “Optional”) for the document usingPOST /documents/1/metadata/
Note that the metadata type "mdt_unused"
is still not assigned to the document. This is (as mentioned before) a constraint violation of the document type to metadata type relations.
My assumption based this minimal example are:
-
The “Required” relation of a document type technically translates to “The document does not need to have this metadata type assigned. If it has this metadata type assigned its value cannot be empty.”
-
The “Optional” relation of a document type technically translates to “The document does not need to have this metadata type assigned. If it has this metadata type assigned its value can be empty.”
-
It is the responsibility of the developer to add all metadata types that are associated using the relation “Required” with the document type the created document belongs to if using the REST API.
Not doing this does not lead to an error, but introduces an inconsistent state. Compare the document type relation definitions vs. the actual metadata type values of the document.
In other words: It is possible to create documents using the REST API that do not respect the document type relations defined.
-
It does not matter whether the metadata types that are associated using the relation “Optional” with the document type the created document belongs to are added using the REST API or not. Both seems to be consistent regarding other operations, e.g. “Delete Metadata from a Document”.
I assume the metadata types that are defined as “Optional” should be added as well to the document, even if they do not have a value. This ensures consistency with the document type definition.
Are these assumptions correct? Until now I did not fulfill points 3 and 4, i.e. I did not assign each and every metadata type with the document type of the created document. Until now I omitted the metadata values that do not have a value (which seems incorrect due to the points made in this topic).
Note that this does not seem to be a problem if using the default web frontend, due to the fact that the UI ensures that the user fills in all metadata values.
I think some guidance regarding the proper/intended usage of both metadata type relations would be helpful. Note that I could not find anything in the documentation or knowledge base on this detail level.