Search in sources :

Example 16 with AspectDefinition

use of org.alfresco.service.cmr.dictionary.AspectDefinition 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 17 with AspectDefinition

use of org.alfresco.service.cmr.dictionary.AspectDefinition in project records-management by Alfresco.

the class RecordsManagementAdminServiceImpl method getCustomisable.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#getCustomisable(org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
public Set<QName> getCustomisable(NodeRef nodeRef) {
    mandatory("nodeRef", nodeRef);
    Set<QName> result = new HashSet<QName>(5);
    // Check the nodes hierarchy for customisable types
    QName type = getNodeService().getType(nodeRef);
    while (type != null && !ContentModel.TYPE_CMOBJECT.equals(type)) {
        // Add to the list if the type is customisable
        if (isCustomisable(type)) {
            result.add(type);
        }
        // Type and get the types parent
        TypeDefinition def = getDictionaryService().getType(type);
        if (def != null) {
            type = def.getParentName();
        } else {
            type = null;
        }
    }
    // Get all the nodes aspects
    Set<QName> aspects = getNodeService().getAspects(nodeRef);
    for (QName aspect : aspects) {
        QName tempAspect = QName.createQName(aspect.toString());
        while (tempAspect != null) {
            // Add to the list if the aspect is customisable
            if (isCustomisable(tempAspect)) {
                result.add(tempAspect);
            }
            // Try and get the parent aspect
            AspectDefinition aspectDef = getDictionaryService().getAspect(tempAspect);
            if (aspectDef != null) {
                tempAspect = aspectDef.getParentName();
            } else {
                tempAspect = null;
            }
        }
    }
    return result;
}
Also used : QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) HashSet(java.util.HashSet) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 18 with AspectDefinition

use of org.alfresco.service.cmr.dictionary.AspectDefinition in project records-management by Alfresco.

the class RecordsManagementNodeFormFilter method addRecordMetadataPropertyFieldsToGroup.

/**
 * @param form
 * @param nodeRef
 */
protected void addRecordMetadataPropertyFieldsToGroup(Form form, NodeRef nodeRef) {
    Set<QName> aspects = recordService.getRecordMetadataAspects(nodeRef);
    for (QName aspect : aspects) {
        if (nodeService.hasAspect(nodeRef, aspect)) {
            String aspectName = aspect.getPrefixedQName(namespaceService).toPrefixString().replace(":", "-");
            String setId = RM_METADATA_PREFIX + aspectName;
            String setLabel = null;
            AspectDefinition aspectDefinition = dictionaryService.getAspect(aspect);
            if (aspectDefinition != null) {
                setLabel = aspectDefinition.getTitle(new StaticMessageLookup());
            }
            addPropertyFieldsToGroup(form, dictionaryService.getPropertyDefs(aspect), setId, setLabel);
        }
    }
}
Also used : StaticMessageLookup(org.alfresco.repo.i18n.StaticMessageLookup) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition)

Example 19 with AspectDefinition

use of org.alfresco.service.cmr.dictionary.AspectDefinition in project records-management by Alfresco.

the class ApplyCustomTypeAction method getParameterDefintions.

@Override
protected synchronized List<ParameterDefinition> getParameterDefintions() {
    // We can take these parameter definitions from the properties defined in the dod model.
    if (this.parameterDefinitions == null) {
        AspectDefinition aspectDefinition = getDictionaryService().getAspect(customTypeAspect);
        if (aspectDefinition == null) {
            throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CUSTOM_ASPECT_NOT_RECOGNISED, customTypeAspect));
        }
        Map<QName, PropertyDefinition> props = aspectDefinition.getProperties();
        this.parameterDefinitions = new ArrayList<ParameterDefinition>(props.size());
        for (Map.Entry<QName, PropertyDefinition> entry : props.entrySet()) {
            String paramName = entry.getKey().toPrefixString(getNamespaceService());
            PropertyDefinition value = entry.getValue();
            QName paramType = value.getDataType().getName();
            boolean paramIsMandatory = value.isMandatory();
            parameterDefinitions.add(new ParameterDefinitionImpl(paramName, paramType, paramIsMandatory, null));
        }
    }
    return parameterDefinitions;
}
Also used : QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) HashMap(java.util.HashMap) Map(java.util.Map) ParameterDefinitionImpl(org.alfresco.repo.action.ParameterDefinitionImpl) ParameterDefinition(org.alfresco.service.cmr.action.ParameterDefinition)

Example 20 with AspectDefinition

use of org.alfresco.service.cmr.dictionary.AspectDefinition in project records-management by Alfresco.

the class RecordServiceImpl method validateForCompletion.

/**
 * Helper method to validate whether the node is in a state suitable for completion
 *
 * @param nodeRef node reference
 * @throws Exception if node not valid for completion
 */
private void validateForCompletion(NodeRef nodeRef) {
    if (!nodeService.exists(nodeRef)) {
        LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
        throw new IntegrityException("The record does not exist.", null);
    }
    if (!isRecord(nodeRef)) {
        LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
        throw new IntegrityException("The node is not a record.", null);
    }
    if (freezeService.isFrozen(nodeRef)) {
        LOGGER.warn(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, nodeRef.toString()));
        throw new IntegrityException("The record is frozen.", null);
    }
    if (isDeclared(nodeRef)) {
        throw new IntegrityException("The record is already completed.", null);
    }
    // if the record is newly created make sure the record identifier is set before completing the record
    Set<NodeRef> newRecords = transactionalResourceHelper.getSet(RecordServiceImpl.KEY_NEW_RECORDS);
    if (newRecords.contains(nodeRef)) {
        generateRecordIdentifier(nodeService, identifierService, nodeRef);
    }
    // Validate that all mandatory properties, if any, are present
    List<String> missingProperties = new ArrayList<>(5);
    // Aspect not already defined - check mandatory properties then add
    if (checkMandatoryPropertiesEnabled) {
        Map<QName, Serializable> nodeRefProps = nodeService.getProperties(nodeRef);
        QName nodeRefType = nodeService.getType(nodeRef);
        // check for missing mandatory metadata from type definitions
        TypeDefinition typeDef = dictionaryService.getType(nodeRefType);
        checkDefinitionMandatoryPropsSet(typeDef, nodeRefProps, missingProperties);
        // check for missing mandatory metadata from aspect definitions
        Set<QName> aspects = nodeService.getAspects(nodeRef);
        for (QName aspect : aspects) {
            AspectDefinition aspectDef = dictionaryService.getAspect(aspect);
            checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
        }
        // check for missing mandatory metadata from custom aspect definitions
        QName customAspect = getCustomAspectImpl(nodeRefType);
        AspectDefinition aspectDef = dictionaryService.getAspect(customAspect);
        checkDefinitionMandatoryPropsSet(aspectDef, nodeRefProps, missingProperties);
        if (!missingProperties.isEmpty()) {
            LOGGER.debug(buildMissingPropertiesErrorString(missingProperties));
            throw new RecordMissingMetadataException("The record has missing mandatory properties.");
        }
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)22 QName (org.alfresco.service.namespace.QName)21 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 NodeRef (org.alfresco.service.cmr.repository.NodeRef)5 Map (java.util.Map)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 Serializable (java.io.Serializable)3 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)3 HashSet (java.util.HashSet)2 ParameterDefinitionImpl (org.alfresco.repo.action.ParameterDefinitionImpl)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)2 CustomModelDefinition (org.alfresco.service.cmr.dictionary.CustomModelDefinition)2 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)2 CustomProperty (org.alfresco.web.config.AdvancedSearchConfigElement.CustomProperty)2 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 SelectItem (javax.faces.model.SelectItem)1