09-22-2014 10:57 AM
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");
}
//Estraggo tutti i figli del documento principale
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);
//Creo la relazione bilaterale
Map relProps = new HashMap();
//Dall'allegato verso il documento principale
relProps = new HashMap();
relProps.put("cmis:sourceId", targetObjectId);
relProps.put("cmis:targetId", sourceObjectId);
relProps.put("cmis:objectTypeId", "R:docarea:related");
session.createRelationship(relProps, null, null, null);
//Collego anche il documento allegato ad ogni fratello
//che non sia stato già collegato
if (relationships==null ) {
//Dal documento principale verso l'allegato
relProps = new HashMap();
relProps.put("cmis:sourceId", sourceObjectId);
relProps.put("cmis:targetId", targetObjectId);
relProps.put("cmis:objectTypeId", "R:docarea: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();
//Dall'allegato verso i fratelli se non sono già presenti
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:docarea:related");
session.createRelationship(relProps, null, null, null);
//Riporto anche il documento sui fratelli
relProps = new HashMap();
relProps.put("cmis:sourceId", relatedDocument.getId());
relProps.put("cmis:targetId", targetObjectId);
relProps.put("cmis:objectTypeId", "R:docarea:related");
session.createRelationship(relProps, null, null, null);
}
}
//Dal documento principale verso l'allegato
relProps = new HashMap();
relProps.put("cmis:sourceId", sourceObjectId);
relProps.put("cmis:targetId", targetObjectId);
relProps.put("cmis:objectTypeId", "R:docarea:related");
session.createRelationship(relProps, null, null, null);
}
09-30-2014 06:36 AM
10-16-2014 03:15 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.