cancel
Showing results for 
Search instead for 
Did you mean: 

Create associations to custom object types

danneex
Champ in-the-making
Champ in-the-making
Hello,

i'm trying to create associations using CMIS on Java.

my "model.xml" is this:
<aspect name="myCustomSpaceName:expediente">
         <title>Associate to expedient</title>
         <associations>
            <association name="myCustomSpaceName:clientsProduct">
               <title>Associated customers</title>
               <source>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </source>
               <target>
                 <class>myCustomSpaceName:cliente</class>
                 <mandatory>false</mandatory>
                 <many>true</many>
               </target>
            </association>
         </associations>
      </aspect>

If I do the association using JavaScript I have not problem:

var expediente = companyhome.childByNamePath("/Delegaciones/0001 - Barcelona/Negocio/Expedientes/EXPH100001");
var cliente = companyhome.childByNamePath("/Delegaciones/0001 - Barcelona/Negocio/Clientes/12345678N");
expediente.createAssociation(cliente, "myCustomSpaceName:clientsProduct");
This code works fine.

But I need to create the association using CMIS. But if I use CMIS on Java (using Apache Chemistry 0.6.0 client libraries), I can't do it. After I connect successfully using Session class, I'm triyng to do the association with this Java Code:

Folder carpetaExpediente = (Folder)session.getObjectByPath("/Delegaciones/0001 - Barcelona/Negocio/Expedientes/EXPH100001");
Folder carpetaCliente = (Folder)session.getObjectByPath("/Delegaciones/0001 - Barcelona/Negocio/Clientes/12345678N");
Map<String, String> propiedades = new HashMap<String, String>();
propiedades.put(PropertyIds.SOURCE_ID, carpetaExpediente.getId());
propiedades.put(PropertyIds.TARGET_ID, carpetaCliente.getId());
propiedades.put(PropertyIds.OBJECT_TYPE_ID, "myCustomSpaceName:clientsProduct");
//I try also with propiedades.put(PropertyIds.OBJECT_TYPE_ID, "R:myCustomSpaceName:clientsProduct"); but do not works.
session.createRelationship(propiedades, null, null, null);

I obtain the next stack trace:

org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException: Bad Request
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:423)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:570)
   at org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.createRelationship(ObjectServiceImpl.java:237)
   at org.apache.chemistry.opencmis.client.runtime.SessionImpl.createRelationship(SessionImpl.java:805)
   at es.privatbank.alfresco.CMISPrivatTest.crearAsociacionEnCarpeta(CMISPrivatTest.java:243)
   at es.privatbank.alfresco.CMISPrivatTest.test(CMISPrivatTest.java:56)
   at es.privatbank.alfresco.CMISPrivatTest.main(CMISPrivatTest.java:36)

Someone can help me?

Pleaseeee!! I can't solve the problem!!
3 REPLIES 3

mitpatoliya
Star Collaborator
Star Collaborator
I think this post could help you
https://forums.alfresco.com/en/viewtopic.php?f=45&t=27219

Also there is one more problem in your code.
If you want to create association then some where in your code you have to use both the references of folder altogether.
O/W how does it takes which folder to be associated with which one.

danneex
Champ in-the-making
Champ in-the-making
I think this post could help you
https://forums.alfresco.com/en/viewtopic.php?f=45&t=27219

Also there is one more problem in your code.
If you want to create association then some where in your code you have to use both the references of folder altogether.
O/W how does it takes which folder to be associated with which one.

Thank you mitpatoliya for your response!!

But I don't understand very good your utterance. Could you be more specific with this phrase?
Also there is one more problem in your code.
If you want to create association then some where in your code you have to use both the references of folder altogether.
O/W how does it takes which folder to be associated with which one.

jpotts
World-Class Innovator
World-Class Innovator
I don't see anything wrong with your code after a quick scan. Note that the relationship name definitely needs to be "R:myCustomSpaceName:clientsProduct".

Can you create two fresh objects you haven't tested with and try again using the "R:myCustomSpaceName:clientsProduct" name for the relationship?

Jeff