AnsweredAssumed Answered

Relation deleted after aspect update

Question asked by mundi on Dec 30, 2014
Hello,

I have a problem with a relation which is deleted after I added an aspect.
Here is my code:


public Document addAspect(Document document, String aspect) {
   List<Object> aspects = document.getProperty("cmis:secondaryObjectTypeIds").getValues();
   aspects.add(aspect);
   HashMap<String, Object> properties = new HashMap<String, Object>();
   properties.put("cmis:secondaryObjectTypeIds", aspects);
   System.out.println(getRelationships(document));
   //Returns 1 relation
   document = (Document)document.updateProperties(properties);
   System.out.println(getRelationships(document));
   //The relation is deleted
   return document;
}

public List<Document> getRelationships(Document document) {
   if (document == null)
      return null;

   //Initialize variables
   Session session = getAlfResource().getSession();
   OperationContext context = session.getDefaultContext();
   context.setIncludeRelationships(IncludeRelationships.BOTH);
   ObjectType objectType = session.getTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value());

   //Get relationships
   ItemIterable<Relationship> relationships = session.getRelationships(document, true, RelationshipDirection.EITHER, objectType, context);

   //Convert target to alfresco document
   List<Document> result = new ArrayList<Document>();
   while (relationships.iterator().hasNext()) {
      CmisObject cmisObject = relationships.iterator().next();
      if (cmisObject != null) {
         Relationship relationship = (Relationship) cmisObject;
         if (relationship.getTarget() instanceof Document) {
            result.add((Document) relationship.getTarget());
         }
      }
   }

   return result;
}


in the function "addAspect" before the "updateProperties" the relation is existing after the update the relation seems to be deleted.
Has anyone an idea why this is happening? Is there anything wrong with my code?
Thanks in advance.

Outcomes