use of org.alfresco.service.cmr.dictionary.Constraint in project alfresco-remote-api by Alfresco.
the class WorkflowModelBuilder method buildPropertyLabels.
private Map<String, String> buildPropertyLabels(WorkflowTask task, Map<String, Object> properties) {
TypeDefinition taskType = task.getDefinition().getMetadata();
final Map<QName, PropertyDefinition> propDefs = taskType.getProperties();
return CollectionUtils.transform(properties, new Function<Entry<String, Object>, Pair<String, String>>() {
@Override
public Pair<String, String> apply(Entry<String, Object> entry) {
String propName = entry.getKey();
PropertyDefinition propDef = propDefs.get(qNameConverter.mapNameToQName(propName));
if (propDef != null) {
List<ConstraintDefinition> constraints = propDef.getConstraints();
for (ConstraintDefinition constraintDef : constraints) {
Constraint constraint = constraintDef.getConstraint();
if (constraint instanceof ListOfValuesConstraint) {
ListOfValuesConstraint listConstraint = (ListOfValuesConstraint) constraint;
String label = listConstraint.getDisplayLabel(String.valueOf(entry.getValue()), dictionaryService);
return new Pair<String, String>(propName, label);
}
}
}
return null;
}
});
}
use of org.alfresco.service.cmr.dictionary.Constraint in project acs-community-packaging by Alfresco.
the class UIStoreSelector method createList.
/**
* @return List of SelectItem components
*/
protected List<SelectItem> createList() {
List<SelectItem> items = new ArrayList<SelectItem>(5);
Constraint storesConstraint = ConstraintRegistry.getInstance().getConstraint("defaultStoreSelector");
for (String store : ((ListOfValuesConstraint) storesConstraint).getAllowedValues()) {
items.add(new SelectItem(store, store));
}
// make sure the list is sorted by the values
QuickSort sorter = new QuickSort(items, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
sorter.sort();
return items;
}
use of org.alfresco.service.cmr.dictionary.Constraint in project records-management by Alfresco.
the class RMCaveatConfigComponentImpl method hasAccess.
/**
* Check whether access to 'record component' node is vetoed for current user due to caveat(s)
*
* @param nodeRef
* @return false, if caveat(s) veto access otherwise return true
*/
@SuppressWarnings("unchecked")
public boolean hasAccess(NodeRef nodeRef) {
try {
if ((!nodeService.exists(nodeRef)) || (caveatAspectQNames.size() == 0)) {
return true;
}
boolean found = false;
for (QName caveatAspectQName : caveatAspectQNames) {
if (nodeService.hasAspect(nodeRef, caveatAspectQName)) {
found = true;
break;
}
}
if (!found) {
// no caveat aspect
return true;
} else {
// check for caveats
String userName = AuthenticationUtil.getRunAsUser();
if (userName != null) {
// check all text properties
Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
for (Map.Entry<QName, Serializable> entry : props.entrySet()) {
QName propName = entry.getKey();
PropertyDefinition propDef = dictionaryService.getProperty(propName);
if ((propDef != null) && (propDef.getDataType().getName().equals(DATATYPE_TEXT))) {
List<ConstraintDefinition> conDefs = propDef.getConstraints();
for (ConstraintDefinition conDef : conDefs) {
Constraint con = conDef.getConstraint();
if (con instanceof RMListOfValuesConstraint) {
RMListOfValuesConstraint rmCon = ((RMListOfValuesConstraint) con);
String conName = rmCon.getShortName();
MatchLogic matchLogic = rmCon.getMatchLogicEnum();
Map<String, List<String>> caveatConstraintDef = caveatConfig.get(conName);
if (caveatConstraintDef == null) {
continue;
} else {
Set<String> userGroupNames = authorityService.getAuthoritiesForUser(userName);
List<String> allowedValues = getRMAllowedValues(userName, userGroupNames, conName);
List<String> propValues = null;
Object val = entry.getValue();
if (val instanceof String) {
propValues = new ArrayList<String>(1);
propValues.add((String) val);
} else if (val instanceof List) {
propValues = (List<String>) val;
}
if (propValues != null && !isAllowed(propValues, allowedValues, matchLogic)) {
if (logger.isDebugEnabled()) {
logger.debug("Veto access: caveat=" + conName + ", userName=" + userName + ", nodeRef=" + nodeRef + ", propName=" + propName + ", propValues=" + propValues + ", allowedValues=" + allowedValues);
}
return false;
}
}
}
}
}
}
}
return true;
}
} catch (AccessDeniedException ade) {
return false;
}
}
use of org.alfresco.service.cmr.dictionary.Constraint in project records-management by Alfresco.
the class RMCaveatConfigComponentImpl 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.Constraint in project records-management by Alfresco.
the class RMCaveatConfigServiceImpl method updateRMConstraintAllowedValues.
/**
* Update The allowed values for an RM Constraint.
*
* @param listName The name of the list.
* @param allowedValues the new alowed values
*/
public RMConstraintInfo updateRMConstraintAllowedValues(String listName, String[] allowedValues) {
QName listQName = QName.createQName(listName, namespaceService);
if (allowedValues != null) {
List<String> allowedValueList = new ArrayList<String>();
for (String value : allowedValues) {
allowedValueList.add(value);
}
ConstraintDefinition dictionaryDef = dictionaryService.getConstraint(listQName);
Constraint con = dictionaryDef.getConstraint();
if (con instanceof RMListOfValuesConstraint) {
final RMListOfValuesConstraint def = (RMListOfValuesConstraint) con;
List<String> oldAllowedValues = AuthenticationUtil.runAs(new RunAsWork<List<String>>() {
public List<String> doWork() {
return def.getAllowedValues();
}
}, AuthenticationUtil.getSystemUserName());
/**
* Deal with any additions
*/
for (String newValue : allowedValueList) {
if (!oldAllowedValues.contains(newValue) && logger.isDebugEnabled()) {
// This is an addition
logger.debug("value added to list:" + listQName + ":" + newValue);
}
}
/**
* Deal with any deletions
*/
for (String oldValue : oldAllowedValues) {
if (!allowedValueList.contains(oldValue)) {
// This is a deletion
if (logger.isDebugEnabled()) {
logger.debug("value removed from list:" + listQName + ":" + oldValue);
}
removeRMConstraintListValue(listName, oldValue);
}
}
}
recordsManagementAdminService.changeCustomConstraintValues(listQName, allowedValueList);
}
return getRMConstraint(listName);
}
Aggregations