Search in sources :

Example 21 with M2Model

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

the class RecordsManagementAdminBase method readCustomContentModel.

/**
 * Gets the deserialized model
 *
 * @param modelNodeRef The node reference of the model
 * @return The deserialized model
 */
protected M2Model readCustomContentModel(NodeRef modelNodeRef) {
    ContentReader reader = getContentService().getReader(modelNodeRef, ContentModel.TYPE_CONTENT);
    if (!reader.exists()) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CUSTOM_MODEL_NO_CONTENT, modelNodeRef.toString()));
    }
    InputStream contentIn = null;
    M2Model deserializedModel = null;
    try {
        contentIn = reader.getContentInputStream();
        deserializedModel = M2Model.createModel(contentIn);
    } finally {
        try {
            if (contentIn != null) {
                contentIn.close();
            }
        } catch (IOException ignored) {
        // Intentionally empty.
        }
    }
    return deserializedModel;
}
Also used : InputStream(java.io.InputStream) ContentReader(org.alfresco.service.cmr.repository.ContentReader) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException)

Example 22 with M2Model

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

the class RecordsManagementAdminServiceImpl method unmakeCustomisable.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#unmakeCustomisable(org.alfresco.service.namespace.QName)
 */
@Override
public void unmakeCustomisable(QName type) {
    mandatory("type", type);
    if (customisableTypes == null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_SERVICE_NOT_INIT));
    }
    QName customAspect = getCustomAspect(type);
    if (getDictionaryService().getAspect(customAspect) != null) {
        // TODO need to confirm that the custom properties are not being used!
        NodeRef modelRef = getCustomModelRef(customAspect.getNamespaceURI());
        M2Model model = readCustomContentModel(modelRef);
        try {
            // Create the new aspect to hold the custom properties
            model.removeAspect(customAspect.toPrefixString(getNamespaceService()));
        } finally {
            writeCustomContentModel(modelRef, model);
        }
        customisableTypes.remove(type);
    }
}
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)

Example 23 with M2Model

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

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

the class RecordsManagementAdminServiceImpl method setCustomPropertyDefinitionLabel.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#setCustomPropertyDefinitionLabel(org.alfresco.service.namespace.QName, java.lang.String)
 */
public QName setCustomPropertyDefinitionLabel(QName propQName, String newLabel) {
    mandatory("propQName", propQName);
    PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
    if (propDefn == null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
    }
    if (newLabel == null) {
        return propQName;
    }
    NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    M2Property targetProperty = findProperty(propQName, deserializedModel);
    targetProperty.setTitle(newLabel);
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("setCustomPropertyDefinitionLabel: " + propQName + "=" + newLabel);
    }
    return propQName;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) M2Property(org.alfresco.repo.dictionary.M2Property) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 25 with M2Model

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

Aggregations

M2Model (org.alfresco.repo.dictionary.M2Model)32 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)18 NodeRef (org.alfresco.service.cmr.repository.NodeRef)15 M2Aspect (org.alfresco.repo.dictionary.M2Aspect)10 QName (org.alfresco.service.namespace.QName)10 ParameterCheck.mandatoryString (org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)10 M2Property (org.alfresco.repo.dictionary.M2Property)8 InputStream (java.io.InputStream)6 M2Constraint (org.alfresco.repo.dictionary.M2Constraint)6 File (java.io.File)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 M2ClassAssociation (org.alfresco.repo.dictionary.M2ClassAssociation)4 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ArrayList (java.util.ArrayList)3 ZipFile (java.util.zip.ZipFile)3 AlfrescoModel (org.alfresco.solr.client.AlfrescoModel)3 HashSet (java.util.HashSet)2 M2Namespace (org.alfresco.repo.dictionary.M2Namespace)2