Search in sources :

Example 6 with M2Property

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

the class RecordsManagementAdminServiceImpl method setCustomPropertyDefinitionConstraint.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementAdminService#setCustomPropertyDefinitionConstraint(org.alfresco.service.namespace.QName, org.alfresco.service.namespace.QName)
 */
public QName setCustomPropertyDefinitionConstraint(QName propQName, QName newLovConstraint) {
    mandatory("propQName", propQName);
    mandatory("newLovConstraint", newLovConstraint);
    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 targetProp = findProperty(propQName, deserializedModel);
    String dataType = targetProp.getType();
    if (!dataType.equals(DataTypeDefinition.TEXT.toPrefixString(getNamespaceService()))) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(CannotApplyConstraintMetadataException.MSG_CANNOT_APPLY_CONSTRAINT, newLovConstraint, targetProp.getName(), dataType));
    }
    String lovConstraintQNameAsString = newLovConstraint.toPrefixString(getNamespaceService());
    // Add the constraint - if it isn't already there (there should only be one constraint).
    String refOfExistingConstraint = (targetProp.getConstraints().isEmpty() ? null : targetProp.getConstraints().get(0).getRef());
    if (refOfExistingConstraint != null) {
        targetProp.removeConstraintRef(refOfExistingConstraint);
    }
    targetProp.addConstraintRef(lovConstraintQNameAsString);
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("addCustomPropertyDefinitionConstraint: " + lovConstraintQNameAsString);
    }
    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)

Example 7 with M2Property

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

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

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

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