Search in sources :

Example 1 with FormModelElement

use of org.alfresco.rest.workflow.api.model.FormModelElement 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());
}
Also used : FormModelElement(org.alfresco.rest.workflow.api.model.FormModelElement) Constraint(org.alfresco.service.cmr.dictionary.Constraint) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) ConstraintDefinition(org.alfresco.service.cmr.dictionary.ConstraintDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ListOfValuesConstraint(org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)

Aggregations

ArrayList (java.util.ArrayList)1 ListOfValuesConstraint (org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint)1 FormModelElement (org.alfresco.rest.workflow.api.model.FormModelElement)1 AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)1 Constraint (org.alfresco.service.cmr.dictionary.Constraint)1 ConstraintDefinition (org.alfresco.service.cmr.dictionary.ConstraintDefinition)1 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)1 QName (org.alfresco.service.namespace.QName)1