Search in sources :

Example 1 with RelationshipDefinition

use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition 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 RelationshipDefinition

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

the class RecordsManagementAdminServiceImpl method addCustomChildAssocDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#addCustomChildAssocDefinition(java.lang.String, java.lang.String)
 *
 * note: currently RMC custom assocs only
 */
public QName addCustomChildAssocDefinition(String source, String target) {
    mandatoryString("source", source);
    mandatoryString("target", target);
    RelationshipDisplayName displayName = new RelationshipDisplayName(source, target);
    RelationshipDefinition relationshipDefinition = getRelationshipService().createRelationshipDefinition(displayName);
    return QName.createQName(RM_CUSTOM_PREFIX, relationshipDefinition.getUniqueName(), getNamespaceService());
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition)

Example 3 with RelationshipDefinition

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

the class RecordsManagementAdminServiceImpl method updateCustomChildAssocDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#updateCustomChildAssocDefinition(org.alfresco.service.namespace.QName, java.lang.String, java.lang.String)
 *
 * note: currently RMC custom assocs only
 */
public QName updateCustomChildAssocDefinition(QName refQName, String newSource, String newTarget) {
    mandatory("refQName", refQName);
    mandatoryString("newSource", newSource);
    mandatoryString("newTarget", newTarget);
    RelationshipDisplayName displayName = new RelationshipDisplayName(newSource, newTarget);
    String localName = refQName.getLocalName();
    RelationshipDefinition relationshipDefinition = getRelationshipService().updateRelationshipDefinition(localName, displayName);
    return QName.createQName(RM_CUSTOM_PREFIX, relationshipDefinition.getUniqueName(), getNamespaceService());
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)

Example 4 with RelationshipDefinition

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

the class RelationshipsGet method buildRelationshipData.

/**
 * Creates the relationship data
 *
 * @param relationships The {@link Set} of relationships
 * @param relationshipEndPoint The end point of the relationship, which is either {@link RelationshipEndpoint#SOURCE} or {@link RelationshipEndpoint#TARGET}
 * @return The relationship data as {@link List}
 */
private List<String> buildRelationshipData(Set<Relationship> relationships, RelationshipEndPoint relationshipEndPoint) {
    List<String> result = new ArrayList<String>();
    for (Relationship relationship : relationships) {
        String uniqueName = relationship.getUniqueName();
        RelationshipDefinition relationshipDefinition = getRelationshipService().getRelationshipDefinition(uniqueName);
        if (relationshipDefinition != null) {
            NodeRef node;
            String label;
            if (RelationshipEndPoint.SOURCE.equals(relationshipEndPoint)) {
                node = relationship.getSource();
                label = relationshipDefinition.getDisplayName().getSourceText();
            } else if (RelationshipEndPoint.TARGET.equals(relationshipEndPoint)) {
                node = relationship.getTarget();
                label = relationshipDefinition.getDisplayName().getTargetText();
            } else {
                throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unknown relationship end point type '" + relationshipEndPoint + "'.");
            }
            String nodeDetails = getJsonConversionComponent().toJSON(node, true);
            JSONObject jsonObject = WebScriptUtils.createJSONObject(nodeDetails);
            WebScriptUtils.putValueToJSONObject(jsonObject, RELATIONSHIP_LABEL, label);
            WebScriptUtils.putValueToJSONObject(jsonObject, RELATIONSHIP_UNIQUE_NAME, relationshipDefinition.getUniqueName());
            result.add(jsonObject.toString());
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.JSONObject) Relationship(org.alfresco.module.org_alfresco_module_rm.relationship.Relationship) ArrayList(java.util.ArrayList) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition)

Example 5 with RelationshipDefinition

use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition 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)

Aggregations

RelationshipDefinition (org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition)9 RelationshipDisplayName (org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)4 Map (java.util.Map)3 RelationshipType (org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipType)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Relationship (org.alfresco.module.org_alfresco_module_rm.relationship.Relationship)2 JSONObject (org.json.JSONObject)2 Serializable (java.io.Serializable)1 List (java.util.List)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)1 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 QName (org.alfresco.service.namespace.QName)1 ParameterCheck.mandatoryString (org.alfresco.util.ParameterCheck.mandatoryString)1 WebScriptUtils.getRequestContentAsJSONObject (org.alfresco.util.WebScriptUtils.getRequestContentAsJSONObject)1 ParameterCheck.mandatoryString (org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)1