Search in sources :

Example 26 with M2Model

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

the class RecordsManagementAdminServiceImpl method changeCustomConstraintValues.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#changeCustomConstraintValues(org.alfresco.service.namespace.QName, java.util.List)
 */
public void changeCustomConstraintValues(QName constraintName, List<String> newAllowedValues) {
    mandatory("constraintName", constraintName);
    mandatory("newAllowedValues", newAllowedValues);
    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_CANNOT_FIND_CONSTRAINT, constraintNameAsPrefixString));
    }
    String type = customConstraint.getType();
    if (type == null || (!type.equals(CUSTOM_CONSTRAINT_TYPE) && !type.equals(CAPATIBILITY_CUSTOM_CONTRAINT_TYPE))) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNEXPECTED_TYPE_CONSTRAINT, type, constraintNameAsPrefixString, CUSTOM_CONSTRAINT_TYPE));
    }
    customConstraint.removeParameter(PARAM_ALLOWED_VALUES);
    customConstraint.createParameter(PARAM_ALLOWED_VALUES, newAllowedValues);
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("changeCustomConstraintValues: " + constraintNameAsPrefixString + " (valueCnt: " + newAllowedValues.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 27 with M2Model

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

the class RecordsManagementAdminServiceImpl method changeCustomConstraintTitle.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#changeCustomConstraintTitle(org.alfresco.service.namespace.QName, java.lang.String)
 */
public void changeCustomConstraintTitle(QName constraintName, String title) {
    mandatory("constraintName", constraintName);
    mandatoryString("title", title);
    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_CANNOT_FIND_CONSTRAINT, constraintNameAsPrefixString));
    }
    String type = customConstraint.getType();
    if ((type == null) || (!type.equals(CUSTOM_CONSTRAINT_TYPE))) {
        throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNEXPECTED_TYPE_CONSTRAINT, type, constraintNameAsPrefixString, CUSTOM_CONSTRAINT_TYPE));
    }
    customConstraint.setTitle(title);
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("changeCustomConstraintTitle: " + constraintNameAsPrefixString + " (title: " + title + ")");
    }
}
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 28 with M2Model

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

the class RecordsManagementAdminServiceImpl method removeCustomConstraintDefinition.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#removeCustomConstraintDefinition(org.alfresco.service.namespace.QName)
 */
public void removeCustomConstraintDefinition(QName constraintName) {
    mandatory("constraintName", constraintName);
    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_CANNOT_FIND_CONSTRAINT, constraintNameAsPrefixString));
    }
    deserializedModel.removeConstraint(constraintNameAsPrefixString);
    writeCustomContentModel(modelRef, deserializedModel);
    if (logger.isInfoEnabled()) {
        logger.info("deleteCustomConstraintDefinition: " + constraintNameAsPrefixString);
    }
}
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 29 with M2Model

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

the class ApplyFixMob1573Get method readCustomContentModel.

private M2Model readCustomContentModel() {
    ContentReader reader = contentService.getReader(RM_CUSTOM_MODEL_NODE_REF, ContentModel.TYPE_CONTENT);
    if (!reader.exists()) {
        throw new AlfrescoRuntimeException("RM CustomModel has no content.");
    }
    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 30 with M2Model

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

the class ApplyFixMob1573Get method executeImpl.

@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    M2Model customModel = readCustomContentModel();
    if (customModel == null) {
        throw new AlfrescoRuntimeException("Custom content model could not be read");
    }
    // Go through every custom reference defined in the custom model and make sure that it
    // has many-to-many multiplicity
    String aspectName = ASPECT_CUSTOM_ASSOCIATIONS.toPrefixString(namespaceService);
    M2Aspect customAssocsAspect = customModel.getAspect(aspectName);
    if (customAssocsAspect == null) {
        throw new AlfrescoRuntimeException("Unknown aspect: " + aspectName);
    }
    for (M2ClassAssociation classAssoc : customAssocsAspect.getAssociations()) {
        classAssoc.setSourceMany(true);
        classAssoc.setTargetMany(true);
    }
    writeCustomContentModel(customModel);
    Map<String, Object> model = new HashMap<String, Object>(1, 1.0f);
    model.put("success", true);
    return model;
}
Also used : HashMap(java.util.HashMap) M2Model(org.alfresco.repo.dictionary.M2Model) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) M2Aspect(org.alfresco.repo.dictionary.M2Aspect) M2ClassAssociation(org.alfresco.repo.dictionary.M2ClassAssociation)

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