cancel
Showing results for 
Search instead for 
Did you mean: 

Set CmisExtensionElement value with Apache Chemistry libs

andreshades
Champ in-the-making
Champ in-the-making
Hi, it´s the first time I use Alfresco. And i have to save a document with extended properties defined. Im able to upload a document to the repository, and then see the list of Extensions, but i´m not capable to set the values before saving the document.

Maybe with the code it becomes clearer:

How I save the document:

public static void createDocument(AnnexCustody document, String fileName, String fileType, String es, String numReg) throws FileNotFoundException {

      Session cmisSession = getCmisSession();
      Folder parentFolder = null;
      String carpetaParePath  = getPathCarpetaDocs()+"/"+FileUtils.getActualYear()+"/"+es+"/"+numReg;
      
      try {
         parentFolder = (Folder) cmisSession.getObjectByPath(carpetaParePath);
      }catch (CmisObjectNotFoundException onfEx) {
         parentFolder = createFoldersPath("/"+FileUtils.getActualYear()+"/"+es+"/"+numReg);
      }

      // properties (minim: name i object type id)
      Map<String, Object> properties = new HashMap<String, Object>();
      properties.put(PropertyIds.OBJECT_TYPE_ID, "D:APBRegistro:anexo");
      properties.put(PropertyIds.NAME, fileName);
      
      byte[] content = document.getData();
      InputStream stream = new ByteArrayInputStream(content);
      ContentStream contentStream = new ContentStreamImpl(fileName, BigInteger.valueOf(content.length), fileType, stream);

                parentFolder.createDocument(properties, contentStream, VersioningState.MAJOR);
}

And this, uploads a custom object into the repository, and then i can list the extensions, with this code:

   public static void printMetadataCMISobject(Document docmnt, ExtensionLevel eLvl) {
      
      if (eLvl!=null) {
      
         List<CmisExtensionElement> extensions = docmnt.getExtensions(eLvl);
   
         System.out.println("#### IMPRIMIENDO EXTENSIONES DEL NIVEL "+eLvl.value() + " ####");
         
         if (extensions!=null) {
         
            for(CmisExtensionElement ext: extensions) {
               
               System.out.println("Extension –> Name: " + ext.getName());
               System.out.println("Extension –> NameSpace: " + ext.getNamespace());
               System.out.println("Extension –> Value: " + ext.getValue());
               
               for(CmisExtensionElement child: ext.getChildren()) {
                  
                  System.out.println(" - Extension Nvl2 –> Clild Name: " + child.getName());
                  System.out.println(" - Extension Nvl2 –> Clild NS: " + child.getNamespace());
                  System.out.println(" - Extension Nvl2 –> Clild Value: " + child.getValue());
                     
                  for(CmisExtensionElement p_child: child.getChildren()) {
                     
                     System.out.println("    - Property –> Clild Name: " + p_child.getName());
                     System.out.println("    - Property –> Clild NS: " + p_child.getNamespace());
                     System.out.println("    - Property –> Clild Value: " + p_child.getValue());
                     
                     Iterator<String> attribs = p_child.getAttributes().keySet().iterator();
                     while(attribs.hasNext()) {
                        String att_key = attribs.next();
                        System.out.println("       - Attribute –> "+att_key+"=" + p_child.getAttributes().get(att_key));
                     }
                  }
               }
            }
         }
         
         System.out.println("#### FIN EXTENSIONES DEL NIVEL "+eLvl.value() + " ####");
      }
   }

Wich generates the following output:

16:21:10,491 INFO  [STDOUT] #### IMPRIMIENDO EXTENSIONES DEL NIVEL properties ####
16:21:10,491 INFO  [STDOUT] Extension –> Name: aspects
16:21:10,491 INFO  [STDOUT] Extension –> NameSpace: http://www.alfresco.org
16:21:10,491 INFO  [STDOUT] Extension –> Value: null
16:21:10,491 INFO  [STDOUT]  - Extension Nvl2 –> Clild Name: appliedAspects
16:21:10,491 INFO  [STDOUT]  - Extension Nvl2 –> Clild NS: http://www.alfresco.org
16:21:10,491 INFO  [STDOUT]  - Extension Nvl2 –> Clild Value: P:cm:thumbnailModification
16:21:10,491 INFO  [STDOUT]  - Extension Nvl2 –> Clild Name: appliedAspects
16:21:10,491 INFO  [STDOUT]  - Extension Nvl2 –> Clild NS: http://www.alfresco.org
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild Value: P:cm:titled
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild Name: appliedAspects
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild NS: http://www.alfresco.org
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild Value: P:cm:author
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild Name: appliedAspects
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild NS: http://www.alfresco.org
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild Value: P:rn:renditioned
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild Name: appliedAspects
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild NS: http://www.alfresco.org
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild Value: P:sys:localized
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild Name: appliedAspects
16:21:10,492 INFO  [STDOUT]  - Extension Nvl2 –> Clild NS: http://www.alfresco.org
16:21:10,502 INFO  [STDOUT]  - Extension Nvl2 –> Clild Value: P:APBRegistro:d_anexo
16:21:10,502 INFO  [STDOUT]  - Extension Nvl2 –> Clild Name: properties
16:21:10,512 INFO  [STDOUT]  - Extension Nvl2 –> Clild NS: http://www.alfresco.org
16:21:10,512 INFO  [STDOUT]  - Extension Nvl2 –> Clild Value: null
16:21:10,512 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,512 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,512 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,512 INFO  [STDOUT]        - Attribute –> localName=policyText
16:21:10,512 INFO  [STDOUT]        - Attribute –> queryName=cmisSmiley TongueolicyText
16:21:10,512 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=cmisSmiley TongueolicyText
16:21:10,512 INFO  [STDOUT]        - Attribute –> displayName=Policy Text
16:21:10,512 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,512 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,512 INFO  [STDOUT]     - Property –> Clild Value: null
16:21:10,512 INFO  [STDOUT]        - Attribute –> localName=lastThumbnailModification
16:21:10,522 INFO  [STDOUT]        - Attribute –> queryName=cm:lastThumbnailModification
16:21:10,522 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=cm:lastThumbnailModification
16:21:10,522 INFO  [STDOUT]        - Attribute –> displayName=Last thumbnail modifcation data
16:21:10,522 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,522 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,522 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,522 INFO  [STDOUT]        - Attribute –> localName=description
16:21:10,522 INFO  [STDOUT]        - Attribute –> queryName=cm:description
16:21:10,522 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=cm:description
16:21:10,522 INFO  [STDOUT]        - Attribute –> displayName=Description
16:21:10,522 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,522 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,522 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,522 INFO  [STDOUT]        - Attribute –> localName=title
16:21:10,522 INFO  [STDOUT]        - Attribute –> queryName=cm:title
16:21:10,522 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=cm:title
16:21:10,522 INFO  [STDOUT]        - Attribute –> displayName=Title
16:21:10,522 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,522 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,522 INFO  [STDOUT]     - Property –> Clild Value: null
16:21:10,522 INFO  [STDOUT]        - Attribute –> localName=author
16:21:10,522 INFO  [STDOUT]        - Attribute –> queryName=cm:author
16:21:10,522 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=cm:author
16:21:10,522 INFO  [STDOUT]        - Attribute –> displayName=Author
16:21:10,522 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,522 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,522 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,522 INFO  [STDOUT]        - Attribute –> localName=dr_validez
16:21:10,532 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_validez
16:21:10,532 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_validez
16:21:10,532 INFO  [STDOUT]        - Attribute –> displayName=Validez
16:21:10,532 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,532 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,532 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,532 INFO  [STDOUT]        - Attribute –> localName=dr_obsAlfresco
16:21:10,532 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_obsAlfresco
16:21:10,532 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_obsAlfresco
16:21:10,532 INFO  [STDOUT]        - Attribute –> displayName=Observaciones Alfresco
16:21:10,532 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,532 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,532 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,532 INFO  [STDOUT]        - Attribute –> localName=dr_tipDocumento
16:21:10,532 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_tipDocumento
16:21:10,532 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_tipDocumento
16:21:10,532 INFO  [STDOUT]        - Attribute –> displayName=Tipo de documento
16:21:10,532 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,532 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,532 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,532 INFO  [STDOUT]        - Attribute –> localName=dr_tipDocumental
16:21:10,532 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_tipDocumental
16:21:10,532 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_tipDocumental
16:21:10,532 INFO  [STDOUT]        - Attribute –> displayName=Tipo documental
16:21:10,532 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,532 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,532 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,542 INFO  [STDOUT]        - Attribute –> localName=dr_formato
16:21:10,542 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_formato
16:21:10,542 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_formato
16:21:10,542 INFO  [STDOUT]        - Attribute –> displayName=Formato
16:21:10,542 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,542 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,542 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,542 INFO  [STDOUT]        - Attribute –> localName=dr_origen
16:21:10,542 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_origen
16:21:10,542 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_origen
16:21:10,542 INFO  [STDOUT]        - Attribute –> displayName=Origen
16:21:10,542 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,542 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,542 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,542 INFO  [STDOUT]        - Attribute –> localName=dr_ofiAnexa
16:21:10,542 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_ofiAnexa
16:21:10,542 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_ofiAnexa
16:21:10,542 INFO  [STDOUT]        - Attribute –> displayName=Oficina que lo anexa
16:21:10,542 INFO  [STDOUT]     - Property –> Clild Name: propertyString
16:21:10,542 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,542 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,542 INFO  [STDOUT]        - Attribute –> localName=dr_obsRegistro
16:21:10,542 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_obsRegistro
16:21:10,542 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_obsRegistro
16:21:10,542 INFO  [STDOUT]        - Attribute –> displayName=Observaciones Registro
16:21:10,542 INFO  [STDOUT]     - Property –> Clild Name: propertyDateTime
16:21:10,542 INFO  [STDOUT]     - Property –> Clild NS: http://docs.oasis-open.org/ns/cmis/core/200908/
16:21:10,542 INFO  [STDOUT]     - Property –> Clild Value:
16:21:10,552 INFO  [STDOUT]        - Attribute –> localName=dr_fecEntrada
16:21:10,552 INFO  [STDOUT]        - Attribute –> queryName=APBRegistro:dr_fecEntrada
16:21:10,552 INFO  [STDOUT]        - Attribute –> propertyDefinitionId=APBRegistro:dr_fecEntrada
16:21:10,552 INFO  [STDOUT]        - Attribute –> displayName=Fecha de entrada en el sistema
16:21:10,552 INFO  [STDOUT] #### FIN EXTENSIONES DEL NIVEL properties ####

How can I set the properties like APBRegistro:dr_fecEntrada or APBRegistro:dr_obsRegistro, before or after upload the document?

Thank you in advance.

Pd.: I´n using chemistry-opencmis-client-impl v0.13.0 with an Alfresco Enterprise 4.2.3.3
1 REPLY 1

andreshades
Champ in-the-making
Champ in-the-making
Here is the solution for mi scenario. Given the custom objects and attributes detailed in the original post:

1.- Include the alfresco opencmis extension lib.

   <dependency>
      <groupId>org.alfresco.cmis.client</groupId>
      <artifactId>alfresco-opencmis-extension</artifactId>
      <version>1.0</version>
   </dependency>

2.- The code:

          Map<String, Object> properties = new HashMap<String, Object>();
      //properties.put(PropertyIds.OBJECT_TYPE_ID, "D:APBRegistro:anexo");
      properties.put(PropertyIds.OBJECT_TYPE_ID, "D:APBRegistro:anexo,P:APBRegistro:d_anexo");
      properties.put(PropertyIds.NAME, fileFinalame);
      properties.put("APBRegistro:dr_obsAlfresco", "HELLOOOO");
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.