Search in sources :

Example 1 with M2ClassAssociation

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;
}
Also used : HashMap(java.util.HashMap) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) ArrayList(java.util.ArrayList) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

Example 2 with M2ClassAssociation

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;
}
Also used : HashMap(java.util.HashMap) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

Example 3 with M2ClassAssociation

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.alfresco.util.ParameterCheck.mandatoryString) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

Example 4 with M2ClassAssociation

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.alfresco.util.ParameterCheck.mandatoryString) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

Aggregations

AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4 M2Aspect (org.alfresco.repo.dictionary.M2Aspect)4 M2ClassAssociation (org.alfresco.repo.dictionary.M2ClassAssociation)4 M2Model (org.alfresco.repo.dictionary.M2Model)4 HashMap (java.util.HashMap)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ParameterCheck.mandatoryString (org.alfresco.util.ParameterCheck.mandatoryString)2 ArrayList (java.util.ArrayList)1 M2Property (org.alfresco.repo.dictionary.M2Property)1 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)1 ChildAssociationDefinition (org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)1 QName (org.alfresco.service.namespace.QName)1