org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint Java Examples

The following examples show how to use org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkflowModelBuilder.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
        }
    });
}
 
Example #2
Source File: SelectorPropertyContentStore.java    From alfresco-simple-content-stores with Apache License 2.0 5 votes vote down vote up
private void afterPropertiesSet_setupConstraint()
{
    if (this.selectorValuesConstraintShortName != null && !this.selectorValuesConstraintShortName.trim().isEmpty())
    {
        final ListOfValuesConstraint lovConstraint = new ListOfValuesConstraint();
        lovConstraint.setShortName(this.selectorValuesConstraintShortName);
        lovConstraint.setRegistry(this.constraintRegistry);
        lovConstraint.setAllowedValues(new ArrayList<>(this.storeBySelectorPropertyValue.keySet()));
        lovConstraint.initialize();
    }
}
 
Example #3
Source File: PropertyFieldProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private List<FieldConstraint> makeFieldConstraints(PropertyDefinition propDef)
{
    List<FieldConstraint> fieldConstraints = null;
    List<ConstraintDefinition> constraints = propDef.getConstraints();
    if (constraints != null && constraints.size() > 0)
    {
        fieldConstraints = new ArrayList<FieldConstraint>(constraints.size());
        for (ConstraintDefinition constraintDef : constraints)
        {
            Constraint constraint = constraintDef.getConstraint();
            String type = constraint.getType();
            Map<String, Object> params = constraint.getParameters();
            
            
            //ListOfValuesConstraints have special handling for localising their allowedValues.
            //If the constraint that we are currently handling is a registered constraint then
            //we need to examine the underlying constraint to see if it is a LIST constraint
            if (RegisteredConstraint.class.isAssignableFrom(constraint.getClass()))
            {
                constraint = ((RegisteredConstraint)constraint).getRegisteredConstraint();
            }
            
            if (ListOfValuesConstraint.class.isAssignableFrom(constraint.getClass()))
            {
                ListOfValuesConstraint lovConstraint = (ListOfValuesConstraint) constraint;
                List<String> allowedValues = lovConstraint.getAllowedValues();
                List<String> localisedValues = new ArrayList<String>(allowedValues.size());
                
                // Look up each localised display-label in turn.
                for (String value : allowedValues)
                {
                    String displayLabel = lovConstraint.getDisplayLabel(value, dictionaryService);
                    // Change the allowedValue entry to the format the FormsService expects for localised strings: "value|label"
                    // If there is no localisation defined for any value, then this will give us "value|value".
                    localisedValues.add(value + "|" + displayLabel);
                }
                
                // Now replace the allowedValues param with our localised version.
                params.put(ListOfValuesConstraint.ALLOWED_VALUES_PARAM, localisedValues);
            }
            FieldConstraint fieldConstraint = new FieldConstraint(type, params);
            fieldConstraints.add(fieldConstraint);
        }
    }
    return fieldConstraints;
}
 
Example #4
Source File: M2ConstraintDefinition.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected Constraint newInstance()
{
    return new ListOfValuesConstraint();
}