Search in sources :

Example 1 with M2Property

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

Example 2 with M2Property

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

the class CustomModelsImpl method setM2Properties.

private void setM2Properties(M2Class m2Class, List<CustomModelProperty> properties, String namespacePrefix, Set<Pair<String, String>> namespacesToImport) {
    if (properties != null) {
        for (CustomModelProperty prop : properties) {
            validateName(prop.getName(), "cmm.rest_api.property_name_null");
            M2Property m2Property = m2Class.createProperty(constructName(prop.getName(), namespacePrefix));
            m2Property.setTitle(prop.getTitle());
            m2Property.setDescription(prop.getDescription());
            m2Property.setMandatory(prop.isMandatory());
            m2Property.setMandatoryEnforced(prop.isMandatoryEnforced());
            m2Property.setMultiValued(prop.isMultiValued());
            String dataType = prop.getDataType();
            // Default type is d:text
            if (StringUtils.isBlank(dataType)) {
                dataType = DEFAULT_DATA_TYPE;
            } else {
                if (!dataType.contains(":")) {
                    throw new InvalidArgumentException("cmm.rest_api.property_datatype_invalid", new Object[] { dataType });
                }
            }
            namespacesToImport.add(resolveToUriAndPrefix(dataType));
            try {
                // validate default values
                this.valueDataTypeValidator.validateValue(dataType, prop.getDefaultValue());
            } catch (Exception ex) {
                throw new InvalidArgumentException(ex.getMessage());
            }
            m2Property.setType(dataType);
            m2Property.setDefaultValue(prop.getDefaultValue());
            // Set indexing options
            m2Property.setIndexed(prop.isIndexed());
            // so it can support boolean data type.
            if (!BOOLEAN_DATA_TYPE.equals(dataType)) {
                if (Facetable.TRUE == prop.getFacetable()) {
                    m2Property.setFacetable(true);
                } else if (Facetable.FALSE == prop.getFacetable()) {
                    m2Property.setFacetable(false);
                }
            }
            m2Property.setIndexTokenisationMode(prop.getIndexTokenisationMode());
            // Check for constraints
            List<String> constraintRefs = prop.getConstraintRefs();
            List<CustomModelConstraint> constraints = prop.getConstraints();
            if (constraintRefs.size() > 0) {
                for (String ref : constraintRefs) {
                    Pair<String, String> prefixLocalName = splitPrefixedQName(ref);
                    if (!namespacePrefix.equals(prefixLocalName.getFirst())) {
                        throw new ConstraintViolatedException(I18NUtil.getMessage("cmm.rest_api.constraint_ref_not_defined", ref));
                    }
                    m2Property.addConstraintRef(ref);
                }
            }
            if (constraints.size() > 0) {
                for (CustomModelConstraint modelConstraint : constraints) {
                    String constraintName = null;
                    if (modelConstraint.getName() != null) {
                        validateName(modelConstraint.getName(), CONSTRAINT_NAME_NULL_ERR);
                        constraintName = constructName(modelConstraint.getName(), namespacePrefix);
                    }
                    M2Constraint m2Constraint = m2Property.addConstraint(constraintName, modelConstraint.getType());
                    // Set title, desc and parameters
                    setConstraintOtherData(modelConstraint, m2Constraint, dataType);
                }
            }
        }
    }
}
Also used : M2Constraint(org.alfresco.repo.dictionary.M2Constraint) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) M2Property(org.alfresco.repo.dictionary.M2Property) CustomModelConstraint(org.alfresco.rest.api.model.CustomModelConstraint) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) CustomModelProperty(org.alfresco.rest.api.model.CustomModelProperty) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) ActiveModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.ActiveModelConstraintException) ModelDoesNotExistException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelDoesNotExistException) CustomModelConstraintException(org.alfresco.service.cmr.dictionary.CustomModelException.CustomModelConstraintException) InvalidCustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException.InvalidCustomModelException) ConstraintViolatedException(org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) CustomModelException(org.alfresco.service.cmr.dictionary.CustomModelException) ModelExistsException(org.alfresco.service.cmr.dictionary.CustomModelException.ModelExistsException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 3 with M2Property

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

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

the class RecordsManagementAdminServiceImpl method updateCustomPropertyDefinitionName.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#updateCustomPropertyDefinitionName(org.alfresco.service.namespace.QName, java.lang.String)
 */
public QName updateCustomPropertyDefinitionName(QName propQName, String newName) throws CustomMetadataException {
    mandatory("propQName", propQName);
    PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
    if (propDefn == null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
    }
    if (newName == null) {
        return propQName;
    }
    QName newPropQName = getQNameForClientId(newName);
    if (newPropQName != null) {
        PropertyDefinition newPropDefn = getDictionaryService().getProperty(newPropQName);
        if (newPropDefn != null && !propDefn.equals(newPropDefn)) {
            // The requested QName is already in use
            String propIdAsString = newPropQName.toPrefixString(getNamespaceService());
            throw new PropertyAlreadyExistsMetadataException(propIdAsString);
        }
    }
    NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    M2Property targetProperty = findProperty(propQName, deserializedModel);
    targetProperty.setName(new StringBuilder().append(RecordsManagementCustomModel.RM_CUSTOM_PREFIX).append(QName.NAMESPACE_PREFIX).append(newName).toString());
    targetProperty.setTitle(URLDecoder.decode(newName));
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("setCustomPropertyDefinitionLabel: " + propQName + "=" + newName);
    }
    return propQName;
}
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) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition)

Example 5 with M2Property

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

the class RecordsManagementAdminServiceImpl method removeCustomPropertyDefinitionConstraints.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#removeCustomPropertyDefinitionConstraints(org.alfresco.service.namespace.QName)
 */
public QName removeCustomPropertyDefinitionConstraints(QName propQName) {
    mandatory("propQName", propQName);
    PropertyDefinition propDefn = getDictionaryService().getProperty(propQName);
    if (propDefn == null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_PROP_EXIST, propQName));
    }
    NodeRef modelRef = getCustomModelRef(propQName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    M2Property targetProperty = findProperty(propQName, deserializedModel);
    // Need to count backwards to remove constraints
    for (int i = targetProperty.getConstraints().size() - 1; i >= 0; i--) {
        String ref = targetProperty.getConstraints().get(i).getRef();
        targetProperty.removeConstraintRef(ref);
    }
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("removeCustomPropertyDefinitionConstraints: " + propQName);
    }
    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) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) RMListOfValuesConstraint(org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint) Constraint(org.alfresco.service.cmr.dictionary.Constraint) M2Constraint(org.alfresco.repo.dictionary.M2Constraint)

Aggregations

M2Property (org.alfresco.repo.dictionary.M2Property)9 M2Model (org.alfresco.repo.dictionary.M2Model)8 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)6 ParameterCheck.mandatoryString (org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)5 M2Aspect (org.alfresco.repo.dictionary.M2Aspect)4 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)4 QName (org.alfresco.service.namespace.QName)3 M2Constraint (org.alfresco.repo.dictionary.M2Constraint)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 RMListOfValuesConstraint (org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint)1 DictionaryDAO (org.alfresco.repo.dictionary.DictionaryDAO)1 M2ClassAssociation (org.alfresco.repo.dictionary.M2ClassAssociation)1 CustomModelConstraint (org.alfresco.rest.api.model.CustomModelConstraint)1 CustomModelProperty (org.alfresco.rest.api.model.CustomModelProperty)1 ApiException (org.alfresco.rest.framework.core.exceptions.ApiException)1 ConstraintViolatedException (org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1