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