use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project records-management by Alfresco.
the class RMCaveatConfigServiceImpl method getRMConstraint.
/**
* Get an RMConstraintInfo
* @param listQName
* @return the constraint or null if it does not exist
*/
public RMConstraintInfo getRMConstraint(QName listQName) {
ConstraintDefinition dictionaryDef = dictionaryService.getConstraint(listQName);
if (dictionaryDef != null) {
Constraint con = dictionaryDef.getConstraint();
if (con instanceof RMListOfValuesConstraint) {
final RMListOfValuesConstraint def = (RMListOfValuesConstraint) con;
RMConstraintInfo info = new RMConstraintInfo();
info.setName(listQName.toPrefixString());
info.setTitle(con.getTitle());
List<String> allowedValues = AuthenticationUtil.runAs(new RunAsWork<List<String>>() {
public List<String> doWork() {
return def.getAllowedValues();
}
}, AuthenticationUtil.getSystemUserName());
info.setAllowedValues(allowedValues.toArray(new String[allowedValues.size()]));
info.setCaseSensitive(def.isCaseSensitive());
return info;
}
}
return null;
}
use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project records-management by Alfresco.
the class RecordsManagementAdminServiceImpl method getCustomConstraintDefinitions.
/**
* @see org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService#getCustomConstraintDefinitions(org.alfresco.service.namespace.QName)
*/
public List<ConstraintDefinition> getCustomConstraintDefinitions(QName modelQName) {
mandatory("modelQName", modelQName);
Collection<ConstraintDefinition> conDefs = getDictionaryService().getConstraints(modelQName, true);
for (ConstraintDefinition conDef : conDefs) {
Constraint con = conDef.getConstraint();
if (!(con instanceof RMListOfValuesConstraint)) {
conDefs.remove(conDef);
}
}
return new ArrayList<ConstraintDefinition>(conDefs);
}
use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project records-management by Alfresco.
the class CustomPropertyDefinitionPut method updatePropertyDefinition.
/**
* If label has a non-null value, it is set on the property def.
* If constraintRef has a non-null value, it is set on this propDef.
* If constraintRef has a null value, all constraints for that propDef are removed.
*
* @param params
* @return
* @throws CustomMetadataException
*/
protected QName updatePropertyDefinition(Map<String, Serializable> params) throws CustomMetadataException {
QName result = null;
boolean updated = false;
String propId = (String) params.get(PROP_ID);
ParameterCheck.mandatoryString("propId", propId);
QName propQName = rmAdminService.getQNameForClientId(propId);
if (propQName == null) {
propQName = rmAdminService.getQNameForClientId(URLEncoder.encode(propId));
}
if (propQName == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Could not find property definition for: " + propId);
}
if (params.containsKey(PARAM_CONSTRAINT_REF)) {
String constraintRef = (String) params.get(PARAM_CONSTRAINT_REF);
List<ConstraintDefinition> constraints = rmAdminService.getCustomPropertyDefinitions().get(propQName).getConstraints();
if (constraintRef == null) {
result = rmAdminService.removeCustomPropertyDefinitionConstraints(propQName);
updated = constraints.isEmpty() ? false : true;
} else {
boolean exists = false;
for (ConstraintDefinition constraintDefinition : constraints) {
if (constraintDefinition.getConstraint().getShortName().equalsIgnoreCase(constraintRef)) {
exists = true;
break;
}
}
if (!exists) {
QName constraintRefQName = QName.createQName(constraintRef, getNamespaceService());
result = rmAdminService.setCustomPropertyDefinitionConstraint(propQName, constraintRefQName);
updated = true;
}
}
}
if (params.containsKey(PARAM_LABEL)) {
String label = (String) params.get(PARAM_LABEL);
try {
result = rmAdminService.updateCustomPropertyDefinitionName(propQName, label);
} catch (PropertyAlreadyExistsMetadataException ex) {
if (!updated) {
String propIdAsString = rmAdminService.getQNameForClientId(label).toPrefixString(getNamespaceService());
throw new PropertyAlreadyExistsMetadataException(propIdAsString);
}
}
}
return result;
}
use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method createCustomModel.
@Override
public CustomModel createCustomModel(M2Model m2Model) {
// Check the current user is authorised to import the custom model
validateCurrentUser();
validateImportedM2Model(m2Model);
CompiledModel compiledModel = null;
try {
compiledModel = customModelService.compileModel(m2Model);
} catch (CustomModelConstraintException mce) {
throw new ConstraintViolatedException(mce.getMessage());
} catch (InvalidCustomModelException iex) {
throw new InvalidArgumentException(iex.getMessage());
}
ModelDefinition modelDefinition = compiledModel.getModelDefinition();
CustomModel customModel = new CustomModel();
customModel.setName(modelDefinition.getName().getLocalName());
customModel.setAuthor(modelDefinition.getAuthor());
customModel.setDescription(modelDefinition.getDescription(dictionaryService));
customModel.setStatus(ModelStatus.DRAFT);
NamespaceDefinition nsd = modelDefinition.getNamespaces().iterator().next();
customModel.setNamespaceUri(nsd.getUri());
customModel.setNamespacePrefix(nsd.getPrefix());
List<CustomType> customTypes = convertToCustomTypes(compiledModel.getTypes(), false);
List<CustomAspect> customAspects = convertToCustomAspects(compiledModel.getAspects(), false);
List<ConstraintDefinition> constraintDefinitions = CustomModelDefinitionImpl.removeInlineConstraints(compiledModel);
List<CustomModelConstraint> customModelConstraints = convertToCustomModelConstraints(constraintDefinitions);
customModel.setTypes(customTypes);
customModel.setAspects(customAspects);
customModel.setConstraints(customModelConstraints);
return createCustomModelImpl(customModel, false);
}
use of org.alfresco.service.cmr.dictionary.ConstraintDefinition in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method getFormModelElements.
/**
* @param type the type to get the elements for
* @param paging Paging
* @return collection with all valid form-model elements for the given type.
*/
public CollectionWithPagingInfo<FormModelElement> getFormModelElements(TypeDefinition type, Paging paging) {
Map<QName, PropertyDefinition> taskProperties = type.getProperties();
Set<QName> typesToExclude = getTypesToExclude(type);
List<FormModelElement> page = new ArrayList<FormModelElement>();
for (Entry<QName, PropertyDefinition> entry : taskProperties.entrySet()) {
String name = entry.getKey().toPrefixString(namespaceService).replace(':', '_');
// Only add properties which are not part of an excluded type
if (!typesToExclude.contains(entry.getValue().getContainerClass().getName()) && excludeModelTypes.contains(name) == false) {
FormModelElement element = new FormModelElement();
element.setName(name);
element.setQualifiedName(entry.getKey().toString());
element.setTitle(entry.getValue().getTitle(dictionaryService));
element.setRequired(entry.getValue().isMandatory());
element.setDataType(entry.getValue().getDataType().getName().toPrefixString(namespaceService));
element.setDefaultValue(entry.getValue().getDefaultValue());
if (entry.getValue().getConstraints() != null) {
for (ConstraintDefinition constraintDef : entry.getValue().getConstraints()) {
Constraint constraint = constraintDef.getConstraint();
if (constraint != null && constraint instanceof ListOfValuesConstraint) {
ListOfValuesConstraint valuesConstraint = (ListOfValuesConstraint) constraint;
if (valuesConstraint.getAllowedValues() != null && valuesConstraint.getAllowedValues().size() > 0) {
element.setAllowedValues(valuesConstraint.getAllowedValues());
}
}
}
}
page.add(element);
}
}
Map<QName, AssociationDefinition> taskAssociations = type.getAssociations();
for (Entry<QName, AssociationDefinition> entry : taskAssociations.entrySet()) {
// Only add associations which are not part of an excluded type
if (!typesToExclude.contains(entry.getValue().getSourceClass().getName())) {
FormModelElement element = new FormModelElement();
element.setName(entry.getKey().toPrefixString(namespaceService).replace(':', '_'));
element.setQualifiedName(entry.getKey().toString());
element.setTitle(entry.getValue().getTitle(dictionaryService));
element.setRequired(entry.getValue().isTargetMandatory());
element.setDataType(entry.getValue().getTargetClass().getName().toPrefixString(namespaceService));
page.add(element);
}
}
return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
Aggregations