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() + ")");
}
}
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 + ")");
}
}
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);
}
}
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;
}
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;
}
Aggregations