use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.
the class RelationshipServiceImpl method persistUpdatedAssocTitle.
/**
* This method writes the specified String into the association's title property.
* For RM custom properties and references, Title is used to store the identifier.
*
* NOTE: Currently RMC custom associations only
* @param associationDefinitionQName Qualified name for the association definition
* @param newTitle The new title
* @return Qualified name for the association definition
*/
private QName persistUpdatedAssocTitle(QName associationDefinitionQName, String newTitle) {
mandatory("associationDefinitionQName", associationDefinitionQName);
AssociationDefinition assocDefn = getDictionaryService().getAssociation(associationDefinitionQName);
if (assocDefn == null) {
StringBuilder sb = new StringBuilder();
sb.append("Cannot find the association definiton for '").append(associationDefinitionQName.getLocalName()).append("'.");
throw new AlfrescoRuntimeException(sb.toString());
}
// defaults to RM_CUSTOM_URI
NodeRef modelRef = getCustomModelRef("");
M2Model deserializedModel = readCustomContentModel(modelRef);
String customAspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(getNamespaceService());
M2Aspect customAssocsAspect = deserializedModel.getAspect(customAspectName);
for (M2ClassAssociation assoc : customAssocsAspect.getAssociations()) {
if (associationDefinitionQName.toPrefixString(getNamespaceService()).equals(assoc.getName()) && newTitle != null) {
assoc.setTitle(newTitle);
}
}
writeCustomContentModel(modelRef, deserializedModel);
if (logger.isInfoEnabled()) {
logger.info("persistUpdatedAssocTitle: " + associationDefinitionQName + "=" + newTitle + " to aspect: " + customAspectName);
}
return associationDefinitionQName;
}
use of org.alfresco.repo.dictionary.M2Model in project records-management by Alfresco.
the class RelationshipServiceImpl method createRelationshipDefinition.
/**
* @see org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipService#createRelationshipDefinition(org.alfresco.module.org_alfresco_module_rm.relationship.RelationshipDisplayName)
*/
@Override
public RelationshipDefinition createRelationshipDefinition(RelationshipDisplayName displayName) {
mandatory("displayName", displayName);
String title;
RelationshipType type = determineRelationshipTypeFromDisplayName(displayName);
switch(type) {
case BIDIRECTIONAL:
title = displayName.getSourceText();
break;
case PARENTCHILD:
String sourceText = displayName.getSourceText();
String targetText = displayName.getTargetText();
title = composeAssociationDefinitionTitle(sourceText, targetText);
break;
default:
StringBuilder sb = new StringBuilder();
sb.append("Unsupported relationship type: '").append(type.toString()).append("'.");
throw new AlfrescoRuntimeException(sb.toString());
}
// If this title is already taken...
if (existsTitle(title)) {
StringBuilder sb = new StringBuilder();
sb.append("Cannot create a relationship definition for the display name: '").append(displayName.toString()).append("' as there is already a relationship definition with this display name.");
throw new AlfrescoRuntimeException(sb.toString());
}
// Defaults to RM_CUSTOM_URI
NodeRef modelRef = getCustomModelRef("");
M2Model deserializedModel = readCustomContentModel(modelRef);
String customAspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(getNamespaceService());
M2Aspect customAssocsAspect = deserializedModel.getAspect(customAspectName);
if (customAssocsAspect == null) {
StringBuilder sb = new StringBuilder();
sb.append("The aspect: '").append(customAspectName).append("' is undefined.");
throw new AlfrescoRuntimeException(sb.toString());
}
QName relationshipDefinitionQName = generateRelationshipDefinitionQNameFor(title);
String generatedShortQName = relationshipDefinitionQName.toPrefixString(getNamespaceService());
M2ClassAssociation customAssoc = customAssocsAspect.getAssociation(generatedShortQName);
if (customAssoc != null) {
StringBuilder sb = new StringBuilder();
sb.append("The association: '").append(customAssoc.getName()).append("' already exists.");
throw new AlfrescoRuntimeException(sb.toString());
}
M2ClassAssociation newAssoc;
switch(type) {
case BIDIRECTIONAL:
newAssoc = customAssocsAspect.createAssociation(generatedShortQName);
break;
case PARENTCHILD:
newAssoc = customAssocsAspect.createChildAssociation(generatedShortQName);
break;
default:
StringBuilder sb = new StringBuilder();
sb.append("Unsupported relationship type: '").append(type.toString()).append("'.");
throw new AlfrescoRuntimeException(sb.toString());
}
newAssoc.setSourceMandatory(false);
newAssoc.setTargetMandatory(false);
// MOB-1573
newAssoc.setSourceMany(true);
newAssoc.setTargetMany(true);
newAssoc.setTitle(title);
newAssoc.setTargetClassName(RecordsManagementModel.ASPECT_RECORD.toPrefixString(getNamespaceService()));
writeCustomContentModel(modelRef, deserializedModel);
return new RelationshipDefinitionImpl(relationshipDefinitionQName.getLocalName(), type, displayName);
}
Aggregations