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());
}
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;
}
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;
}
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;
}
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);
}
Aggregations