cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Relationships

gclaussn
Champ in-the-making
Champ in-the-making
Hey guys.

I'm actual trying to create a relationship between two documents via OpenCMIS. But it is not working, getting the error message "Relationship type cmis:relationship is not creatable". Using Alfresco 3.3

Is it really the fact, that creating a relationship with CMIS is not possible?
3 REPLIES 3

julio_melo
Champ in-the-making
Champ in-the-making
You have to specify another association type, since cmis:relationship is defined as not creatabled. All associations defined in types on Alfresco's content model is mapped as an inherited relationship from cmis:relationship.

I tested this by creating two documents of type "ws:article" (embedded in Alfresco) and associating them through "ws:relatedArticles" (defined on that type) using the code below on Alfresco 3.4.b and OpenCMIS 0.1.0.


      HashMap<String, Object> prop1 = new HashMap<String, Object>();
      prop1.put(PropertyIds.NAME , "Test 1");
      prop1.put(PropertyIds.OBJECT_TYPE_ID, "D:ws:article");

      HashMap<String, Object> prop2 = new HashMap<String, Object>();
      prop2.put(PropertyIds.NAME , "Test 2");
      prop2.put(PropertyIds.OBJECT_TYPE_ID, "D:ws:article");

      Folder folder = (Folder) session.getObjectByPath("/");

      Document doc1 = folder.createDocument(prop1, null, null, null, null, null, session.getDefaultContext());
      Document doc2 = folder.createDocument(prop2, null, null, null, null, null, session.getDefaultContext());

      Map<String, String> relProps = new HashMap<String, String>();
      relProps.put("cmis:sourceId", doc1.getId());
      relProps.put("cmis:targetId", doc2.getId());
      relProps.put("cmis:objectTypeId", "R:ws:relatedArticles");
      session.createRelationship(relProps, null, null, null);

I don't know if it is possible to create a relationship using an association from an aspect definition. Anyone have any clues?

gclaussn
Champ in-the-making
Champ in-the-making
Sounds good, thank you 🙂

julio_melo
Champ in-the-making
Champ in-the-making
ERRATA:

I just figured out that not all associations are mapped as cmis:relationship descendant.

According to org.alfresco.cmis.mapping.CMISMapping.isValidCmisRelationship(…) javadoc, a valid association in cmis "must be a non-child relationship and the source and target must both be valid". A "valid source and target" in its source code means that their class must be either a document or a folder.