Java Code Examples for org.alfresco.service.cmr.action.ParameterDefinition#getParameterConstraintName()

The following examples show how to use org.alfresco.service.cmr.action.ParameterDefinition#getParameterConstraintName() . 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: ActionParameterField.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method creates a list of {@link FieldConstraint field constraints}, if there are any.
 * 
 * @return a List<FieldConstraint> if there are any, else Collections.emptyList()
 */
private List<FieldConstraint> processActionConstraints(ParameterDefinition parameterDef,
        ActionService actionService)
{
    List<FieldConstraint> fieldConstraints = Collections.emptyList();
    String paramConstraintName = parameterDef.getParameterConstraintName();
    if (paramConstraintName != null)
    {
        ParameterConstraint paramConstraint = actionService.getParameterConstraint(paramConstraintName);
        if (paramConstraint == null)
        {
            throw new FormException("ParameterConstraint name '" + paramConstraintName + "' not recognised.");
        }
        else
        {
            // This map is of allowedValue : display label for that value.
            Map<String, String> allowableValuesMap = paramConstraint.getAllowableValues();
            
            // We need to concatenate each key-value entry into a String like "value|displaylabel"
            // Then the FormService can display the labels but deal with the values as the underlying data.
            List<String> pipeSeparatedAllowedValues = new ArrayList<String>(allowableValuesMap.size());
            for (Map.Entry<String, String> entry : allowableValuesMap.entrySet())
            {
                pipeSeparatedAllowedValues.add(entry.getKey() + "|" + entry.getValue());
            }
            
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("allowedValues", pipeSeparatedAllowedValues);
            
            // Finally wrap it up in a parameter map.
            fieldConstraints = new ArrayList<FieldConstraint>(allowableValuesMap.size());
            fieldConstraints.add(new FieldConstraint("LIST", params));
            
        }
    }
    return fieldConstraints;
}
 
Example 2
Source File: ComparePropertyValueEvaluatorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testCheckParamDefintionWithConstraint()
{
    ActionConditionDefinition def = evaluator.getActionConditionDefintion();        
    assertEquals(ComparePropertyValueEvaluator.NAME, def.getName());
    ParameterDefinition paramDef = def.getParameterDefintion(ComparePropertyValueEvaluator.PARAM_OPERATION);
    assertNotNull(paramDef);
    assertEquals(ComparePropertyValueEvaluator.PARAM_OPERATION, paramDef.getName());
    String constraintName = paramDef.getParameterConstraintName();
    assertNotNull(constraintName);
    ParameterConstraint paramConstraint = actionService.getParameterConstraint(constraintName);
    assertNotNull(paramConstraint);
    assertEquals("ac-compare-operations", paramConstraint.getName());
}
 
Example 3
Source File: ActionsImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private ActionDefinition.ParameterDefinition toModel(ParameterDefinition p)
{
    return new ActionDefinition.ParameterDefinition(
            p.getName(),
            toShortQName(p.getType()),
            p.isMultiValued(),
            p.isMandatory(),
            p.getDisplayLabel(),
            p.getParameterConstraintName()
    );
}