use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project records-management by Alfresco.
the class RelationshipServiceImpl method getAssociationDefinitionName.
/**
* Gets the qualified name of the association definition for the given unique name
*
* @param uniqueName The unique name
* @return The qualified name of the association definition for the given unique name
*/
private QName getAssociationDefinitionName(String uniqueName) {
AssociationDefinition associationDefinition = getAssociationDefinition(uniqueName);
if (associationDefinition == null) {
StringBuilder sb = new StringBuilder();
sb.append("The qualified name for '").append(uniqueName).append("' was not found.");
throw new AlfrescoRuntimeException(sb.toString());
}
return associationDefinition.getName();
}
use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project records-management by Alfresco.
the class RelationshipServiceImpl method getAssociationDefinition.
/**
* Gets the association definition for the given unique name
*
* @param uniqueName The unique name
* @return The association definition for the given unique name if exists, <code>null</code> otherwise
*/
private AssociationDefinition getAssociationDefinition(String uniqueName) {
AssociationDefinition associationDefinition = null;
Set<Entry<QName, AssociationDefinition>> associationsEntrySet = getCustomAssociations().entrySet();
for (Map.Entry<QName, AssociationDefinition> associationEntry : associationsEntrySet) {
String localName = associationEntry.getKey().getLocalName();
if (uniqueName.equals(localName)) {
associationDefinition = associationEntry.getValue();
break;
}
}
return associationDefinition;
}
use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project records-management by Alfresco.
the class RelationshipServiceImpl method getRelationshipDefinitions.
/**
* @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#getRelationshipDefinitions()
*/
@Override
public Set<RelationshipDefinition> getRelationshipDefinitions() {
Set<RelationshipDefinition> relationshipDefinitions = new HashSet<RelationshipDefinition>();
Set<Entry<QName, AssociationDefinition>> associationsEntrySet = getCustomAssociations().entrySet();
for (Map.Entry<QName, AssociationDefinition> associationEntry : associationsEntrySet) {
AssociationDefinition associationDefinition = associationEntry.getValue();
RelationshipDefinition relationshipDefinition = createRelationshipDefinition(associationDefinition);
if (relationshipDefinition != null) {
relationshipDefinitions.add(relationshipDefinition);
}
}
return relationshipDefinitions;
}
use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project records-management by Alfresco.
the class RelationshipServiceImpl method getRelationshipDefinition.
/**
* @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#getRelationshipDefinition(java.lang.String)
*/
@Override
public RelationshipDefinition getRelationshipDefinition(String uniqueName) {
mandatoryString("uniqueName", uniqueName);
RelationshipDefinition relationshipDefinition = null;
AssociationDefinition associationDefinition = getAssociationDefinition(uniqueName);
if (associationDefinition != null) {
relationshipDefinition = createRelationshipDefinition(associationDefinition);
}
return relationshipDefinition;
}
use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project records-management by Alfresco.
the class RelationshipServiceImpl method removeRelationship.
/**
* @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#removeRelationship(java.lang.String, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public void removeRelationship(String uniqueName, NodeRef source, NodeRef target) {
mandatoryString("uniqueName", uniqueName);
mandatory("source", source);
mandatory("target", target);
// Check that the association definition for the given unique name exists.
AssociationDefinition associationDefinition = getAssociationDefinition(uniqueName);
if (associationDefinition == null) {
StringBuilder sb = new StringBuilder();
sb.append("No association definition found for '").append(uniqueName).append("'.");
throw new IllegalArgumentException(sb.toString());
}
// Get the association definition name
final QName associationDefinitionName = associationDefinition.getName();
final NodeRef targetNode = target;
final NodeRef sourceNode = source;
invokeBeforeRemoveReference(sourceNode, targetNode, associationDefinitionName);
if (associationDefinition.isChild()) {
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() {
List<ChildAssociationRef> children = getNodeService().getChildAssocs(sourceNode);
for (ChildAssociationRef chRef : children) {
if (associationDefinitionName.equals(chRef.getTypeQName()) && chRef.getChildRef().equals(targetNode)) {
getNodeService().removeChildAssociation(chRef);
}
}
return null;
}
});
} else {
getNodeService().removeAssociation(source, targetNode, associationDefinitionName);
}
invokeOnRemoveReference(source, targetNode, associationDefinitionName);
}
Aggregations