use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project records-management by Alfresco.
the class RmClassesGet method executeImpl.
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, boolean isRM) {
String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
String className = null;
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>();
List<QName> qnames = new ArrayList<QName>();
QName classQname = null;
QName myModel = null;
// if classfilter is not given, then it defaults to all
if (classFilter == null) {
classFilter = "all";
}
// validate classfilter
if (!isValidClassFilter(classFilter)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL");
}
// name alone has no meaning without namespaceprefix
if (namespacePrefix == null && name != null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
// validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
if (namespacePrefix != null) {
// validate name parameter if present along with the namespaceprefix
if (name != null) {
className = namespacePrefix + "_" + name;
if (!isValidClassname(className)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL");
}
classQname = QName.createQName(getFullNamespaceURI(className));
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
} else {
// if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
for (QName qnameObj : this.dictionaryservice.getAllModels()) {
if (qnameObj.getNamespaceURI().equals(namespaceUri)) {
name = qnameObj.getLocalName();
myModel = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
// check the classfilter to pull out either all or type or aspects
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
qnames.addAll(this.dictionaryservice.getAspects(myModel));
qnames.addAll(this.dictionaryservice.getTypes(myModel));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
qnames.addAll(this.dictionaryservice.getTypes(myModel));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
qnames.addAll(this.dictionaryservice.getAspects(myModel));
}
}
}
}
}
// if namespacePrefix is null, then check the class filter to pull out either all, type or aspects
if (myModel == null) {
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
qnames.addAll(getAspects(isRM));
qnames.addAll(getTypes(isRM));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
qnames.addAll(getTypes(isRM));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
qnames.addAll(getAspects(isRM));
}
}
if (classdef.isEmpty()) {
for (QName qnameObj : qnames) {
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, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
return model;
}
use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-remote-api by Alfresco.
the class AbstractClassGet method executeImpl.
/**
* Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
Map<String, Object> model = new HashMap<String, Object>(3);
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>>();
QName classQname = getClassQname(req);
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
model.put(MODEL_PROP_KEY_CLASS_DETAILS, classdef.values());
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
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 RestVariableHelper method setVariableValueAndType.
/**
* Sets the variable value with possible conversion to the correct format to be used in the response and sets
* the type accordingly. If the variables is defined on the {@link TypeDefinition}, the data-type is used. If it's not
* defined, the type is deducted from the raw variable value.
*/
protected void setVariableValueAndType(Variable variable, Object value, TypeDefinitionContext context) {
PropertyDefinition propDef = context.getPropertyDefinition(variable.getName());
if (propDef != null) {
variable.setValue(getSafePropertyValue(value));
variable.setType(propDef.getDataType().getName().toPrefixString(namespaceService));
} else {
// Not defined as a property, check if it's an association
AssociationDefinition assocDef = context.getAssociationDefinition(variable.getName());
if (assocDef == null) {
// Try to get an association definition through dictionary
String[] prefixLocalName = variable.getName().split("_");
if (prefixLocalName.length == 2) {
QName qName = QName.createQName(prefixLocalName[0], prefixLocalName[1], namespaceService);
assocDef = dictionaryService.getAssociation(qName);
}
}
if (assocDef != null) {
// Type of variable is the target class-name
variable.setType(assocDef.getTargetClass().getName().toPrefixString(namespaceService));
variable.setValue(getAssociationRepresentation(value, assocDef));
} else {
// Variable is not declared as property or association type-def. Use actual raw value as base for conversion.
variable.setValue(getSafePropertyValue(value));
variable.setType(extractTypeStringFromValue(value));
}
}
}
use of org.alfresco.service.cmr.dictionary.AssociationDefinition in project alfresco-remote-api by Alfresco.
the class AbstractAssociationsGet method executeImpl.
/**
* Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
String associationFilter = req.getParameter(REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
Map<String, Object> model = new HashMap<String, Object>();
Map<QName, AssociationDefinition> assocdef = new HashMap<QName, AssociationDefinition>();
QName associationQname = null;
QName classQname = getClassQname(req);
if (associationFilter == null) {
associationFilter = "all";
}
// validate association filter
if (isValidAssociationFilter(associationFilter) == false) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the associationFilter - " + associationFilter + " - parameter in the URL");
}
// validate for the presence of both name and namespaceprefix
if ((name == null && namespacePrefix != null) || (name != null && namespacePrefix == null)) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing either name or namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
// check for association filters
if (associationFilter.equals("child")) {
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getChildAssociations().values());
} else if (associationFilter.equals("general")) {
for (AssociationDefinition assocname : this.dictionaryservice.getClass(classQname).getAssociations().values()) {
if (assocname.isChild() == false) {
assocdef.put(assocname.getName(), assocname);
}
}
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
} else if (associationFilter.equals("all")) {
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getAssociations().values());
}
// if both namespaceprefix and name parameters are given then, the combination namespaceprefix_name is used as the index to create the qname
if (name != null && namespacePrefix != null) {
// validate the class combination namespaceprefix_name
associationQname = getAssociationQname(namespacePrefix, name);
if (this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname) == null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "not a Valid - namespaceprefix_name combination");
}
model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname));
}
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 AbstractClassesGet method executeImpl.
/**
* Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
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>();
List<QName> qnames = new ArrayList<QName>();
QName classQname = null;
QName myModel = null;
// if classfilter is not given, then it defaults to all
if (classFilter == null) {
classFilter = "all";
}
// validate classfilter
if (isValidClassFilter(classFilter) == false) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL");
}
// name alone has no meaning without namespaceprefix
if (namespacePrefix == null && name != null) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
// validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
if (namespacePrefix != null) {
// validate name parameter if present along with the namespaceprefix
if (name != null) {
classQname = getClassQname(namespacePrefix, name);
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
} else {
// if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
for (QName qnameObj : this.dictionaryservice.getAllModels()) {
if (qnameObj.getNamespaceURI().equals(namespaceUri)) {
name = qnameObj.getLocalName();
myModel = getQNameForModel(namespacePrefix, name);
// check the classfilter to pull out either all or type or aspects
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
qnames.addAll(this.dictionaryservice.getAspects(myModel));
qnames.addAll(this.dictionaryservice.getTypes(myModel));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
qnames.addAll(this.dictionaryservice.getTypes(myModel));
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
qnames.addAll(this.dictionaryservice.getAspects(myModel));
}
}
}
}
}
// if namespacePrefix is null, then check the classfilter to pull out either all or type or aspects
if (myModel == null) {
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) {
qnames.addAll(this.dictionaryservice.getAllAspects());
qnames.addAll(this.dictionaryservice.getAllTypes());
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) {
qnames.addAll(this.dictionaryservice.getAllTypes());
} else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) {
qnames.addAll(this.dictionaryservice.getAllAspects());
}
}
if (classdef.isEmpty() == true) {
for (QName qnameObj : qnames) {
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, dictionaryservice);
return model;
}
Aggregations