use of org.alfresco.repo.dictionary.M2ClassAssociation in project records-management by Alfresco.
the class ApplyDodCertModelFixesGet method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
LOGGER.info("Applying webscript-based patches to RM custom model in the repo.");
M2Model customModel = readCustomContentModel();
if (customModel == null) {
final String msg = "Custom content model could not be read";
LOGGER.error(msg);
throw new AlfrescoRuntimeException(msg);
}
String customAspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(namespaceService);
M2Aspect customAssocsAspect = customModel.getAspect(customAspectName);
if (customAssocsAspect == null) {
final String msg = "Unknown aspect: " + customAspectName;
LOGGER.error(msg);
throw new AlfrescoRuntimeException(msg);
}
// MOB-1573. All custom references should have many-many multiplicity.
LOGGER.info("MOB-1573. All custom references should have many-many multiplicity.");
for (M2ClassAssociation classAssoc : customAssocsAspect.getAssociations()) {
classAssoc.setSourceMany(true);
classAssoc.setTargetMany(true);
}
// MOB-1621. Custom fields should be created as untokenized by default.
LOGGER.info("MOB-1621. Custom fields should be created as untokenized by default.");
List<String> allCustomPropertiesAspects = new ArrayList<String>(4);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_SERIES_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_CATEGORY_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_FOLDER_PROPERTIES);
allCustomPropertiesAspects.add(RMC_CUSTOM_RECORD_PROPERTIES);
for (String aspectName : allCustomPropertiesAspects) {
M2Aspect aspectObj = customModel.getAspect(aspectName);
List<M2Property> customProperties = aspectObj.getProperties();
for (M2Property propertyObj : customProperties) {
propertyObj.setIndexed(true);
propertyObj.setIndexedAtomically(true);
propertyObj.setStoredInIndex(false);
propertyObj.setIndexTokenisationMode(IndexTokenisationMode.FALSE);
}
}
writeCustomContentModel(customModel);
LOGGER.info("Completed application of webscript-based patches to RM custom model in the repo.");
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("success", true);
return model;
}
use of org.alfresco.repo.dictionary.M2ClassAssociation in project records-management by Alfresco.
the class ApplyFixMob1573Get method executeImpl.
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
M2Model customModel = readCustomContentModel();
if (customModel == null) {
throw new AlfrescoRuntimeException("Custom content model could not be read");
}
// Go through every custom reference defined in the custom model and make sure that it
// has many-to-many multiplicity
String aspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(namespaceService);
M2Aspect customAssocsAspect = customModel.getAspect(aspectName);
if (customAssocsAspect == null) {
throw new AlfrescoRuntimeException("Unknown aspect: " + aspectName);
}
for (M2ClassAssociation classAssoc : customAssocsAspect.getAssociations()) {
classAssoc.setSourceMany(true);
classAssoc.setTargetMany(true);
}
writeCustomContentModel(customModel);
Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
model.put("success", true);
return model;
}
use of org.alfresco.repo.dictionary.M2ClassAssociation 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.M2ClassAssociation 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