Search in sources :

Example 1 with RelationshipType

use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType in project records-management by Alfresco.

the class CustomRefsGet method getRelationshipData.

/**
 * Creates relationship data for the ftl template
 *
 * @param relationships The relationships
 * @return The relationship data
 */
private List<Map<String, String>> getRelationshipData(Set<Relationship> relationships) {
    List<Map<String, String>> relationshipData = new ArrayList<Map<String, String>>();
    for (Relationship relationship : relationships) {
        String uniqueName = relationship.getUniqueName();
        RelationshipDefinition relationshipDefinition = getRelationshipService().getRelationshipDefinition(uniqueName);
        NodeRef source = relationship.getSource();
        NodeRef target = relationship.getTarget();
        if (relationshipDefinition != null && hasView(source) && hasView(target)) {
            Map<String, String> data = new HashMap<String, String>();
            RelationshipType type = relationshipDefinition.getType();
            RelationshipDisplayName displayName = relationshipDefinition.getDisplayName();
            if (RelationshipType.BIDIRECTIONAL.equals(type)) {
                data.put(LABEL, displayName.getSourceText());
                data.put(SOURCE_REF, source.toString());
                data.put(TARGET_REF, target.toString());
            } else if (RelationshipType.PARENTCHILD.equals(type)) {
                data.put(SOURCE, displayName.getSourceText());
                data.put(TARGET, displayName.getTargetText());
                data.put(PARENT_REF, source.toString());
                data.put(CHILD_REF, target.toString());
            } else {
                StringBuilder sb = new StringBuilder();
                sb.append("Unsupported relationship type '").append(type).append("'.");
                throw new WebScriptException(Status.STATUS_BAD_REQUEST, sb.toString());
            }
            data.put(REFERENCE_TYPE, type.toString().toLowerCase());
            data.put(REF_ID, uniqueName);
            relationshipData.add(data);
        }
    }
    return relationshipData;
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelationshipType(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) Relationship(org.alfresco.module.org_alfresco_module_rm.relationship.Relationship) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with RelationshipType

use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType in project records-management by Alfresco.

the class RelationshipLabelsGet method getRelationshipsLabels.

/**
 * Gets the list of available relationship labels
 *
 * @return The list of available relationship labels
 */
private List<RelationshipLabel> getRelationshipsLabels() {
    List<RelationshipLabel> relationshipLabels = new ArrayList<RelationshipLabel>();
    Set<RelationshipDefinition> relationshipDefinitions = getRelationshipService().getRelationshipDefinitions();
    for (RelationshipDefinition relationshipDefinition : relationshipDefinitions) {
        RelationshipType type = relationshipDefinition.getType();
        String uniqueName = relationshipDefinition.getUniqueName();
        RelationshipDisplayName displayName = relationshipDefinition.getDisplayName();
        String sourceText = displayName.getSourceText();
        String targetText = displayName.getTargetText();
        if (RelationshipType.PARENTCHILD.equals(type)) {
            relationshipLabels.add(new RelationshipLabel(sourceText, uniqueName + INVERT));
            relationshipLabels.add(new RelationshipLabel(targetText, uniqueName));
        } else if (RelationshipType.BIDIRECTIONAL.equals(type)) {
            if (!sourceText.equals(targetText)) {
                throw new WebScriptException(Status.STATUS_BAD_REQUEST, "The source '" + sourceText + "' and target text '" + targetText + "' must be the same for a bidirectional relationship.");
            }
            relationshipLabels.add(new RelationshipLabel(sourceText, uniqueName));
        } else {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unknown relationship type '" + type + "'.");
        }
    }
    return sortRelationshipLabelsByName(relationshipLabels);
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) ArrayList(java.util.ArrayList) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition) RelationshipType(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType) ParameterCheck.mandatoryString(org.alfresco.util.ParameterCheck.mandatoryString)

Example 3 with RelationshipType

use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType in project records-management by Alfresco.

the class CustomReferenceDefinitionsGet method createRelationshipDefinitionData.

/**
 * Creates relationship definition data for the ftl template
 *
 * @param relationshipDefinitions The relationship definitions
 * @return The relationship definition data
 */
private List<Map<String, String>> createRelationshipDefinitionData(Set<RelationshipDefinition> relationshipDefinitions) {
    List<Map<String, String>> relationshipDefinitionData = new ArrayList<Map<String, String>>();
    for (RelationshipDefinition relationshipDefinition : relationshipDefinitions) {
        Map<String, String> data = new HashMap<String, String>();
        RelationshipType type = relationshipDefinition.getType();
        RelationshipDisplayName displayName = relationshipDefinition.getDisplayName();
        if (RelationshipType.BIDIRECTIONAL.equals(type)) {
            data.put(LABEL, displayName.getSourceText());
        } else if (RelationshipType.PARENTCHILD.equals(type)) {
            data.put(SOURCE, displayName.getSourceText());
            data.put(TARGET, displayName.getTargetText());
        } else {
            StringBuilder sb = new StringBuilder();
            sb.append("Unsupported relationship type '").append(type).append("'.");
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, sb.toString());
        }
        data.put(REF_ID, relationshipDefinition.getUniqueName());
        data.put(REFERENCE_TYPE, type.toString().toLowerCase());
        relationshipDefinitionData.add(data);
    }
    return relationshipDefinitionData;
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition) RelationshipType(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)3 RelationshipDefinition (org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition)3 RelationshipDisplayName (org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName)3 RelationshipType (org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Relationship (org.alfresco.module.org_alfresco_module_rm.relationship.Relationship)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 ParameterCheck.mandatoryString (org.alfresco.util.ParameterCheck.mandatoryString)1