use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName 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;
}
use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName 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;
}
use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName 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();
}
}
use of org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName 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;
}
});
}
Aggregations