Search in sources :

Example 6 with M2Aspect

use of org.alfresco.repo.dictionary.M2Aspect in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method initCustomMap.

/**
 * Initialise custom type map
 */
private void initCustomMap() {
    customisableTypes = new HashMap<QName, QName>(7);
    Collection<QName> aspects = getDictionaryService().getAspects(RM_CUSTOM_MODEL);
    for (QName aspect : aspects) {
        AspectDefinition aspectDef = getDictionaryService().getAspect(aspect);
        String name = aspectDef.getName().getLocalName();
        if (name.endsWith("Properties")) {
            QName type = null;
            String prefixString = aspectDef.getDescription(getDictionaryService());
            if (prefixString == null) {
                // Backward compatibility from previous RM V1.0 custom models
                if (CompatibilityModel.NAME_CUSTOM_RECORD_PROPERTIES.equals(name)) {
                    type = RecordsManagementModel.ASPECT_RECORD;
                } else if (CompatibilityModel.NAME_CUSTOM_RECORD_FOLDER_PROPERTIES.equals(name)) {
                    type = RecordsManagementModel.TYPE_RECORD_FOLDER;
                } else if (CompatibilityModel.NAME_CUSTOM_RECORD_CATEGORY_PROPERTIES.equals(name)) {
                    type = RecordsManagementModel.TYPE_RECORD_CATEGORY;
                } else if (CompatibilityModel.NAME_CUSTOM_RECORD_SERIES_PROPERTIES.equals(name) && // a v1.0 installation has added custom properties
                aspectDef.getProperties().size() != 0) {
                    type = CompatibilityModel.TYPE_RECORD_SERIES;
                }
            } else {
                type = QName.createQName(prefixString, getNamespaceService());
            }
            // Add the customisable type to the map
            if (type != null) {
                customisableTypes.put(type, aspect);
                // Remove customisable type from the pending list
                if (pendingCustomisableTypes != null && pendingCustomisableTypes.contains(type)) {
                    pendingCustomisableTypes.remove(type);
                }
            }
        }
    }
    // Deal with any pending types left over
    if (pendingCustomisableTypes != null && pendingCustomisableTypes.size() != 0) {
        NodeRef modelRef = getCustomModelRef(RecordsManagementModel.RM_CUSTOM_URI);
        M2Model model = readCustomContentModel(modelRef);
        try {
            for (QName customisableType : pendingCustomisableTypes) {
                QName customAspect = getCustomAspectImpl(customisableType);
                // Create the new aspect to hold the custom properties
                M2Aspect aspect = model.createAspect(customAspect.toPrefixString(getNamespaceService()));
                aspect.setDescription(customisableType.toPrefixString(getNamespaceService()));
                // Make a record of the customisable type
                customisableTypes.put(customisableType, customAspect);
            }
        } finally {
            writeCustomContentModel(modelRef, model);
        }
    }
    // indicate map is initialised
    isCustomMapInit = true;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString) M2Aspect(org.alfresco.repo.dictionary.M2Aspect)

Example 7 with M2Aspect

use of org.alfresco.repo.dictionary.M2Aspect in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method addCustomPropertyDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#addCustomPropertyDefinition(org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName, java.lang.String, org.alfresco.service.namespace.QName, java.lang.String, java.lang.String, java.lang.String, boolean, boolean, boolean, org.alfresco.service.namespace.QName)
 */
public QName addCustomPropertyDefinition(QName propId, QName aspectName, String label, QName dataType, String title, String description, String defaultValue, boolean multiValued, boolean mandatory, boolean isProtected, QName lovConstraint) throws CustomMetadataException {
    if (!isCustomisable(aspectName)) {
        throw new NotCustomisableMetadataException(aspectName.toPrefixString(getNamespaceService()));
    }
    // title parameter is currently ignored. Intentionally.
    if (propId == null) {
        // Generate a propId
        propId = this.generateQNameFor(label);
    }
    mandatory("aspectName", aspectName);
    mandatory("label", label);
    mandatory("dataType", dataType);
    NodeRef modelRef = getCustomModelRef(propId.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    QName customAspect = getCustomAspect(aspectName);
    M2Aspect customPropsAspect = deserializedModel.getAspect(customAspect.toPrefixString(getNamespaceService()));
    if (customPropsAspect == null) {
        throw new InvalidCustomAspectMetadataException(customAspect, aspectName.toPrefixString(getNamespaceService()));
    }
    String propIdAsString = propId.toPrefixString(getNamespaceService());
    M2Property customProp = customPropsAspect.getProperty(propIdAsString);
    if (customProp != null) {
        throw new PropertyAlreadyExistsMetadataException(propIdAsString);
    }
    M2Property newProp = customPropsAspect.createProperty(propIdAsString);
    newProp.setName(propIdAsString);
    newProp.setType(dataType.toPrefixString(getNamespaceService()));
    // Note that the title is used to store the RM 'label'.
    newProp.setTitle(label);
    newProp.setDescription(description);
    newProp.setDefaultValue(defaultValue);
    newProp.setMandatory(mandatory);
    newProp.setProtected(isProtected);
    newProp.setMultiValued(multiValued);
    newProp.setIndexed(true);
    newProp.setIndexedAtomically(true);
    newProp.setStoredInIndex(false);
    newProp.setIndexTokenisationMode(IndexTokenisationMode.FALSE);
    if (lovConstraint != null) {
        if (!dataType.equals(DataTypeDefinition.TEXT)) {
            throw new CannotApplyConstraintMetadataException(lovConstraint, propIdAsString, dataType);
        }
        String lovConstraintQNameAsString = lovConstraint.toPrefixString(getNamespaceService());
        newProp.addConstraintRef(lovConstraintQNameAsString);
    }
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("addCustomPropertyDefinition: " + label + "=" + propIdAsString + " to aspect: " + aspectName);
    }
    return propId;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)

Example 8 with M2Aspect

use of org.alfresco.repo.dictionary.M2Aspect 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 9 with M2Aspect

use of org.alfresco.repo.dictionary.M2Aspect 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 10 with M2Aspect

use of org.alfresco.repo.dictionary.M2Aspect 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

M2Aspect (org.alfresco.repo.dictionary.M2Aspect)10 M2Model (org.alfresco.repo.dictionary.M2Model)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 QName (org.alfresco.service.namespace.QName)5 M2ClassAssociation (org.alfresco.repo.dictionary.M2ClassAssociation)4 M2Property (org.alfresco.repo.dictionary.M2Property)4 ParameterCheck.mandatoryString (org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)3 HashMap (java.util.HashMap)2 ParameterCheck.mandatoryString (org.alfresco.util.ParameterCheck.mandatoryString)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 DictionaryDAO (org.alfresco.repo.dictionary.DictionaryDAO)1 M2Constraint (org.alfresco.repo.dictionary.M2Constraint)1 M2Type (org.alfresco.repo.dictionary.M2Type)1 CustomAspect (org.alfresco.rest.api.model.CustomAspect)1 CustomModelConstraint (org.alfresco.rest.api.model.CustomModelConstraint)1 CustomType (org.alfresco.rest.api.model.CustomType)1 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)1 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)1