diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/assocdefinition.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/assocdefinition.lib.ftl index df69128b93..94300952a0 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/assocdefinition.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/assocdefinition.lib.ftl @@ -49,14 +49,12 @@ "requiredChildName" : "${assocdefs.getRequiredChildName()}", <#if assocdefs.getDuplicateChildNamesAllowed() == true> - "duplicateChildNameAllowed" : true, + "duplicateChildNameAllowed" : true, <#else> - "duplicateChildNameAllowed" : false, + "duplicateChildNameAllowed" : false, - "url" : "${"/api/classes/" + url.templateArgs.classname + "/childassociation/" + assocdefs.name.toPrefixString()?replace(":","_")}" - <#else> - "url" : "${"/api/classes/" + url.templateArgs.classname + "/association/" + assocdefs.name.toPrefixString()?replace(":","_")}" + "url" : "${"/api/classes/" + url.templateArgs.classname + "/association/" + assocdefs.name.toPrefixString()?replace(":","_")}" } \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/classdetails.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/classdetails.lib.ftl index e197e943f0..d022affadd 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/classdetails.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/classdetails.lib.ftl @@ -94,7 +94,7 @@ <#if assocdefs.title?exists> "title" : "${assocdefs.title}", - "url" : "${"/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/childassociation/" + assocdefs.name.toPrefixString()?replace(":","_")}" + "url" : "${"/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/association/" + assocdefs.name.toPrefixString()?replace(":","_")}" } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.json.ftl index c66856a5fb..186f9fb182 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.json.ftl @@ -1,3 +1,6 @@ <#import "assocdefinition.lib.ftl" as assocDefLib/> - -<@assocDefLib.assocDefJSON assocdefs=assocdefs/> \ No newline at end of file +<#if assocdefs?exists> +<@assocDefLib.assocDefJSON assocdefs=assocdefs/> +<#else> +{} + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.json.ftl index e778a3643c..c188eb0ac8 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.json.ftl @@ -4,6 +4,7 @@ <#if individualproperty?exists> <#if assocdefs.name == individualproperty.name> <@assocDefLib.assocDefJSON assocdefs=assocdefs/> + <#break> <#else> <@assocDefLib.assocDefJSON assocdefs=assocdefs/> diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.json.ftl index 0157342917..dc7c307e54 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.json.ftl @@ -1,14 +1,22 @@ <#import "propertydefinition.lib.ftl" as propertyDefLib/> -[ -<#list propertydefs as propertydefinitions> - <#if individualproperty?exists> - <#if propertydefinitions.name == individualproperty.name> - <@propertyDefLib.propertyDefJSON propertydefs=propertydefinitions/> - <#break> - - <#else> - <@propertyDefLib.propertyDefJSON propertydefs=propertydefinitions/> - <#if propertydefinitions_has_next>, +<#if propertydefs?exists> + <#if individualproperty?exists == false> + [ - -] \ No newline at end of file + <#list propertydefs as propertydefinitions> + <#if individualproperty?exists> + <#if propertydefinitions.name == individualproperty.name> + <@propertyDefLib.propertyDefJSON propertydefs=propertydefinitions/> + <#break> + + <#else> + <@propertyDefLib.propertyDefJSON propertydefs=propertydefinitions/> + <#if propertydefinitions_has_next>, + + + <#if individualproperty?exists == false> + ] + +<#else> + {} + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.json.ftl index 0a1c659b86..6870ea1ed9 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.json.ftl @@ -1,3 +1,6 @@ <#import "propertydefinition.lib.ftl" as propertyDefLib/> - -<@propertyDefLib.propertyDefJSON propertydefs=propertydefs/> \ No newline at end of file +<#if propertydefs?exists> + <@propertyDefLib.propertyDefJSON propertydefs=propertydefs/> +<#else> + {} + \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java index bc5c080d5f..397fa173b9 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java @@ -120,7 +120,7 @@ public class DictionaryHelper } catch(Exception e) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact classname - " + classname + " parameter has not been provided in the URL"); } } @@ -182,27 +182,6 @@ public class DictionaryHelper } } - - /** - * - * @param namespaceprefix - gets a valid namespaceprefix as input - * @return modelname from namespaceprefix - returns null if invalid namespaceprefix is given - */ - public String getModelNameFromPrefix(String namespaceprefix) - { - String name = null; - for(QName qnameObj:this.dictionaryservice.getAllModels()) - { - String prefix = this.getUrlsAndPrefixesMap().get(qnameObj.getNamespaceURI()); - if(prefix.equals(namespaceprefix)) - { - name = qnameObj.getLocalName(); - break; - } - } - return name; - } - /** * * @param namespaceprefix - gets a valid namespaceprefix as input @@ -358,8 +337,9 @@ public class DictionaryHelper return prefixesAndUrlsMap; } - /* - * returns a string map of urls and prefixes - with url as the key + /** + * + * @return- a string map of urls and prefixes - with url as the key */ public Map getUrlsAndPrefixesMap() { 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 148f800934..36404a9184 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java @@ -29,6 +29,7 @@ import org.alfresco.web.scripts.TestWebScriptServer.GetRequest; import org.alfresco.web.scripts.TestWebScriptServer.Response; import java.util.HashMap; import java.util.Map; + import org.json.JSONObject; import org.json.JSONArray; @@ -67,7 +68,6 @@ public class DictionaryServiceTest extends BaseWebScriptTest assertEquals(true, result.get("protected")); assertEquals(true, result.get("indexed")); assertEquals(true, result.get("indexedAtomically")); - //assertEquals check is yet to be made on constraints assertEquals("/api/classes/cm_auditable/property/cm_created", result.get("url")); } @@ -88,7 +88,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest assertEquals(false, result.getJSONObject("target").get("mandatory")); assertEquals(false, result.getJSONObject("target").get("many")); - assertEquals("/api/classes/wca_form/childassociation/wca_formworkflowdefaults", result.get("url")); + assertEquals("/api/classes/wca_form/association/wca_formworkflowdefaults", result.get("url")); } private void validateAssociation(JSONObject result) throws Exception @@ -180,7 +180,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest assertEquals(0, result.getJSONObject("associations").length()); assertEquals("cm:thumbnails", result.getJSONObject("childassociations").getJSONObject("cm:thumbnails").get("name")); - assertEquals("/api/classes/cm_thumbnailed/childassociation/cm_thumbnails", result.getJSONObject("childassociations").getJSONObject("cm:thumbnails").get("url")); + assertEquals("/api/classes/cm_thumbnailed/association/cm_thumbnails", result.getJSONObject("childassociations").getJSONObject("cm:thumbnails").get("url")); } @@ -190,10 +190,16 @@ public class DictionaryServiceTest extends BaseWebScriptTest assertEquals(200,response.getStatus()); JSONObject result = new JSONObject(response.getContentAsString()); validatePropertyDef(result); - // TODO Constraint data has to be added... yet to do + assertEquals(13, result.length()); response = sendRequest(new GetRequest("/api/classes/cm_hi/property/cm_welcome"), 404); assertEquals(404,response.getStatus()); + + //invalid property name , returns a null JsonObject as such a property doesn't exist under cm_auditable + response = sendRequest(new GetRequest("/api/classes/cm_auditable/property/cm_welcome"), 200); + result = new JSONObject(response.getContentAsString()); + assertEquals(0, result.length()); + assertEquals(200,response.getStatus()); } public void testGetPropertyDefs() throws Exception @@ -206,45 +212,27 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); Response response = sendRequest(req, 200); assertEquals(200,response.getStatus()); - JSONArray result = new JSONArray(response.getContentAsString()); - validatePropertyDef(result.getJSONObject(0)); + JSONObject resultSet = new JSONObject(response.getContentAsString()); + validatePropertyDef(resultSet); - // validate without name parameter => returns an array of property definitions + // both name and namespaceprefix parameters are needed arguments.clear(); arguments.put("nsp", "cm"); req.setArgs(arguments); - response = sendRequest(req, 200); - result = new JSONArray(response.getContentAsString()); - assertEquals(200,response.getStatus()); - assertEquals(5, result.length()); - for(int i=0; i returns an array of property definitions arguments.clear(); response = sendRequest(req, 200); - result = new JSONArray(response.getContentAsString()); + JSONArray result = new JSONArray(response.getContentAsString()); assertEquals(200,response.getStatus()); assertEquals(5, result.length()); for(int i=0; i results a null object arguments.clear(); arguments.put("n", "dublincore"); arguments.put("nsp", "cm"); req.setArgs(arguments); - response = sendRequest(req, 404); - assertEquals(404,response.getStatus()); + response = sendRequest(req, 200); + resultSet = new JSONObject(response.getContentAsString()); + assertEquals(0,resultSet.length()); + assertEquals(200,response.getStatus()); + // with invalid namespace parameter arguments.clear(); @@ -275,21 +266,23 @@ public class DictionaryServiceTest extends BaseWebScriptTest response = sendRequest(req, 404); assertEquals(404,response.getStatus()); - // with invalid name parameter + // with invalid name parameter => results a null json object arguments.clear(); arguments.put("nsp", "cm"); arguments.put("n", "create"); req.setArgs(arguments); - response = sendRequest(req, 404); - assertEquals(404,response.getStatus()); + response = sendRequest(req, 200); + resultSet = new JSONObject(response.getContentAsString()); + assertEquals(0,resultSet.length()); - // name is valid here, but the namespaceprefix is different from the classname i.e classname is of cm and given namespaceprefix is wcm - which contradicts arguments.clear(); arguments.put("nsp", "wcm"); arguments.put("n", "created"); req.setArgs(arguments); - response = sendRequest(req, 404); - assertEquals(404,response.getStatus()); + response = sendRequest(req, 200); + resultSet = new JSONObject(response.getContentAsString()); + assertEquals(0,resultSet.length()); + } public void testGetClassDetail() throws Exception @@ -311,6 +304,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest assertEquals(404,response.getStatus()); } + public void testGetClassDetails() throws Exception { /** @@ -384,7 +378,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest } assertEquals(200,response.getStatus()); - /*//check for a type under cm without options=>name, namespaceprefix [case-type:2] + //check for a type under cm without options=>name, namespaceprefix [case-type:2] arguments.clear(); arguments.put("cf", "type"); arguments.put("nsp", "cm"); @@ -409,7 +403,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - assertEquals(34, result.length()); + assertEquals(37, result.length()); // the above result has all the aspects under cm, so now check for the presence aspect cm:thumnailed in the array of classes of all aspects for(int i=0; igeneral and classname=>wca_form + //validate with associationfilter=>general(that means an association and not child) and classname=>wca_form arguments.clear(); arguments.put("af", "general"); req.setArgs(arguments); @@ -789,8 +819,9 @@ public class DictionaryServiceTest extends BaseWebScriptTest if(result.getJSONObject(i).get("name").equals("wca:renderingenginetemplates")) validateAssociation(result.getJSONObject(i)); } + assertEquals(200,response.getStatus()); - //look for association wca_renderingenginetemplates in the class wca_form + //look for association wca_renderingenginetemplates in the class wca_form => returns a single valid class arguments.clear(); arguments.put("af", "general"); arguments.put("nsp", "wca"); @@ -804,8 +835,9 @@ public class DictionaryServiceTest extends BaseWebScriptTest if(result.getJSONObject(i).get("name").equals("wca:renderingenginetemplates")) validateAssociation(result.getJSONObject(i)); } + assertEquals(200,response.getStatus()); - //look for childassociation wca_formworkflowdefaults in the class wca_form + //look for childassociation wca_formworkflowdefaults in the class wca_form =>returns a single valid class arguments.clear(); arguments.put("af", "child"); arguments.put("nsp", "wca"); @@ -819,8 +851,9 @@ public class DictionaryServiceTest extends BaseWebScriptTest if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults")) validateChildAssociation(result.getJSONObject(i)); } + assertEquals(200,response.getStatus()); - //look for details on wca_formworkflowdefaults in the class wca_form + //look for details on wca_formworkflowdefaults in the class wca_form , with no classfilter arguments.clear(); arguments.put("nsp", "wca"); arguments.put("n", "formworkflowdefaults"); @@ -833,69 +866,59 @@ public class DictionaryServiceTest extends BaseWebScriptTest if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults")) validateChildAssociation(result.getJSONObject(i)); } + assertEquals(200,response.getStatus()); - //look for childassociation in the class wca_form , with a name parameter + // wca_formworkflowdefaults has a child_assoc relation with wca_form , but ask for general association, this then returns a null array arguments.clear(); - arguments.put("af", "child"); + arguments.put("af", "general"); + arguments.put("nsp", "wca"); 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 name alone is given , a check is made to ensure renderingenginetemplates is in the associations list, if present check whether its a valid - // child association otherwise returns a null array - arguments.clear(); - arguments.put("af", "child"); arguments.put("n", "renderingenginetemplates"); req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); assertEquals(0,result.length()); + assertEquals(200,response.getStatus()); + + //look for childassociation in the class wca_form , with no name parameter =>both name and namespaceprefix are needed + arguments.clear(); + arguments.put("af", "child"); + arguments.put("nsp", "wca"); + req.setArgs(arguments); + response = sendRequest(req, 404); + assertEquals(404,response.getStatus()); + + arguments.clear(); + arguments.put("af", "child"); + arguments.put("n", "renderingenginetemplates"); + req.setArgs(arguments); + response = sendRequest(req, 404); + assertEquals(404,response.getStatus()); - //ask for an invalid general-association => name alone is given , a check is made to ensure formworkflowdefaults is in the associations list, if present check whether its a valid - // general association otherwise returns a null array arguments.clear(); arguments.put("af", "general"); arguments.put("n", "formworkflowdefaults"); req.setArgs(arguments); - response = sendRequest(req, 200); - result = new JSONArray(response.getContentAsString()); - assertEquals(0,result.length()); - + response = sendRequest(req, 404); + assertEquals(404,response.getStatus()); //look for associations (excluding child assocs) in the class wca_form , with no name parameter arguments.clear(); arguments.put("af", "general"); arguments.put("nsp", "wca"); req.setArgs(arguments); - response = sendRequest(req, 200); - result = new JSONArray(response.getContentAsString()); - assertEquals(1,result.length()); - for(int i=0; i should be of class-type wca + arguments.put("nsp", "wca"); // invalid namespaceprefix => should be of class-type wca arguments.put("n", "renderingenginetemplates"); req.setArgs(arguments); - response = sendRequest(req, 404); - assertEquals(404,response.getStatus()); + response = sendRequest(req, 200); + assertEquals(200,response.getStatus()); //data without name parameter arguments.clear(); @@ -941,27 +964,14 @@ public class DictionaryServiceTest extends BaseWebScriptTest response = sendRequest(req, 404); assertEquals(404,response.getStatus()); - } - - //TODO individual check of all elements - public void testGetChildAssociatoinDef() throws Exception - { - GetRequest req = new GetRequest(URL_SITES + "/cm_thumbnailed/childassociation/cm_thumbnails"); - Response response = sendRequest(req, 200); - assertEquals(200,response.getStatus()); - response = sendRequest(new GetRequest(URL_SITES +"/cm_thumbnailed:sara/childassociation/cm:thumbnails"), 404); + //data with invalid class in wca_form + arguments.clear(); + arguments.put("nsp", "wca"); + arguments.put("n", "dublincore"); + req.setArgs(arguments); + response = sendRequest(req, 404); assertEquals(404,response.getStatus()); } - //TODO individual check of all elements - public void testGetChildAssociatoinDefs() throws Exception - { - GetRequest req = new GetRequest(URL_SITES + "/cm_thumbnailed/childassociations"); - Response response = sendRequest(req, 200); - assertEquals(200,response.getStatus()); - response = sendRequest(new GetRequest(URL_SITES +"/cm_thumbnailed:sara/childassociations"), 404); - assertEquals(404,response.getStatus()); - } - } diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDef.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDef.java index 870c625eef..66ea35d397 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDef.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDef.java @@ -24,13 +24,14 @@ */ 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 java.util.HashMap; import java.util.Map; @@ -42,7 +43,6 @@ import java.util.Map; public class GetAssociationDef extends DeclarativeWebScript { private DictionaryService dictionaryservice; - private ClassDefinition classdefinition; private DictionaryHelper dictionaryhelper; private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; @@ -72,32 +72,35 @@ public class GetAssociationDef extends DeclarativeWebScript /** * @Override method from DeclarativeWebScript */ - protected Map executeImpl(WebScriptRequest req, Status status) + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); - String assocname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_NAME); - Map model = new HashMap(); - QName classqname = null; - QName assocqname = null; - boolean classnameGiven = (classname != null) && (classname.length() > 0); - boolean assocnameGiven = (assocname != null) && (assocname.length() > 0); + String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String associationName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_NAME); + Map model = new HashMap(1); + QName classQname = null; + QName associationQname = null; - if(classnameGiven && assocnameGiven) + //validate the classname + if(this.dictionaryhelper.isValidClassname(className) == false) { - classqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); - assocqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(assocname)); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL"); } - classdefinition = this.dictionaryservice.getClass(classqname); + + classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); - if(this.classdefinition != null) + if(associationName == null) { - model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.classdefinition.getAssociations().get(assocqname)); - return model; + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association name in the URL"); } - else - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); - } + + associationQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(associationName)); + + if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname) != null) + { + model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname)); + } + + return model; } } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java index 253f3bfd1b..20abdd8ffe 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java @@ -24,6 +24,7 @@ */ 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; @@ -75,17 +76,17 @@ public class GetAssociationDefs extends DeclarativeWebScript /** * @Override method from DeclarativeWebScript */ - protected Map executeImpl(WebScriptRequest req, Status status) + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); String associationFilter = req.getParameter(REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER); - String namespaceprefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX); + String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX); String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME); Map model = new HashMap(); Map assocdef = new HashMap(); - QName assoc_qname = null; - QName class_qname = null; + QName associationQname = null; + QName classQname = null; if(associationFilter == null) { @@ -99,88 +100,62 @@ public class GetAssociationDefs extends DeclarativeWebScript } //validate classname - if(this.dictionaryhelper.isValidClassname(classname) == true) + if(this.dictionaryhelper.isValidClassname(className) == true) { - class_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); } else { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + classname + " - parameter in the URL"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL"); } - //validate namespaceprefix - if(namespaceprefix != null) + // validate for the presence of both name and namespaceprefix + if((name == null && namespacePrefix != null) || + (name != null && namespacePrefix == null)) { - if(this.dictionaryhelper.isValidPrefix(namespaceprefix) == false) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " - parameter in the URL"); - } - - // validate whether the namespaceprefix is same of classname prefix - if(!this.dictionaryhelper.getPrefix(classname).equalsIgnoreCase(namespaceprefix)) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " parameter in the URL, namespaceprefix should be of class-type "+ classname); - } + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing either name or namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed"); } - // 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)); - if(this.dictionaryservice.getClass(class_qname).getAssociations().get(assoc_qname)== null) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the parameter name - "+ name +" in the URL "); - } - model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(class_qname).getAssociations().get(assoc_qname)); + // 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) + if(name != null && 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 class combination namespaceprefix_name - assoc_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespaceprefix + "_" + name)); - if(this.dictionaryservice.getClass(class_qname).getAssociations().get(assoc_qname)== null) + associationQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespacePrefix + "_" + name)); + + if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname)== null) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " and name - "+ name + " - parameter in the URL =>has no valid Association with class - "+ classname); - } - model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(class_qname).getAssociations().values()); - - if(associationFilter.equals("child")) - { - if(this.dictionaryservice.getClass(class_qname).getChildAssociations().get(assoc_qname)== null) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " and name - "+ name + " - parameter in the URL => not a valid childassociation for class - "+ classname); - } - 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 - { // 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()); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "not a Valid - namespaceprefix_name combination"); } - if(associationFilter.equals("general")) - { - for(AssociationDefinition assocname:this.dictionaryservice.getClass(class_qname).getAssociations().values()) - { - if(assocname.isChild() == false){ - assocdef.put(assocname.getName(), assocname); - } - } - model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values()); - } - - if(associationFilter.equals("all")) - { - model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(class_qname).getAssociations().values()); - } + model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname)); } + return model; } 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 77bf3ca0ff..e0c6bc61a7 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java @@ -37,6 +37,8 @@ import org.alfresco.service.cmr.dictionary.AssociationDefinition; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.ArrayList; +import java.util.List; /** * Webscript to get the Classdefinitions using classfilter , namespaceprefix and name @@ -85,103 +87,104 @@ public class GetClassDetail extends DeclarativeWebScript */ protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - String classfilter = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER)); - String namespaceprefix = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX)); + String classFilter = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER)); + String namespacePrefix = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX)); String name = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME)); - String classname = null; + String className = null; Map classdef = new HashMap(); Map> propdef = new HashMap>(); Map> assocdef = new HashMap>(); Map model = new HashMap(); - Collection qnames = null; - QName class_qname = null; + List qnames = new ArrayList(); + QName classQname = null; QName myModel = null; //if classfilter is not given, then it defaults to all - if(classfilter == null) + if(classFilter == null) { - classfilter = "all"; + classFilter = "all"; } //validate classfilter - if(this.dictionaryhelper.isValidClassFilter(classfilter) == false) + if(this.dictionaryhelper.isValidClassFilter(classFilter) == false) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classfilter + " provided in the URL"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL"); } - if(namespaceprefix == null && name != null) + //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) + if(namespacePrefix != null) { - if(this.dictionaryhelper.isValidPrefix(namespaceprefix) == false) + if(this.dictionaryhelper.isValidPrefix(namespacePrefix) == false) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " parameter in the URL"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespacePrefix + " parameter in the URL"); } //validate name parameter if present along with the namespaceprefix if(name != null) { - classname = namespaceprefix + "_" + name; - if(this.dictionaryhelper.isValidClassname(classname) == false) + className = namespacePrefix + "_" + name; + if(this.dictionaryhelper.isValidClassname(className) == false) { throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL"); } - class_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); - classdef.put(class_qname, this.dictionaryservice.getClass(class_qname)); - propdef.put(class_qname, this.dictionaryservice.getClass(class_qname).getProperties().values()); - assocdef.put(class_qname, this.dictionaryservice.getClass(class_qname).getAssociations().values()); + classQname = QName.createQName(this.dictionaryhelper.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 namespaceQname = this.dictionaryhelper.getNamespaceURIfromPrefix(namespaceprefix); + String namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespacePrefix); for(QName qnameObj:this.dictionaryservice.getAllModels()) { - if(qnameObj.getNamespaceURI().equals(namespaceQname)) + if(qnameObj.getNamespaceURI().equals(namespaceUri)) { name = qnameObj.getLocalName(); - myModel = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespaceprefix + "_" + name)); - qnames.clear(); + myModel = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespacePrefix + "_" + name)); + // check the classfilter to pull out either all or type or aspects - if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) - { + 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)) + else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) { qnames.addAll(this.dictionaryservice.getTypes(myModel)); } - else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) - { + 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 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)) + if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) { - qnames = this.dictionaryservice.getAllAspects(); - qnames.addAll(this.dictionaryservice.getAllTypes()); + qnames.addAll(this.dictionaryservice.getAllAspects()); + qnames.addAll(this.dictionaryservice.getAllTypes()); } - else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) + else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) { - qnames = this.dictionaryservice.getAllTypes(); + qnames.addAll(this.dictionaryservice.getAllTypes()); } - else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) + else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) { - qnames = this.dictionaryservice.getAllAspects(); + qnames.addAll(this.dictionaryservice.getAllAspects()); } } diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java index c6bdb49b92..37cf31ff8b 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java @@ -79,36 +79,33 @@ public class GetClassDetails extends DeclarativeWebScript */ protected Map executeImpl(WebScriptRequest req, Status status) { - String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); Map model = new HashMap(3); - QName qname = null; + QName classQname = null; Map classdef = new HashMap(); Map> propdef = new HashMap>(); Map> assocdef = new HashMap>(); - boolean classnameGiven = (classname != null) && (classname.length() > 0); - boolean hasData = false; - if(classnameGiven && this.dictionaryhelper.isValidClassname(classname)) + //validate the classname and throw appropriate error message + if(this.dictionaryhelper.isValidClassname(className) == true) { - qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); - hasData = true; - classdef.put(qname, this.dictionaryservice.getClass(qname)); - propdef.put(qname, this.dictionaryservice.getClass(qname).getProperties().values()); - assocdef.put(qname, this.dictionaryservice.getClass(qname).getAssociations().values()); - } - - if(hasData) - { - 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()); - return model; + classQname = QName.createQName(this.dictionaryhelper.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 { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); - } + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL"); + } + + 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()); + + return model; + } } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDef.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDef.java index 3e84847326..32748dcc89 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDef.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDef.java @@ -24,13 +24,14 @@ */ 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 java.util.HashMap; import java.util.Map; @@ -43,7 +44,6 @@ import java.util.Map; public class GetPropertyDef extends DeclarativeWebScript { private DictionaryService dictionaryservice; - private ClassDefinition classdefinition; private DictionaryHelper dictionaryhelper; private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; @@ -73,32 +73,37 @@ public class GetPropertyDef extends DeclarativeWebScript /** * @Override method from DeclarativeWebScript */ - protected Map executeImpl(WebScriptRequest req, Status status) + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); - String propertyname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PROPERTY_NAME); - Map model = new HashMap(); - QName qname = null; - QName propname = null; - boolean classnameGiven = (classname != null) && (classname.length() > 0); - boolean propertynameGiven = (propertyname != null) && (propertyname.length() > 0); + String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String propertyName = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PROPERTY_NAME); + Map model = new HashMap(1); + QName classQname = null; + QName propertyQname = null; - if(classnameGiven && propertynameGiven) + //validate the classname + if(this.dictionaryhelper.isValidClassname(className) == false) { - qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); - propname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(propertyname)); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + className + " - parameter in the URL"); } - classdefinition = this.dictionaryservice.getClass(qname); + + classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); - if(this.classdefinition != null) + //validate the presence of property name + if(propertyName == null) { - model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.classdefinition.getProperties().get(propname)); - return model; + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter propertyname in the URL"); } - else - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); - } + + propertyQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(propertyName)); + + if(this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname) != null) + { + model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname)); + } + + return model; + } } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java index 9352fa507e..8bd14eee69 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java @@ -24,6 +24,7 @@ */ 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; @@ -76,68 +77,52 @@ public class GetPropertyDefs extends DeclarativeWebScript /** * @Override method from DeclarativeWebScript */ - protected Map executeImpl(WebScriptRequest req, Status status) + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME); - String namespaceprefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX); + String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX); Map model = new HashMap(); - QName class_qname = null; - QName property_qname = null; + QName classQname = null; + QName propertyQname = null; - //validate the classname - if(this.dictionaryhelper.isValidClassname(classname) == true) + //validate the className + if(this.dictionaryhelper.isValidClassname(className) == true) { - class_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); } else { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + classname + " - parameter in the URL"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL"); } - //validate namespaceprefix - if(namespaceprefix != null) + // validate for the presence of both name and namespaceprefix + if((name == null && namespacePrefix != null) || + (name != null && namespacePrefix == null)) { - if(this.dictionaryhelper.isValidPrefix(namespaceprefix) == false) + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing either name or namespacePrefix parameter in the URL - both combination of name and namespacePrefix is needed"); + } + + // if both namespacePrefix and name parameters are given then, the combination namespacePrefix_name is used as the index to create the propertyqname + if(name != null && namespacePrefix != null) + { + if(this.dictionaryhelper.isValidPrefix(namespacePrefix) == false) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " - parameter in the URL"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespacePrefix - " + namespacePrefix + " - parameter in the URL"); } - // validate whether the namespaceprefix is same of classname prefix - if(!this.dictionaryhelper.getPrefix(classname).equalsIgnoreCase(namespaceprefix)) + // validate the class combination namespacePrefix_name + propertyQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespacePrefix + "_" + name)); + if(this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname) != null) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " parameter in the URL, namespaceprefix should be of type "+ classname); + model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname)); + model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(classQname).getProperties().values()); } } - - // validate the condition, if name is present and namespaceprefix is null - if(name !=null && namespaceprefix == null) - { - property_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(this.dictionaryhelper.getPrefix(classname) + "_" + name)); - if(this.dictionaryservice.getClass(class_qname).getProperties().get(property_qname)== null) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the parameter name - "+ name +" in the URL "); - } - model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(class_qname).getProperties().get(property_qname)); - } - - // if both namespaceprefix and name parameters are given then, the combination namespaceprefix_name is used as the index to create the propertyqname - if(name != null && namespaceprefix != null) - { - // validate the class combination namespaceprefix_name - property_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespaceprefix + "_" + name)); - if(this.dictionaryservice.getClass(class_qname).getProperties().get(property_qname)== null) - { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + " - parameter in the URL"); - } - - model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(class_qname).getProperties().values()); - model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(class_qname).getProperties().get(property_qname)); - } else - { // if no name and namespaceprefix parameters are given then pull all properties pertaining to the classname - model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(class_qname).getProperties().values()); + { + model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(classQname).getProperties().values()); } return model; diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetSubClassesDef.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetSubClassesDef.java index b09d5d899c..0a3ffa8230 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetSubClassesDef.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetSubClassesDef.java @@ -40,7 +40,7 @@ import java.util.Map; /** * - * Webscript to get the Sub-Classdefinitions using classfilter , namespaceprefix and name + * Webscript to get the Sub-Classdefinitions using classfilter , namespacePrefix and name * @author Saravanan Sellathurai */ @@ -85,9 +85,9 @@ public class GetSubClassesDef extends 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)); + String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX); + String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String recursiveValue = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN)); boolean recursive = true; @@ -103,35 +103,35 @@ public class GetSubClassesDef extends DeclarativeWebScript boolean ignoreCheck = false; // validate recursive parameter => can be either true or false or null - if(recursive_value == null) + if(recursiveValue == null) { recursive = true; } - else if(recursive_value.equalsIgnoreCase("true")) + else if(recursiveValue.equalsIgnoreCase("true")) { recursive = true; } - else if (recursive_value.equalsIgnoreCase("false")) + else if (recursiveValue.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"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the value for the parameter recursive=> " + recursiveValue +" can only be either true or false"); } - //validate the classname - if(this.dictionaryhelper.isValidClassname(classname) == true) + //validate the className + if(this.dictionaryhelper.isValidClassname(className) == true) { - classQName = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); - if(this.dictionaryhelper.isValidTypeorAspect(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"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " parameter in the URL"); } // collect the subaspects or subtypes of the class @@ -145,11 +145,11 @@ public class GetSubClassesDef extends DeclarativeWebScript } //validate the namespaceprefix parameter - if(namespaceprefix != null) + if(namespacePrefix != null) { - if(this.dictionaryhelper.isValidPrefix(namespaceprefix) == false) + if(this.dictionaryhelper.isValidPrefix(namespacePrefix) == false) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " - parameter in the URL"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespacePrefix - " + namespacePrefix + " - parameter in the URL"); } } @@ -163,34 +163,35 @@ public class GetSubClassesDef extends DeclarativeWebScript } //validate the name parameter - if (namespaceprefix == null && name != null) + if (namespacePrefix == null && name != null) { namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(this.dictionaryhelper.getPrefixFromModelName(name)); } - if (namespaceprefix != null && name == null) + if (namespacePrefix != null && name == null) { - namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespaceprefix); + namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespacePrefix); } - if(namespaceprefix == null && name == null) + if(namespacePrefix == null && name == null) { namespaceUri = null; ignoreCheck = true; } - if (namespaceprefix != null && name != null) + if (namespacePrefix != null && name != null) { - if(this.dictionaryhelper.isValidClassname(namespaceprefix + "_" + name) == false) + 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"); + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespacePrefix - " + namespacePrefix + " and name - "+ name + " - parameter in the URL"); } - namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespaceprefix); + namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespacePrefix); } for(QName qnameObj: qname) { - if(ignoreCheck || qnameObj.getNamespaceURI().equals(namespaceUri)) + if((ignoreCheck == true) || + (qnameObj.getNamespaceURI().equals(namespaceUri))) { classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj)); propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());