08-29-2018 03:59 AM
Hi,
I am currently using CMIS to create documents. I see lot of examples that update for aspect properties or custom properties on the document by updating the properties map and passing it to createDocument API
Do these documents need to have any aspect associated upfront before I set a custom property?
I am currently setting a custom property but I get the below error
ObjectId idOfCheckedOutDocument = currentDocument.checkOut();
pwc = (Document) session.getObject(idOfCheckedOutDocument);
ByteArrayInputStream stream = new ByteArrayInputStream(newContent);
ContentStream contentStream = session.getObjectFactory().createContentStream(documentName, Long.valueOf(newContent.length), mimeType, stream);
ObjectId objectId = pwc.checkIn(true, properties, contentStream, "New version of document");
I had set the properties map with a custom property but I get the below exception . Is this because an aspect type s not associated to the document at some hierarchy?
Exception in thread "main" java.lang.IllegalArgumentException: Property 'myaspect:docStatus' is not valid for this type or one of the secondary types!
at org.apache.chemistry.opencmis.client.runtime.repository.ObjectFactoryImpl.convertProperties(ObjectFactoryImpl.java:488)
at org.apache.chemistry.opencmis.client.runtime.AbstractCmisObject.updateProperties(AbstractCmisObject.java:405)
Thanks
08-29-2018 06:09 AM
Add also your prefix to property name, something like "custom:classification"
Sample for Alfresco available at: https://gist.github.com/jpotts/7242070
08-29-2018 04:25 AM
You must set the secondary type (aspect) before setting the properties.
https://chemistry.apache.org/docs/cmis-samples/samples/properties/index.html#setting-secondary-types
08-29-2018 06:06 AM
Hi Angel Borroy - Thanks a lot for the link.
What will happen if I have two secondary types with different namespace but the same property name. In the below example from the link that you have provided, the secondary type gets added with namespaceropertyname but when the property is set it is set without the namespace. So if I have two namespace custom1 and custom2 and they have property called classification, how do I set it in the properties for both these namespaces
Map<String, Object> properties = new HashMap<String, Object>();
// add the new secondary type
secondaryTypes.add("custom:classification");
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypes); // set secondary type property
properties.put("classification", "public");
08-29-2018 06:09 AM
Add also your prefix to property name, something like "custom:classification"
Sample for Alfresco available at: https://gist.github.com/jpotts/7242070
08-30-2018 11:58 AM
This is how I am doing while uploading a document with properties. Sometimes the version of CMIS API might matter to the way we do things. I am using CMIS 1.1
My pom dependency
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-api</artifactId>
<version>0.13.0</version>
</dependency>
And my CMIS API endpoint
ttp://alfresco-server:8180/alfresco/api/-default-/public/cmis/versions/1.1/atom
Code extract:
HashMap<String, Object> cmisDocumentProperties = new HashMap<String, Object>();
cmisDocumentProperties.put("cmisbjectTypeId", "D:slo:mdocument");
List<String> secondaryTypes = new ArrayList<String>();
secondaryTypes.add("P:slo:documentProperties");
cmisDocumentProperties.put("cmis:secondaryObjectTypeIds", secondaryTypes);
cmisDocumentProperties.put("slo:m_link", value);
cmisDocumentProperties.put("slo:m_category", value);
InputStream stream = null;
byte[] content = mDocument.getBData();
stream = new ByteArrayInputStream(content);
ContentStream contentStream = cmisSession.getObjectFactory().createContentStream(
mDocument.getFileName(), Long.valueOf(content.length), mimeType, stream);
insertedDocument = entityFolder.createDocument(cmisDocumentProperties, contentStream, VersioningState.MAJOR);
My custom model xml:
<types>
<!-- custom document type -->
<type name="slo:mdocument">
<title>SLO Document type</title>
<parent>cm:content</parent>
<!-- associations section - no associations as of now -->
<!-- aspect is defined to hold all the properties -->
<mandatory-aspects>
<aspect>slo:documentProperties</aspect>
</mandatory-aspects>
</type>
</types>
<aspects>
<!-- There is one aspect with all the custom properties defined -->
<aspect name="slo:documentProperties">
<title>m document properties</title>
<properties>
<property name="slo:m_category">
<title>Category</title>
<type>d:text</type>
</property>
<property name="slo:m_link">
<title>Link ID</title>
<type>d:int</type>
</property>
....
Hope this helps.
Explore our Alfresco products with the links below. Use labels to filter content by product module.