Search in sources :

Example 6 with AssociationDefinition

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();
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 7 with AssociationDefinition

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;
}
Also used : Entry(java.util.Map.Entry) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) QName(org.alfresco.service.namespace.QName) ParameterCheck.mandatoryString(org.alfresco.util.ParameterCheck.mandatoryString) Map(java.util.Map)

Example 8 with 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;
}
Also used : Entry(java.util.Map.Entry) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) QName(org.alfresco.service.namespace.QName) Map(java.util.Map) HashSet(java.util.HashSet)

Example 9 with AssociationDefinition

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;
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)

Example 10 with AssociationDefinition

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) QName(org.alfresco.service.namespace.QName) List(java.util.List) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Aggregations

AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)60 QName (org.alfresco.service.namespace.QName)46 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)24 ChildAssociationDefinition (org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)15 HashMap (java.util.HashMap)13 Serializable (java.io.Serializable)11 ArrayList (java.util.ArrayList)11 ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)9 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)6 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 Collection (java.util.Collection)5 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 Pair (org.alfresco.util.Pair)3