Search in sources :

Example 6 with RelationshipDefinition

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

the class CustomReferenceDefinitionPost method executeImpl.

/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
 *      org.springframework.extensions.webscripts.Status,
 *      org.springframework.extensions.webscripts.Cache)
 */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    JSONObject requestContent = getRequestContentAsJSONObject(req);
    RelationshipDisplayName displayName = createDisplayName(requestContent);
    RelationshipDefinition relationshipDefinition = getRelationshipService().createRelationshipDefinition(displayName);
    Map<String, Object> model = new HashMap<String, Object>();
    String servicePath = req.getServicePath();
    Map<String, Object> customRelationshipData = createRelationshipDefinitionData(relationshipDefinition, servicePath);
    model.putAll(customRelationshipData);
    return model;
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) WebScriptUtils.getRequestContentAsJSONObject(org.alfresco.util.WebScriptUtils.getRequestContentAsJSONObject) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition) WebScriptUtils.getRequestContentAsJSONObject(org.alfresco.util.WebScriptUtils.getRequestContentAsJSONObject) JSONObject(org.json.JSONObject)

Example 7 with RelationshipDefinition

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

Example 8 with RelationshipDefinition

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

the class SplitEmailAction method bootstrap.

public void bootstrap() {
    Set<RelationshipDefinition> relationshipDefinitions = getRelationshipService().getRelationshipDefinitions();
    for (RelationshipDefinition relationshipDefinition : relationshipDefinitions) {
        RelationshipDisplayName displayName = relationshipDefinition.getDisplayName();
        String sourceText = displayName.getSourceText();
        String targetText = displayName.getTargetText();
        if (sourceText.equals(REL_FROM) && targetText.equals(REL_TO)) {
            relationshipUniqueName = relationshipDefinition.getUniqueName();
        }
    }
    if (isBlank(relationshipUniqueName)) {
        RelationshipDisplayName displayName = new RelationshipDisplayName(REL_FROM, REL_TO);
        RelationshipDefinition relationshipDefinition = getRelationshipService().createRelationshipDefinition(displayName);
        relationshipUniqueName = relationshipDefinition.getUniqueName();
    }
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition)

Example 9 with RelationshipDefinition

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

the class RecordsManagementAdminServiceImplTest method createAndUseCustomReference.

private void createAndUseCustomReference(final RelationshipType refType, final String label, final String source, final String target) throws Exception {
    final NodeRef testRecord1 = retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            NodeRef result = utils.createRecord(rmFolder, "testRecordA" + System.currentTimeMillis());
            return result;
        }
    });
    final NodeRef testRecord2 = retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() throws Throwable {
            NodeRef result = utils.createRecord(rmFolder, "testRecordB" + System.currentTimeMillis());
            return result;
        }
    });
    final QName generatedQName = retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<QName>() {

        public QName execute() throws Throwable {
            utils.completeRecord(testRecord1);
            utils.completeRecord(testRecord2);
            Map<String, Serializable> params = new HashMap<String, Serializable>();
            params.put("referenceType", refType.toString());
            if (label != null)
                params.put("label", label);
            if (source != null)
                params.put("source", source);
            if (target != null)
                params.put("target", target);
            // Create the relationship display name
            RelationshipDisplayName displayName;
            if (label != null) {
                // A bidirectional reference
                displayName = new RelationshipDisplayName(label, label);
            } else {
                // A parent/child reference
                displayName = new RelationshipDisplayName(source, target);
            }
            // Create the relationship definition
            RelationshipDefinition relationshipDefinition = relationshipService.createRelationshipDefinition(displayName);
            // Get the qualified name
            QName qNameResult = QName.createQName(RM_CUSTOM_PREFIX, relationshipDefinition.getUniqueName(), namespaceService);
            ;
            System.out.println("Creating new " + refType + " reference definition: " + qNameResult);
            System.out.println("  params- label: '" + label + "' source: '" + source + "' target: '" + target + "'");
            return qNameResult;
        }
    });
    retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            RelationshipDefinition relationshipDefinition = relationshipService.getRelationshipDefinition(generatedQName.getLocalName());
            assertNotNull("Relationship definition from relationshipService was null.", relationshipDefinition);
            assertEquals(generatedQName.getLocalName(), relationshipDefinition.getUniqueName());
            assertTrue(refType.equals(relationshipDefinition.getType()));
            // Now we need to use the custom reference.
            // So we apply the aspect containing it to our test records.
            nodeService.addAspect(testRecord1, ASPECT_CUSTOM_ASSOCIATIONS, null);
            if (RelationshipType.PARENTCHILD.equals(refType)) {
                nodeService.addChild(testRecord1, testRecord2, generatedQName, generatedQName);
            } else {
                nodeService.createAssociation(testRecord1, testRecord2, generatedQName);
            }
            return null;
        }
    });
    retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {

        public Void execute() throws Throwable {
            // Read back the reference value to make sure it was correctly applied.
            List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(testRecord1);
            List<AssociationRef> retrievedAssocs = nodeService.getTargetAssocs(testRecord1, RegexQNamePattern.MATCH_ALL);
            Object newlyAddedRef = null;
            if (RelationshipType.PARENTCHILD.equals(refType)) {
                for (ChildAssociationRef caRef : childAssocs) {
                    QName refInstanceQName = caRef.getQName();
                    if (generatedQName.equals(refInstanceQName))
                        newlyAddedRef = caRef;
                }
            } else {
                for (AssociationRef aRef : retrievedAssocs) {
                    QName refQName = aRef.getTypeQName();
                    if (generatedQName.equals(refQName))
                        newlyAddedRef = aRef;
                }
            }
            assertNotNull("newlyAddedRef was null.", newlyAddedRef);
            // Check that the reference has appeared in the data dictionary
            AspectDefinition customAssocsAspect = dictionaryService.getAspect(ASPECT_CUSTOM_ASSOCIATIONS);
            assertNotNull(customAssocsAspect);
            if (RelationshipType.PARENTCHILD.equals(refType)) {
                assertNotNull("The customReference is not returned from the dictionaryService.", customAssocsAspect.getChildAssociations().get(generatedQName));
            } else {
                assertNotNull("The customReference is not returned from the dictionaryService.", customAssocsAspect.getAssociations().get(generatedQName));
            }
            return null;
        }
    });
}
Also used : RelationshipDisplayName(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName) Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDefinition) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

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