Search in sources :

Example 6 with M2Model

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

the class RecordsManagementAdminServiceImpl method addCustomConstraintDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#addCustomConstraintDefinition(org.alfresco.service.namespace.QName, java.lang.String, boolean, java.util.List, org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint.MatchLogic)
 */
public void addCustomConstraintDefinition(QName constraintName, String title, boolean caseSensitive, List<String> allowedValues, MatchLogic matchLogic) {
    mandatory("constraintName", constraintName);
    mandatoryString("title", title);
    mandatory("allowedValues", allowedValues);
    mandatory("matchLogic", matchLogic);
    NodeRef modelRef = getCustomModelRef(constraintName.getNamespaceURI());
    M2Model deserializedModel = readCustomContentModel(modelRef);
    String constraintNameAsPrefixString = constraintName.toPrefixString(getNamespaceService());
    M2Constraint customConstraint = deserializedModel.getConstraint(constraintNameAsPrefixString);
    if (customConstraint != null) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_CONSTRAINT_EXISTS, constraintNameAsPrefixString));
    }
    M2Constraint newCon = deserializedModel.createConstraint(constraintNameAsPrefixString, CUSTOM_CONSTRAINT_TYPE);
    newCon.setTitle(title);
    newCon.createParameter(PARAM_ALLOWED_VALUES, allowedValues);
    newCon.createParameter(PARAM_CASE_SENSITIVE, caseSensitive ? "true" : "false");
    newCon.createParameter(PARAM_MATCH_LOGIC, matchLogic.toString());
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("addCustomConstraintDefinition: " + constraintNameAsPrefixString + " (valueCnt: " + allowedValues.size() + ")");
    }
}
Also used : M2Constraint(org.alfresco.repo.dictionary.M2Constraint) NodeRef(org.alfresco.service.cmr.repository.NodeRef) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ParameterCheck.mandatoryString(org.springframework.extensions.surf.util.ParameterCheck.mandatoryString)

Example 7 with M2Model

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

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

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

Example 10 with M2Model

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

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