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);
}
Archive content from product discussions in Italian.
This group is now closed and content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.