Hi Andreu,

It is possible but there are 2 parts to doing this. Firstly, you need to be 
using the Alfresco CMIS extensions (this handles the Alfresco concept of 
aspects for you). Secondly, when trying to set properties defined on an aspect 
you need to provide the list of the aspects to apply in the ObjectTypeId 
property.

We have some documentation on how to do exactly what you want here: 
http://docs.alfresco.com/4.1/concepts/opencmis-ext-intro.html

Also please note, if you are using Alfresco 4.2 or above you can use the CMIS 
1.1 binding which has native support for “aspects”, known in CMIS as secondary 
types.

Hope this helps,

Gavin Cornwell
Engineering Manager – Content Services Practice
Alfresco Software Inc.


From: Andreu Serra
Reply-To: "dev@chemistry.apache.org<mailto:dev@chemistry.apache.org>"
Date: Wednesday, 20 May 2015 16:10
To: "dev@chemistry.apache.org<mailto:dev@chemistry.apache.org>"
Subject: Set CmisExtensionElement value with Apache Chemistry libs

Hi, it´s the first time I use Alfresco. I have to save a custom object with 
extended properties defined. Im able to upload a document to the repository, 
and then, see the list of Aspects and properties, but i´m not capable to set 
the values before saving the document. (setting them in the ContentStream as a 
list of CmisExtensionElement), maybe this is not thw way to do this, i´m a 
little lost.

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 properties = new HashMap();
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);
}

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

public static void printMetadataCMISobject(Document docmnt, ExtensionLevel 
eLvl) {

if (eLvl!=null) {

List 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 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=cmis:policyText
16:21:10,512 INFO [STDOUT] - Attribute --> propertyDefinitionId=cmis:policyText
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?

I, ve tried bi setting as a property in the properties Map but alwais gave me 
the error: Property XXX is not valid for this type or one of the secondary 
types!
Also i have tried this code for setting an aspect in the ContentStream before 
saving the document:

             List<CmisExtensionElement> extensions = new 
ArrayList<CmisExtensionElement>();
             String ns = 
System.getProperty("es.caib.regweb.annex.plugins.documentcustody.alfresco.extensions.ns");


               CmisExtensionElement valueElem = new 
CmisExtensionElementImpl(ns, "value", null, "Accounting");

               List<CmisExtensionElement> valueElems = new 
ArrayList<CmisExtensionElement>();

               valueElems.add(valueElem);



               List<CmisExtensionElement> children = new 
ArrayList<CmisExtensionElement>();

               Map<String, String> attributes = new HashMap<String, String>();

               attributes.put("propertyDefinitionId", 
"APBRegistro:dr_obsAlfresco");
               attributes.put("displayName", "Observaciones Alfresco");
               attributes.put("queryName", "APBRegistro:dr_obsAlfresco");
               attributes.put("localName", "dr_obsAlfresco");

               children.add(new CmisExtensionElementImpl(ns, "propertyString", 
attributes, valueElems));



               List<CmisExtensionElement> propertyValuesExtension = new 
ArrayList<CmisExtensionElement>();

               propertyValuesExtension.add(new CmisExtensionElementImpl(ns, 
"properties", null, children));



               CmisExtensionElement setAspectsExtension = new 
CmisExtensionElementImpl(ns, "aspects", null, propertyValuesExtension);

               extensions.add(setAspectsExtension);

               contentStream.setExtensions(extensions);


Thank you in advance.

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

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

       <dependency>
             <groupId>org.apache.chemistry.opencmis</groupId>
             <artifactId>chemistry-opencmis-client-bindings</artifactId>
             <version>0.13.0</version>
       </dependency>

Andreu Serra
Dept. Programació.







[logo degradat fons blanc petit.PNG]                                            
                 Límit Tecnologies S.L.
[EmpresaExcellent]                                                             
C/ Bas 3 - 07500 Manacor
                                                             Tel 971 84 45 53 - 
Fax 971 84 57 73
              
www.limit.es<../../Datos%20de%20programa/Microsoft/Signatures/www.limit.es>
________________________________
Aquest missatge es dirigeix exclusivament al seu destinatari i pot incloure 
dades confidencials i/o de caràcter personal, la difusió de les quals es regula 
mitjançant la Llei orgànica de protecció de dades. Si no sou la persona 
destinatària (o la responsable de lliurar-l’hi), en cap cas heu de copiar 
aquest missatge ni lliurar-lo a terceres persones. Si heu rebut aquest missatge 
per error, us preguem que ens ho comuniqueu immediatament per aquesta mateixa 
via i que l’elimineu de manera permanent.
PAbans d’imprimir aquest missatge, pensi en el medi ambient i asseguri’s que és 
necessari.
Este mensaje se dirige exclusivamente a su destinatario y puede incluir datos 
confidenciales y/o de carácter personal, la difusión de los cuales se regula 
mediante la Ley orgánica de protección de datos. Si no es la persona 
destinataria (o la responsable de entregárselo), en ningún caso debe copiar 
este mensaje ni entregarlo a terceras personas. Si ha recibido este mensaje por 
error, le rogamos que nos lo comunique inmediatamente por esta misma vía y que 
lo elimine de manera permanente.
PAntes de imprimir este mensaje, piense en el medio ambiente y asegúrese que es 
necesario.

Reply via email to