AnsweredAssumed Answered

Relations between documents

Question asked by fedemori on Sep 24, 2014
Hi,
I need to associate multiple attachments. The association works but is very slow and consequently. more attachments are there and the bigger they are, the slower this feature.
How can I fix the problem?
Following the code
<code>
public static void updateDocumentRelated(Session session, String root, String sourceObjectId, String targetObjectId,long idRepositoryPrincipale,long idRepositoryAllegato) throws Exception {

   Document doc = getDocumentInFolderByidRepository(session, idRepositoryPrincipale, root);
   if (doc==null){
     throw new Exception("Il documento con idRepository " + idRepositoryPrincipale + " non è stato trovato su Alfresco");
   }
   ObjectType typeDefinition = session.getTypeDefinition("R:documento:related");

   OperationContext operationContext = session.createOperationContext();

   RelationshipDirection direction = RelationshipDirection.SOURCE;

   ItemIterable<Relationship> relationships = session.getRelationships(doc,true, direction, typeDefinition, operationContext);
   Map relProps = new HashMap();
   relProps = new HashMap();
   relProps.put("cmis:sourceId", targetObjectId);
   relProps.put("cmis:targetId", sourceObjectId);
   relProps.put("cmis:objectTypeId", "R:documento:related");
   session.createRelationship(relProps, null, null, null);
   if (relationships==null ) {
     relProps = new HashMap();
     relProps.put("cmis:sourceId", sourceObjectId);
     relProps.put("cmis:targetId", targetObjectId);
     relProps.put("cmis:objectTypeId", "R:documento:related");
     session.createRelationship(relProps, null, null, null);
     return;
   }

   Document docAllegato = getDocumentInFolderByidRepository(session, idRepositoryAllegato, root);
   ItemIterable<Relationship> brotherships = session.getRelationships(docAllegato,true, direction, typeDefinition, operationContext);
   for (Relationship relationship : relationships) {
     Document relatedDocument = (Document) relationship.getTarget();
     boolean esiste = false;
     if (brotherships!=null ){
       for (Relationship brothership : brotherships) {
         Document brotherDocument = (Document) brothership.getTarget();
         if (brotherDocument.getId().equals(relatedDocument.getId())) {
            esiste = true;
            break;
         }
       }
     }
     if (!esiste){
       relProps = new HashMap();
       relProps.put("cmis:sourceId", targetObjectId);
       relProps.put("cmis:targetId", relatedDocument.getId());
       relProps.put("cmis:objectTypeId", "R:documento:related");
       session.createRelationship(relProps, null, null, null);
       relProps = new HashMap();
       relProps.put("cmis:sourceId", relatedDocument.getId());
       relProps.put("cmis:targetId", targetObjectId);
       relProps.put("cmis:objectTypeId", "R:documento:related");
       session.createRelationship(relProps, null, null, null);
     }
   }
   relProps = new HashMap();
   relProps.put("cmis:sourceId", sourceObjectId);
   relProps.put("cmis:targetId", targetObjectId);
   relProps.put("cmis:objectTypeId", "R:documento:related");
   session.createRelationship(relProps, null, null, null);
}

Outcomes