Search in sources :

Example 6 with Constraint

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;
        }
    });
}
Also used : Constraint(org.alfresco.service.cmr.dictionary.Constraint) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) Entry(java.util.Map.Entry) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) ArrayList(java.util.ArrayList) List(java.util.List) Pair(org.alfresco.util.Pair)

Example 7 with Constraint

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;
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) Constraint(org.alfresco.service.cmr.dictionary.Constraint) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) SelectItem(javax.faces.model.SelectItem) ArrayList(java.util.ArrayList) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)

Example 8 with Constraint

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;
    }
}
Also used : Serializable(java.io.Serializable) AccessDeniedException(net.sf.acegisecurity.AccessDeniedException) Constraint(org.alfresco.service.cmr.dictionary.Constraint) QName(org.alfresco.service.namespace.QName) MatchLogic(org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint.MatchLogic) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) List(java.util.List) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap)

Example 9 with Constraint

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;
}
Also used : Constraint(org.alfresco.service.cmr.dictionary.Constraint) List(java.util.List) ArrayList(java.util.ArrayList) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Example 10 with Constraint

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);
}
Also used : Constraint(org.alfresco.service.cmr.dictionary.Constraint) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition)

Aggregations

Constraint (org.alfresco.service.cmr.dictionary.Constraint)13 ArrayList (java.util.ArrayList)12 ConstraintDefinition (org.alfresco.service.cmr.dictionary.ConstraintDefinition)11 List (java.util.List)8 QName (org.alfresco.service.namespace.QName)7 ListOfValuesConstraint (org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)5 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)5 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 RMListOfValuesConstraint (org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint)2 MimetypeMap (org.alfresco.repo.content.MimetypeMap)2 JSONObject (org.json.JSONObject)2 Serializable (java.io.Serializable)1 Entry (java.util.Map.Entry)1 SelectItem (javax.faces.model.SelectItem)1 AccessDeniedException (net.sf.acegisecurity.AccessDeniedException)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 MatchLogic (org.alfresco.module.org_alfresco_module_rm.caveat.RMListOfValuesConstraint.MatchLogic)1 M2Constraint (org.alfresco.repo.dictionary.M2Constraint)1