Search code examples
alfrescocmisopencmis

Property 'pos:empCode' is not valid for this type or one of the secondary types! error setting custom object in cmis


When I am adding my custom object in map, it gives me error.

java.lang.IllegalArgumentException: Property 'pos:empCode' is not valid for this type or one of the secondary types! at org.apache.chemistry.opencmis.client.runtime.repository.ObjectFactoryImpl.conver tProperties(ObjectFactoryImpl.java:426) at org.apache.chemistry.opencmis.client.runtime.SessionImpl.createDocument(Session Impl.java:1091) at org.apache.chemistry.opencmis.client.runtime.FolderImpl.createDocument(FolderImp l.java:77)

My code is:

    Map<String, Object> metaData = new HashMap<String, Object>(0);
    metaData.put(DocumentConstants.EMPCODE, empCode);
//  metaData.put(DocumentConstants.TYPE, Constants.EMP_FILE_UPLOAD);
//  metaData.put(DocumentConstants.SUBTYPE, Constants.ADD);
    docService.uploadDocumentsForAlfresco(metaData, byteArray, fileName);

DocService:

    public Boolean uploadDocumentsForAlfresco(Map<String, Object> metaData, 
    byte[] data, String name) {
        Session session = connect();
        String folderPath = null;
        folderPath = cmisSite.concat(cmisPath).concat("documentlibrary/");
       //       String path = 
    "DATAFILES/".concat(metaData.get(DocumentConstants.EMPCODE).toString());
    String path = "DATAFILES/".concat("6");
    folderPath = folderPath.concat(path);
    Folder folder = createFolder(session, folderPath); 
// metaData.put(PropertyIds.OBJECT_TYPE_ID, "D:ebs:bulkUploadDoc");
    metaData.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
    // set the alfresco object factory

    metaData.put(PropertyIds.NAME, name);
    ByteArrayInputStream input = new ByteArrayInputStream(data);
    ContentStream contentStream = 
   session.getObjectFactory().createContentStream(name, data.length, 
   "application/octet-stream", input);
    try {
            folder.createDocument(metaData, contentStream, 
    VersioningState.MAJOR);
            return true;
    } catch (Exception ex) {
   //log.error("exception while uploading document",ex);
        ex.printStackTrace();
        return false;
    }
  }

added dependency in pom.xml

   <dependency>
        <groupId>org.alfresco.cmis.client</groupId>
        <artifactId>alfresco-opencmis-extension</artifactId>
        <version>0.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.chemistry.opencmis</groupId>
        <artifactId>chemistry-opencmis-client-impl</artifactId>
        <version>0.13.0</version>
    </dependency>

Solution

  • pos:empCode is a property that is defined on one of your custom types or aspects. You are attempting to set the value of that property on the object, but you've told CMIS that the object type is cmis:document. The cmis:document type maps to cm:content, the out-of-the-box type which does not have your custom property.

    Instead of using cmis:document as the object type ID, use the object type ID of the type from your custom model that defines the pos:empCode property.