diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getsubclassesdef.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getsubclassesdef.get.desc.xml new file mode 100644 index 0000000000..d18b9284cd --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getsubclassesdef.get.desc.xml @@ -0,0 +1,8 @@ + + Get Sub Class Definitions + Get the collection of sub classes definitions - parameters r=> recursive, classfilter , namespaceprefix and name + /api/classes/{classname}/subclasses?r={recursive?}&nsp={namespacePrefix?}&n={name?} + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getsubclassesdef.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getsubclassesdef.get.json.ftl new file mode 100644 index 0000000000..b6dd6516e2 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getsubclassesdef.get.json.ftl @@ -0,0 +1,7 @@ +<#import "classdetails.lib.ftl" as classdetailsDefLib/> +[ +<#list classdefs as classdefs> + <@classdetailsDefLib.classDefJSON classdefs=classdefs key = classdefs_index/> + <#if classdefs_has_next>, + +] diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/propertydefinition.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/propertydefinition.lib.ftl index 97ade1b40b..72d9037970 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/propertydefinition.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/propertydefinition.lib.ftl @@ -28,10 +28,10 @@ [ <#if propertydefs.constraints?exists> <#list propertydefs.constraints as constraintdefs> - { <#--constraintdefs.getConstraint()[key]--> + { <#--constraintdefs.getConstraint()[key] <#assign keys = constraintdefs.getConstraint()?keys> <#list keys as key>"${key}" : <#if constraintdefs.getConstraint()[key]?exists>"${constraintdefs.getConstraint()[key]}"<#if key_has_next>, - + --> }<#if constraintdefs_has_next>, diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 0e77c03779..cca39ab79f 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -607,6 +607,12 @@ + + + + + + diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java index cd29fec971..645e886166 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java @@ -322,8 +322,8 @@ public class DictionaryServiceTest extends BaseWebScriptTest * 4 no no no Array of classes [returns all classes of both type and aspects in the entire repository] * 5 no yes yes single class [returns a single class of a valid namespaceprefix:name combination] * 6 no yes no Array of classes [returns an array of all aspects and types under particular namespaceprefix] - * 7 no no yes Array of all classes [since name alone doesn't makes any meaning] - * 8 yes no yes + * 7 no no yes 404 error [since name alone doesn't makes any meaning] + * 8 yes no yes 404 error [since name alone doesn't makes any meaning] * Test cases are provided for all the above scenarios */ @@ -578,88 +578,21 @@ public class DictionaryServiceTest extends BaseWebScriptTest } assertEquals(200,response.getStatus()); - //check for a name alone without classfilter and namespaceprefix option [case-type:7] + //check for a name alone without classfilter and namespaceprefix option [case-type:7] => returns 404 error arguments.clear(); arguments.put("n", "cmobject"); req.setArgs(arguments); - response = sendRequest(req, 200); - result = new JSONArray(response.getContentAsString()); - assertEquals(193, result.length()); - for(int i=0; i returns 404 error arguments.clear(); arguments.put("cf", "type"); arguments.put("n", "cmobject"); req.setArgs(arguments); - response = sendRequest(req, 200); - result = new JSONArray(response.getContentAsString()); - assertEquals(107, result.length()); - for(int i=0; iname @@ -721,6 +654,83 @@ public class DictionaryServiceTest extends BaseWebScriptTest assertEquals(200,response.getStatus()); } + public void testSubClassDetails() throws Exception + { + GetRequest req = new GetRequest(URL_SITES + "/sys_base/subclasses"); + Map< String, String > arguments = new HashMap< String, String >(); + arguments.put("r", "true"); + req.setArgs(arguments); + Response response = sendRequest(req, 200); + assertEquals(200,response.getStatus()); + response = sendRequest(req, 200); + JSONArray result = new JSONArray(response.getContentAsString()); + assertEquals(104, result.length()); + for(int i=0; ichild and classname=>wca_form arguments.clear(); @@ -764,6 +775,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults")) validateChildAssociation(result.getJSONObject(i)); } + assertEquals(200,response.getStatus()); //validate with associationfilter=>general and classname=>wca_form arguments.clear(); @@ -822,6 +834,20 @@ public class DictionaryServiceTest extends BaseWebScriptTest validateChildAssociation(result.getJSONObject(i)); } + //look for childassociation in the class wca_form , with a name parameter + arguments.clear(); + arguments.put("af", "child"); + arguments.put("n", "formworkflowdefaults"); + req.setArgs(arguments); + response = sendRequest(req, 200); + result = new JSONArray(response.getContentAsString()); + assertEquals(1,result.length()); + for(int i=0; i if the name is a valid + // validate the condition, if name is present and namespaceprefix is null if(name !=null && namespaceprefix == null) { assoc_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(this.dictionaryhelper.getPrefix(classname) + "_" + name)); @@ -154,12 +154,12 @@ public class GetAssociationDefs extends DeclarativeWebScript model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(class_qname).getChildAssociations().get(assoc_qname)); } else - { + { //association filter is either general or all model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(class_qname).getAssociations().get(assoc_qname)); } } else - { //if both name and namespaceprefix are not given, then if the assocfilter is a child =>pull only the childassociations, else if general=> pull + { // this point is always reached, if both name and namespaceprefix are not given OR Just namespaceprefix is alone given if(associationFilter.equals("child")) { model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(class_qname).getChildAssociations().values()); diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java index ed09ff1d48..8696988aa0 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java @@ -111,6 +111,11 @@ public class GetClassDetail extends DeclarativeWebScript throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classfilter + " provided in the URL"); } + 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) { diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetSubClassesDef.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetSubClassesDef.java new file mode 100644 index 0000000000..b09d5d899c --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetSubClassesDef.java @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.Cache; +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import org.alfresco.service.cmr.dictionary.PropertyDefinition; +import org.alfresco.service.cmr.dictionary.AssociationDefinition; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * + * Webscript to get the Sub-Classdefinitions using classfilter , namespaceprefix and name + * @author Saravanan Sellathurai + */ + +public class GetSubClassesDef extends DeclarativeWebScript +{ + private DictionaryService dictionaryservice; + private DictionaryHelper dictionaryhelper; + + private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs"; + private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; + private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; + + private static final String REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN = "r"; + //private static final String REQ_URL_TEMPL_VAR_CLASS_FILTER = "cf"; + private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp"; + private static final String REQ_URL_TEMPL_VAR_NAME = "n"; + private static final String DICTIONARY_CLASS_NAME = "classname"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + /** + * @Override method from DeclarativeWebScript + */ + protected Map 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 classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String recursive_value = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN)); + + boolean recursive = true; + + Map classdef = new HashMap(); + Map> propdef = new HashMap>(); + Map> assocdef = new HashMap>(); + Map model = new HashMap(); + + QName classQName = null; + String namespaceUri = null; + Collection qname = null; + boolean isAspect = false; + boolean ignoreCheck = false; + + // validate recursive parameter => can be either true or false or null + if(recursive_value == null) + { + recursive = true; + } + else if(recursive_value.equalsIgnoreCase("true")) + { + recursive = true; + } + else if (recursive_value.equalsIgnoreCase("false")) + { + recursive = false; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the value for the parameter recursive=> " + recursive_value +" can only be either true or false"); + } + + //validate the classname + if(this.dictionaryhelper.isValidClassname(classname) == true) + { + classQName = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + if(this.dictionaryhelper.isValidTypeorAspect(classname) == true) + { + isAspect = true; + } + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + classname + " parameter in the URL"); + } + + // collect the subaspects or subtypes of the class + if(isAspect == true) + { + qname = this.dictionaryservice.getSubAspects(classQName, recursive); + } + else + { + qname = this.dictionaryservice.getSubTypes(classQName, recursive); + } + + //validate the namespaceprefix parameter + if(namespaceprefix != null) + { + if(this.dictionaryhelper.isValidPrefix(namespaceprefix) == false) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " - parameter in the URL"); + } + } + + //validate the name parameter + if(name != null) + { + if(this.dictionaryhelper.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 = this.dictionaryhelper.getNamespaceURIfromPrefix(this.dictionaryhelper.getPrefixFromModelName(name)); + } + + if (namespaceprefix != null && name == null) + { + namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespaceprefix); + } + + if(namespaceprefix == null && name == null) + { + namespaceUri = null; + ignoreCheck = true; + } + + if (namespaceprefix != null && name != null) + { + if(this.dictionaryhelper.isValidClassname(namespaceprefix + "_" + name) == false) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " and name - "+ name + " - parameter in the URL"); + } + namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespaceprefix); + } + + for(QName qnameObj: qname) + { + if(ignoreCheck || 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()); + } + } + + model.put(MODEL_PROP_KEY_CLASS_DEFS, classdef.values()); + model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values()); + model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values()); + return model; + + } + + } \ No newline at end of file