Search in sources :

Example 41 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition 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)

Example 42 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-remote-api by Alfresco.

the class AbstractSubClassesGet method executeImpl.

/**
 * Override method from DeclarativeWebScript
 */
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
    String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
    String recursiveValue = getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN));
    boolean recursive = true;
    Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
    Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
    Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
    Map<String, Object> model = new HashMap<String, Object>();
    String namespaceUri = null;
    Collection<QName> qname = null;
    boolean ignoreCheck = false;
    // validate recursive parameter => can be either true or false or null
    if (recursiveValue == null) {
        recursive = true;
    } else if (recursiveValue.equalsIgnoreCase("true")) {
        recursive = true;
    } else if (recursiveValue.equalsIgnoreCase("false")) {
        recursive = false;
    } else {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the value for the parameter recursive=> " + recursiveValue + "  can only be either true or false");
    }
    qname = getQNameCollection(req, recursive);
    // validate the name parameter
    if (name != null) {
        if (isValidModelName(name) == false) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name parameter - " + name + " in the URL");
        }
    }
    // validate the name parameter
    if (namespacePrefix == null && name != null) {
        namespaceUri = namespaceService.getNamespaceURI(getPrefixFromModelName(name));
    }
    if (namespacePrefix != null && name == null) {
        namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
    }
    if (namespacePrefix == null && name == null) {
        namespaceUri = null;
        ignoreCheck = true;
    }
    if (namespacePrefix != null && name != null) {
        validateClassname(namespacePrefix, name);
        namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
    }
    for (QName qnameObj : qname) {
        if ((ignoreCheck == true) || (qnameObj.getNamespaceURI().equals(namespaceUri))) {
            classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
            propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
            assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
        }
    }
    List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
    Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator(dictionaryservice));
    model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
    model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, reorderedValues(classDefinitions, propdef));
    model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, reorderedValues(classDefinitions, assocdef));
    model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.dictionaryservice);
    return model;
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) Collection(java.util.Collection)

Example 43 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-remote-api by Alfresco.

the class DictionaryGet method executeImpl.

/**
 * Execute the webscript
 *
 * @param req       WebScriptRequest
 * @param status    Status
 */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    List<QName> qnames = new ArrayList<QName>(256);
    Set<String> namespaces = new HashSet<String>();
    Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
    Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
    Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
    // check configured list of model namespaces to ignore when retrieving all models
    for (String ns : this.namespaceService.getURIs()) {
        if (!ignoreNamespaces.contains(ns)) {
            namespaces.add(ns);
        }
    }
    // specific model qname provided or will process all available models
    String strModel = req.getParameter("model");
    if (strModel != null && strModel.length() != 0) {
        // handle full QName and prefixed shortname of a model
        QName modelQName = (strModel.charAt(0) == QName.NAMESPACE_BEGIN ? QName.createQName(strModel) : QName.createQName(strModel, this.namespaceService));
        ModelDefinition modelDef = this.dictionaryservice.getModel(modelQName);
        if (modelDef != null) {
            qnames.addAll(this.dictionaryservice.getAspects(modelQName));
            qnames.addAll(this.dictionaryservice.getTypes(modelQName));
        }
    } else {
        // walk all models and extract the aspects and types
        for (QName qname : this.dictionaryservice.getAllModels()) {
            if (namespaces.contains(qname.getNamespaceURI())) {
                qnames.addAll(this.dictionaryservice.getAspects(qname));
                qnames.addAll(this.dictionaryservice.getTypes(qname));
            }
        }
    }
    // get the class definitions and the properties and associations
    for (QName qname : qnames) {
        ClassDefinition classDef = this.dictionaryservice.getClass(qname);
        classdef.put(qname, classDef);
        propdef.put(qname, classDef.getProperties().values());
        assocdef.put(qname, classDef.getAssociations().values());
    }
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(MODEL_CLASS_DEFS, classdef.values());
    model.put(MODEL_PROPERTY_DEFS, propdef.values());
    model.put(MODEL_ASSOCIATION_DEFS, assocdef.values());
    model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, this.dictionaryservice);
    return model;
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ModelDefinition(org.alfresco.service.cmr.dictionary.ModelDefinition) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 44 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-repository by Alfresco.

the class FieldUtils method makeAssociationFields.

/**
 * Generates a list of association fields with values.
 *
 * @param assocDefs List of association definitions to generate
 * @param values Map containing the values to use for each property
 * @param group The group the field belongs to
 * @param namespaceService NamespaceService instance
 * @return List of generated Field objects
 */
public static List<Field> makeAssociationFields(Collection<AssociationDefinition> assocDefs, Map<AssociationDefinition, Object> values, FieldGroup group, NamespaceService namespaceService, DictionaryService dictionaryService) {
    AssociationFieldProcessor processor = new AssociationFieldProcessor(namespaceService, dictionaryService);
    ArrayList<Field> fields = new ArrayList<Field>(assocDefs.size());
    for (AssociationDefinition propDef : assocDefs) {
        Object value = values == null ? null : values.get(propDef);
        Field field = processor.makeField(propDef, value, group);
        fields.add(field);
    }
    return fields;
}
Also used : Field(org.alfresco.repo.forms.Field) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ArrayList(java.util.ArrayList)

Example 45 with AssociationDefinition

use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-repository by Alfresco.

the class RemoveChildAssocCommand method makeItemData.

@Override
protected ContentModelItemData<ItemType> makeItemData(ItemType item) {
    TypeDefinition baseType = getBaseType(item);
    Set<QName> aspects = getAspectNames(item);
    TypeDefinition anonType = dictionaryService.getAnonymousType(baseType.getName(), aspects);
    Map<QName, PropertyDefinition> propDefs = anonType.getProperties();
    Map<QName, AssociationDefinition> assocDefs = anonType.getAssociations();
    Map<QName, Serializable> propValues = getPropertyValues(item);
    Map<QName, Serializable> assocValues = getAssociationValues(item);
    Map<String, Object> transientValues = getTransientValues(item);
    return new ContentModelItemData<ItemType>(item, propDefs, assocDefs, propValues, assocValues, transientValues);
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition)

Aggregations

AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)60 QName (org.alfresco.service.namespace.QName)46 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)24 ChildAssociationDefinition (org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)15 HashMap (java.util.HashMap)13 Serializable (java.io.Serializable)11 ArrayList (java.util.ArrayList)11 ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)9 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)6 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 Collection (java.util.Collection)5 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 Pair (org.alfresco.util.Pair)3