Search in sources :

Example 1 with M2Aspect

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

the class RecordsManagementAdminServiceImpl method removeCustomPropertyDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#removeCustomPropertyDefinition(org.alfresco.service.namespace.QName)
 */
public void removeCustomPropertyDefinition(QName propQName) {
    mandatory("propQName", propQName);
    NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    String propQNameAsString = propQName.toPrefixString(getNamespaceService());
    String aspectName = null;
    boolean found = false;
    // attempt to delete the property definition.
    for (QName customisableType : getCustomisable()) {
        aspectName = getCustomAspect(customisableType).toPrefixString(getNamespaceService());
        M2Aspect customPropsAspect = deserializedModel.getAspect(aspectName);
        if (customPropsAspect == null) {
            throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNKNOWN_ASPECT, aspectName));
        }
        M2Property prop = customPropsAspect.getProperty(propQNameAsString);
        if (prop != null) {
            if (logger.isDebugEnabled()) {
                StringBuilder msg = new StringBuilder();
                msg.append("Attempting to delete custom property: ");
                msg.append(propQNameAsString);
                logger.debug(msg.toString());
            }
            found = true;
            customPropsAspect.removeProperty(propQNameAsString);
            break;
        }
    }
    if (!found) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQNameAsString));
    }
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("deleteCustomPropertyDefinition: " + propQNameAsString + " from aspect: " + aspectName);
    }
}
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) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString) M2Aspect(org.alfresco.repo.dictionary.M2Aspect)

Example 2 with M2Aspect

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

the class RecordsManagementAdminServiceImpl method makeCustomisable.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#makeCustomisable(org.alfresco.service.namespace.QName)
 */
@Override
public void makeCustomisable(QName type) {
    mandatory("type", type);
    if (customisableTypes == null) {
        // Add the type to the pending list
        pendingCustomisableTypes.add(type);
    } else {
        QName customAspect = getCustomAspect(type);
        if (getDictionaryService().getAspect(customAspect) == null) {
            NodeRef modelRef = getCustomModelRef(customAspect.getNamespaceURI());
            M2Model model = readCustomContentModel(modelRef);
            try {
                // Create the new aspect to hold the custom properties
                M2Aspect aspect = model.createAspect(customAspect.toPrefixString(getNamespaceService()));
                aspect.setDescription(type.toPrefixString(getNamespaceService()));
            } finally {
                writeCustomContentModel(modelRef, model);
            }
            customisableTypes.put(type, customAspect);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) M2Model(org.alfresco.repo.dictionary.M2Model) M2Aspect(org.alfresco.repo.dictionary.M2Aspect)

Example 3 with M2Aspect

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

use of org.alfresco.repo.dictionary.M2Aspect in project alfresco-remote-api by Alfresco.

the class CustomModelsImpl method convertToM2Model.

/**
 * Converts the given {@code org.alfresco.rest.api.model.CustomModel}
 * object, a collection of {@code org.alfresco.rest.api.model.CustomType}
 * objects, a collection of
 * {@code org.alfresco.rest.api.model.CustomAspect} objects, and a collection of
 * {@code org.alfresco.rest.api.model.CustomModelConstraint} objects into a {@link M2Model} object
 *
 * @param customModel the custom model
 * @param types the custom types
 * @param aspects the custom aspects
 * @param constraints the custom constraints
 * @return {@link M2Model} object
 */
private M2Model convertToM2Model(CustomModel customModel, Collection<CustomType> types, Collection<CustomAspect> aspects, Collection<CustomModelConstraint> constraints) {
    validateBasicModelInput(customModel);
    Set<Pair<String, String>> namespacesToImport = new LinkedHashSet<>();
    final String namespacePrefix = customModel.getNamespacePrefix();
    final String namespaceURI = customModel.getNamespaceUri();
    // Construct the model name
    final String name = constructName(customModel.getName(), namespacePrefix);
    M2Model model = M2Model.createModel(name);
    model.createNamespace(namespaceURI, namespacePrefix);
    model.setDescription(customModel.getDescription());
    String author = customModel.getAuthor();
    if (author == null) {
        author = getCurrentUserFullName();
    }
    model.setAuthor(author);
    // Types
    if (types != null) {
        for (CustomType type : types) {
            validateName(type.getName(), TYPE_NAME_NULL_ERR);
            M2Type m2Type = model.createType(constructName(type.getName(), namespacePrefix));
            m2Type.setDescription(type.getDescription());
            m2Type.setTitle(type.getTitle());
            setParentName(m2Type, type.getParentName(), namespacesToImport, namespacePrefix);
            setM2Properties(m2Type, type.getProperties(), namespacePrefix, namespacesToImport);
        }
    }
    // Aspects
    if (aspects != null) {
        for (CustomAspect aspect : aspects) {
            validateName(aspect.getName(), ASPECT_NAME_NULL_ERR);
            M2Aspect m2Aspect = model.createAspect(constructName(aspect.getName(), namespacePrefix));
            m2Aspect.setDescription(aspect.getDescription());
            m2Aspect.setTitle(aspect.getTitle());
            setParentName(m2Aspect, aspect.getParentName(), namespacesToImport, namespacePrefix);
            setM2Properties(m2Aspect, aspect.getProperties(), namespacePrefix, namespacesToImport);
        }
    }
    // Constraints
    if (constraints != null) {
        for (CustomModelConstraint constraint : constraints) {
            validateName(constraint.getName(), CONSTRAINT_NAME_NULL_ERR);
            final String constraintName = constructName(constraint.getName(), namespacePrefix);
            M2Constraint m2Constraint = model.createConstraint(constraintName, constraint.getType());
            // Set title, desc and parameters
            setConstraintOtherData(constraint, m2Constraint, null);
        }
    }
    // Add imports
    for (Pair<String, String> uriPrefix : namespacesToImport) {
        // Don't import the already defined namespace
        if (!namespaceURI.equals(uriPrefix.getFirst())) {
            model.createImport(uriPrefix.getFirst(), uriPrefix.getSecond());
        }
    }
    return model;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) CustomType(org.alfresco.rest.api.model.CustomType) M2Constraint(org.alfresco.repo.dictionary.M2Constraint) M2Type(org.alfresco.repo.dictionary.M2Type) M2Model(org.alfresco.repo.dictionary.M2Model) CustomAspect(org.alfresco.rest.api.model.CustomAspect) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) Pair(org.alfresco.util.Pair)

Example 5 with M2Aspect

use of org.alfresco.repo.dictionary.M2Aspect in project alfresco-remote-api by Alfresco.

the class AbstractEnterpriseOpenCMISTCKTest method overrideVersionableAspectProperties.

protected void overrideVersionableAspectProperties(ApplicationContext ctx) {
    final DictionaryDAO dictionaryDAO = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    dictionaryDAO.removeModel(QName.createQName("cm:contentmodel"));
    M2Model contentModel = M2Model.createModel(getClass().getClassLoader().getResourceAsStream("alfresco/model/contentModel.xml"));
    M2Aspect versionableAspect = contentModel.getAspect("cm:versionable");
    M2Property prop = versionableAspect.getProperty("cm:initialVersion");
    prop.setDefaultValue(Boolean.FALSE.toString());
    prop = versionableAspect.getProperty("cm:autoVersion");
    prop.setDefaultValue(Boolean.FALSE.toString());
    prop = versionableAspect.getProperty("cm:autoVersionOnUpdateProps");
    prop.setDefaultValue(Boolean.FALSE.toString());
    dictionaryDAO.putModel(contentModel);
}
Also used : DictionaryDAO(org.alfresco.repo.dictionary.DictionaryDAO) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) M2Aspect(org.alfresco.repo.dictionary.M2Aspect)

Aggregations

M2Aspect (org.alfresco.repo.dictionary.M2Aspect)12 M2Model (org.alfresco.repo.dictionary.M2Model)12 M2Property (org.alfresco.repo.dictionary.M2Property)6 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 ParameterCheck.mandatoryString (org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)3 HashMap (java.util.HashMap)2 M2Type (org.alfresco.repo.dictionary.M2Type)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 M2Association (org.alfresco.repo.dictionary.M2Association)1 M2ChildAssociation (org.alfresco.repo.dictionary.M2ChildAssociation)1 M2Constraint (org.alfresco.repo.dictionary.M2Constraint)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