use of org.alfresco.service.cmr.dictionary.Constraint in project records-management by Alfresco.
the class RMCaveatConfigServiceImpl method getAllRMConstraints.
/**
* Get all Constraint Lists
*/
public Set<RMConstraintInfo> getAllRMConstraints() {
Set<RMConstraintInfo> info = new HashSet<RMConstraintInfo>();
List<ConstraintDefinition> defs = new ArrayList<ConstraintDefinition>(10);
for (QName caveatModelQName : rmCaveatConfigComponent.getRMCaveatModels()) {
defs.addAll(recordsManagementAdminService.getCustomConstraintDefinitions(caveatModelQName));
}
for (ConstraintDefinition dictionaryDef : defs) {
Constraint con = dictionaryDef.getConstraint();
if (con instanceof RMListOfValuesConstraint) {
final RMListOfValuesConstraint def = (RMListOfValuesConstraint) con;
RMConstraintInfo i = new RMConstraintInfo();
i.setName(def.getShortName());
i.setTitle(def.getTitle());
// note: assumes only one caveat/LOV against a given property
List<String> allowedValues = AuthenticationUtil.runAs(new RunAsWork<List<String>>() {
public List<String> doWork() {
return def.getAllowedValues();
}
}, AuthenticationUtil.getSystemUserName());
i.setAllowedValues(allowedValues.toArray(new String[allowedValues.size()]));
i.setCaseSensitive(def.isCaseSensitive());
info.add(i);
}
}
return info;
}
use of org.alfresco.service.cmr.dictionary.Constraint in project records-management by Alfresco.
the class RecordsManagementAdminServiceImplTest method testCreateCustomConstraints.
public void testCreateCustomConstraints() throws Exception {
final int beforeCnt = retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Integer>() {
public Integer execute() throws Throwable {
List<ConstraintDefinition> result = rmAdminService.getCustomConstraintDefinitions(RecordsManagementCustomModel.RM_CUSTOM_MODEL);
assertNotNull(result);
return result.size();
}
});
final String conTitle = "test title - " + testRunID;
final List<String> allowedValues = new ArrayList<String>(3);
allowedValues.add("RED");
allowedValues.add("AMBER");
allowedValues.add("GREEN");
final QName testCon = retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<QName>() {
public QName execute() throws Throwable {
String conLocalName = "test-" + testRunID;
final QName result = QName.createQName(RecordsManagementCustomModel.RM_CUSTOM_URI, conLocalName);
rmAdminService.addCustomConstraintDefinition(result, conTitle, true, allowedValues, MatchLogic.AND);
return result;
}
});
// Set the current security context as System - to see allowed values (unless caveat config is also updated for admin)
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
List<ConstraintDefinition> customConstraintDefs = rmAdminService.getCustomConstraintDefinitions(RecordsManagementCustomModel.RM_CUSTOM_MODEL);
assertEquals(beforeCnt + 1, customConstraintDefs.size());
boolean found = false;
for (ConstraintDefinition conDef : customConstraintDefs) {
if (conDef.getName().equals(testCon)) {
assertEquals(conTitle, conDef.getTitle(dictionaryService));
Constraint con = conDef.getConstraint();
assertTrue(con instanceof RMListOfValuesConstraint);
assertEquals("LIST", ((RMListOfValuesConstraint) con).getType());
assertEquals(3, ((RMListOfValuesConstraint) con).getAllowedValues().size());
found = true;
break;
}
}
assertTrue(found);
return null;
}
});
// Set the current security context as admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
allowedValues.clear();
allowedValues.add("RED");
allowedValues.add("YELLOW");
rmAdminService.changeCustomConstraintValues(testCon, allowedValues);
return null;
}
});
// Set the current security context as System - to see allowed values (unless caveat config is also updated for admin)
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
List<ConstraintDefinition> customConstraintDefs = rmAdminService.getCustomConstraintDefinitions(RecordsManagementCustomModel.RM_CUSTOM_MODEL);
assertEquals(beforeCnt + 1, customConstraintDefs.size());
boolean found = false;
for (ConstraintDefinition conDef : customConstraintDefs) {
if (conDef.getName().equals(testCon)) {
assertEquals(conTitle, conDef.getTitle(dictionaryService));
Constraint con = conDef.getConstraint();
assertTrue(con instanceof RMListOfValuesConstraint);
assertEquals("LIST", ((RMListOfValuesConstraint) con).getType());
assertEquals(2, ((RMListOfValuesConstraint) con).getAllowedValues().size());
found = true;
break;
}
}
assertTrue(found);
return null;
}
});
// Set the current security context as admin
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
// Add custom property to record with test constraint
retryingTransactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>() {
public Void execute() throws Throwable {
String propLocalName = "myProp-" + testRunID;
QName dataType = DataTypeDefinition.TEXT;
String propTitle = "My property title";
String description = "My property description";
String defaultValue = null;
boolean multiValued = false;
boolean mandatory = false;
boolean isProtected = false;
QName propName = rmAdminService.addCustomPropertyDefinition(null, ASPECT_RECORD, propLocalName, dataType, propTitle, description, defaultValue, multiValued, mandatory, isProtected, testCon);
createdCustomProperties.add(propName);
return null;
}
});
}
use of org.alfresco.service.cmr.dictionary.Constraint 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