From e29c5738625c9e0967ffa775e24c54cf3bc70254 Mon Sep 17 00:00:00 2001 From: Saravanan Sellathurai Date: Wed, 19 Nov 2008 16:31:20 +0000 Subject: [PATCH] Changes to dictionary service webscripts git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11997 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../dictionary/classdetails.lib.ftl | 2 +- .../getassociationdefs.get.desc.xml | 2 +- .../getassociationdefs.get.json.ftl | 14 +- .../dictionary/getproperties.get.desc.xml | 2 +- .../dictionary/getproperties.get.json.ftl | 13 +- .../dictionary/propertydefinition.lib.ftl | 11 +- .../scripts/dictionary/DictionaryHelper.java | 255 +++++++-- .../dictionary/DictionaryServiceTest.java | 527 +++++++++++++++--- .../dictionary/GetAssociationDefs.java | 118 +++- .../scripts/dictionary/GetClassDetail.java | 189 +++---- .../scripts/dictionary/GetClassDetails.java | 2 +- .../scripts/dictionary/GetPropertyDefs.java | 79 ++- 12 files changed, 959 insertions(+), 255 deletions(-) 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 decbb42cc8..7c2bf99627 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 @@ -26,7 +26,7 @@ "url" : "${"/api/classes/" + classdefs.parentName.toPrefixString()?replace(":","_")}" }, - "defaultAspects" : { + "defaultAspects" : { <#if classdefs.defaultAspects?exists> <#list classdefs.defaultAspects as aspectdef> "${aspectdef.name.toPrefixString()}" : { diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.desc.xml index 74f0b6db09..a5da762271 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.desc.xml @@ -1,7 +1,7 @@ Get Association Definitions Get the collection of association definitions for a given classname - /api/classes/{classname}/associations + /api/classes/{classname}/associations?af={associationFilter?}&nsp={namespacePrefix?}&n={name?} user required 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 77cb1a0bba..e778a3643c 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 @@ -1,9 +1,13 @@ <#import "assocdefinition.lib.ftl" as assocDefLib/> [ <#list assocdefs as assocdefs> - <#if assocdefs.isChild() == false> - <@assocDefLib.assocDefJSON assocdefs=assocdefs/> - <#if assocdefs_has_next>, - + <#if individualproperty?exists> + <#if assocdefs.name == individualproperty.name> + <@assocDefLib.assocDefJSON assocdefs=assocdefs/> + + <#else> + <@assocDefLib.assocDefJSON assocdefs=assocdefs/> + <#if assocdefs_has_next>, + -] \ No newline at end of file +] \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.desc.xml index 28c0911fe7..a222fb3411 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.desc.xml @@ -1,7 +1,7 @@ Get Property Definitions Get the collection of property definitions - /api/classes/{classname}/properties + /api/classes/{classname}/properties?nsp={namespacePrefix?}&n={name?} user required 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 372c966a48..0157342917 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,7 +1,14 @@ <#import "propertydefinition.lib.ftl" as propertyDefLib/> [ -<#list propertydefs as propertydefs> - <@propertyDefLib.propertyDefJSON propertydefs=propertydefs/> - <#if propertydefs_has_next>, +<#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>, + ] \ No newline at end of file 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 761c23cd5a..97ade1b40b 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 @@ -26,12 +26,15 @@ "indexedAtomically" : ${propertydefs.indexedAtomically?string}, "constraints" : [ - <#-- - <#if propertydefs.constraints?exists> + <#if propertydefs.constraints?exists> <#list propertydefs.constraints as constraintdefs> - "name" : "${constraintdefs.name}" + { <#--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>, - --> + ], "url" : "${"/api/classes/" + url.templateArgs.classname + "/property/" + propertydefs.name.toPrefixString()?replace(":","_")}" } 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 b2a086abc1..bc5c080d5f 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java @@ -25,8 +25,11 @@ package org.alfresco.repo.web.scripts.dictionary; import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; +import org.alfresco.service.namespace.InvalidQNameException; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -45,6 +48,14 @@ public class DictionaryHelper private Collection prefixes; private DictionaryService dictionaryservice; + private static final String CLASS_FILTER_OPTION_TYPE1 = "all"; + private static final String CLASS_FILTER_OPTION_TYPE2 = "aspect"; + private static final String CLASS_FILTER_OPTION_TYPE3 = "type"; + + private static final String ASSOCIATION_FILTER_OPTION_TYPE1 = "all"; + private static final String ASSOCIATION_FILTER_OPTION_TYPE2 = "general"; + private static final String ASSOCIATION_FILTER_OPTION_TYPE3 = "child"; + /** * Set the namespaceService property. * @@ -81,24 +92,36 @@ public class DictionaryHelper } } - public String getNamespaceURIfromQname(QName qname){ + /** + * + * @param qname + * @return the namespaceuri from a qname + */ + public String getNamespaceURIfromQname(QName qname) + { return qname.getNamespaceURI(); - - - } - /** + } + + /** * * @param className the class name as cm_person * @return String the full name in the following format {namespaceuri}shorname */ public String getFullNamespaceURI(String classname) { - String result = null; - String prefix = this.getPrefix(classname); - String url = this.prefixesAndUrlsMap.get(prefix); - String name = this.getShortName(classname); - result = "{" + url + "}"+ name; - return result; + try + { + String result = null; + String prefix = this.getPrefix(classname); + String url = this.prefixesAndUrlsMap.get(prefix); + String name = this.getShortName(classname); + result = "{" + url + "}"+ name; + return result; + } + catch(Exception e) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } } /** @@ -108,36 +131,160 @@ public class DictionaryHelper */ public String getNamespaceURIfromPrefix(String prefix) { - String result = null; - if(this.isValidPrefix(prefix)) result = this.prefixesAndUrlsMap.get(prefix); - return result; + if(this.isValidPrefix(prefix) == true) + { + return this.prefixesAndUrlsMap.get(prefix); + } + else + { + return null; + } } - /* - * checks whether the classname (eg.cm_author) is a valid one + /** + * + * @param classname - checks whether the classname is valid , gets the classname as input e.g cm_person + * @return true - if the class is valid , false - if the class is invalid */ - public boolean isValidClassname(String classname) + public boolean isValidClassname(String classname) { - boolean result = false; - QName qname = QName.createQName(this.getFullNamespaceURI(classname)); - if(this.isValidPrefix(this.getPrefix(classname))&& this.dictionaryservice.getClass(qname)!=null) result = true; - return result; + QName qname = null; + try + { + qname = QName.createQName(this.getFullNamespaceURI(classname)); + if ((this.isValidPrefix(this.getPrefix(classname)) == true) && + this.dictionaryservice.getClass(qname) != null) + { + return true; + } + } + catch(InvalidQNameException e) + { + //just ignore + } + return false; } - /* - * checks whether the prefix is a valid one + /** + * + * @param prefix - checks whether the prefix is a valid one + * @return true if the prefix is valid or false */ public boolean isValidPrefix(String prefix) { - boolean result = false; - if(this.prefixes.contains(prefix)) result = true; - return result; + if(this.prefixes.contains(prefix) == true) + { + return true; + } + else + { + return false; + } } - - /* - * returns the prefix from the classname of the format cm_person - * here cm represents the prefix + + /** + * + * @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 + * @return modelname from namespaceprefix - returns null if invalid namespaceprefix is given + */ + public String getPrefixFromModelName(String modelname) + { + String namespaceprefix = null; + for(QName qnameObj:this.dictionaryservice.getAllModels()) + { + if(qnameObj.getLocalName().equals(modelname)) + { + namespaceprefix = this.getUrlsAndPrefixesMap().get(qnameObj.getNamespaceURI()); + break; + } + } + return namespaceprefix; + } + + public boolean isValidAssociationFilter(String af) + { + if(af.equalsIgnoreCase(ASSOCIATION_FILTER_OPTION_TYPE1) || + af.equalsIgnoreCase(ASSOCIATION_FILTER_OPTION_TYPE2) || + af.equalsIgnoreCase(ASSOCIATION_FILTER_OPTION_TYPE3)) + { + return true; + } + else + { + return false; + } + } + + /** + * + * @param classname as the input + * @return true if it is a aspect or false if it is a Type + */ + public boolean isValidTypeorAspect(String classname) + { + try + { + QName qname = QName.createQName(this.getFullNamespaceURI(classname)); + if( (this.dictionaryservice.getClass(qname)!=null) && + (this.dictionaryservice.getClass(qname).isAspect() == true)) + { + return true; + } + else + { + return false; + } + } + catch(InvalidQNameException e) + { + //ignore + } + return false; + } + + /** + * + * @param modelname - gets the modelname as the input (modelname is without prefix ie. cm:contentmodel => where modelname = contentmodel) + * @return true if valid or false + */ + public boolean isValidModelName(String modelname) + { + boolean value = false; + for(QName qnameObj:this.dictionaryservice.getAllModels()) + { + if(qnameObj.getLocalName().equalsIgnoreCase(modelname)) + { + value = true; + break; + } + } + return value; + } + /** + * + * @param classname - returns the prefix from the classname of the format namespaceprefix:name eg. cm_person + * @return prefix - returns the prefix of the classname */ public String getPrefix(String classname) { @@ -150,9 +297,10 @@ public class DictionaryHelper return prefix; } - /* - * returns the shortname from the classname of the format cm_person - * here person represents the shortname + /** + * @param classname + * @returns the shortname from the classname of the format cm_person + * here person represents the shortname */ public String getShortName(String classname) { @@ -165,8 +313,45 @@ public class DictionaryHelper return shortname; } - /* - * returns a string map or prefixes and urls - with prefix as the key + /** + * @param input -gets a string input and validates it + * + * @return null if invalid or the string itself if its valid + */ + public String getValidInput(String input) + { + if((input != null) && (input.length() > 0)) + { + return input; + } + else + { + return null; + } + } + + /** + * + * @param classfilter =>valid class filters are all,apect or type + * @return true if valid or false if invalid + */ + public boolean isValidClassFilter(String classfilter) + { + if(classfilter.equals(CLASS_FILTER_OPTION_TYPE1) || + classfilter.equals(CLASS_FILTER_OPTION_TYPE2) || + classfilter.equals(CLASS_FILTER_OPTION_TYPE3)) + { + return true; + } + else + { + return false; + } + } + + /** + * @param + * @return a string map or prefixes and urls - with prefix as the key */ public Map getPrefixesAndUrlsMap() { 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 8c9faeec08..cd29fec971 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java @@ -55,7 +55,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest super.tearDown(); } - private boolean validatePropertyDef(JSONObject result) throws Exception + private void validatePropertyDef(JSONObject result) throws Exception { assertEquals("cm:created", result.get("name")); assertEquals("Created Date", result.get("title")); @@ -69,10 +69,49 @@ public class DictionaryServiceTest extends BaseWebScriptTest 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")); - return true; + } - private boolean validateAssociationDef(JSONObject result) throws Exception + private void validateChildAssociation(JSONObject result) throws Exception + { + assertEquals("wca:formworkflowdefaults", result.get("name")); + assertEquals("", result.get("title")); + assertEquals("", result.get("description")); + assertEquals(true, result.get("isChildAssociation")); + assertEquals(false, result.get("protected")); + + assertEquals("wca:form", result.getJSONObject("source").get("class")); + assertEquals(false, result.getJSONObject("source").get("mandatory")); + assertEquals(false, result.getJSONObject("source").get("many")); + + assertEquals("wca:workflowdefaults", result.getJSONObject("target").get("class")); + 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")); + } + + private void validateAssociation(JSONObject result) throws Exception + { + assertEquals("wca:renderingenginetemplates", result.get("name")); + assertEquals("Form Data Renderers", result.get("title")); + assertEquals("", result.get("description")); + assertEquals(false, result.get("isChildAssociation")); + assertEquals(false, result.get("protected")); + + assertEquals("wca:form", result.getJSONObject("source").get("class")); + assertEquals("wca:capture", result.getJSONObject("source").get("role")); + assertEquals(false, result.getJSONObject("source").get("mandatory")); + assertEquals(false, result.getJSONObject("source").get("many")); + + assertEquals("wca:renderingenginetemplate", result.getJSONObject("target").get("class")); + assertEquals("wca:presentation", result.getJSONObject("target").get("role")); + assertEquals(false, result.getJSONObject("target").get("mandatory")); + assertEquals(true, result.getJSONObject("target").get("many")); + + assertEquals("/api/classes/wca_form/association/wca_renderingenginetemplates", result.get("url")); + } + private void validateAssociationDef(JSONObject result) throws Exception { assertEquals("cm:avatar", result.get("name")); assertEquals("", result.get("title")); @@ -91,11 +130,9 @@ public class DictionaryServiceTest extends BaseWebScriptTest assertEquals(false, result.getJSONObject("target").get("many")); assertEquals("/api/classes/cm_person/association/cm_avatar", result.get("url")); - - return true; } - private boolean validateTypeClass(JSONObject result) throws Exception + private void validateTypeClass(JSONObject result) throws Exception { //cm:cmobject is of type =>type assertEquals("cm:cmobject", result.get("name")); @@ -124,10 +161,9 @@ public class DictionaryServiceTest extends BaseWebScriptTest assertEquals("/api/classes/cm_cmobject", result.get("url")); - return true; } - private boolean validateAspectClass(JSONObject result) throws Exception + private void validateAspectClass(JSONObject result) throws Exception { //cm:thumbnailed is of type =>aspect assertEquals("cm:thumbnailed", result.get("name")); @@ -146,16 +182,14 @@ public class DictionaryServiceTest extends BaseWebScriptTest 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")); - return true; } - public void testGetPropertyDef() throws Exception { Response response = sendRequest(new GetRequest("/api/classes/cm_auditable/property/cm_created"), 200); assertEquals(200,response.getStatus()); JSONObject result = new JSONObject(response.getContentAsString()); - assertEquals(true, validatePropertyDef(result)); + 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); @@ -164,17 +198,98 @@ public class DictionaryServiceTest extends BaseWebScriptTest public void testGetPropertyDefs() throws Exception { - Response response = sendRequest(new GetRequest("/api/classes/cm_auditable/properties"), 200); + //validate for a particular property cm_created in the class cm_auditable + GetRequest req = new GetRequest(URL_SITES + "/cm_auditable/properties"); + Map< String, String > arguments = new HashMap< String, String >(); + arguments.put("nsp", "cm"); + arguments.put("n", "created"); + req.setArgs(arguments); + Response response = sendRequest(req, 200); + assertEquals(200,response.getStatus()); JSONArray result = new JSONArray(response.getContentAsString()); + validatePropertyDef(result.getJSONObject(0)); + + // validate without name parameter => returns an array of property definitions + 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()); assertEquals(200,response.getStatus()); assertEquals(5, result.length()); + for(int i=0; iname, namespaceprefix [case-type:2] @@ -268,13 +391,15 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(13, result.length()); // the above result has all the types under cm, so now check for the presence type cm:cmobject in the array of classes of all types for(int i=0; iname [case-type:2] @@ -284,15 +409,15 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(34, 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; iname [case-type:2] arguments.clear(); @@ -301,12 +426,14 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(47, result.length()); for(int i=0; iname, namespaceprefix [case-type:3] @@ -315,12 +442,14 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(107, result.length()); for(int i=0; iname, namespaceprefix [case-type:3] @@ -329,36 +458,42 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(86, result.length()); for(int i=0; i cm:cmobject] without classfilter option [case-type:5] @@ -368,27 +503,31 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(1, result.length()); for(int i=0; i cm:thumbnailed] without classfilter option [case-type:5] arguments.clear(); arguments.put("nsp", "cm"); - arguments.put("n", "cmobject"); + arguments.put("n", "thumbnailed"); req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(1, result.length()); for(int i=0; i cm] without classfilter and name option [case-type:6] @@ -397,12 +536,14 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(47, result.length()); for(int i=0; i cm] without classfilter and name option [case-type:6] @@ -411,12 +552,14 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(47, result.length()); for(int i=0; i cm] without classfilter and name option [case-type:6] @@ -425,12 +568,14 @@ public class DictionaryServiceTest extends BaseWebScriptTest req.setArgs(arguments); response = sendRequest(req, 200); result = new JSONArray(response.getContentAsString()); - flag = false; + assertEquals(47, result.length()); for(int i=0; iall and classname=>wca_form + GetRequest req = new GetRequest(URL_SITES + "/wca_form/associations"); + Map< String, String > arguments = new HashMap< String, String >(); + arguments.put("af", "all"); + req.setArgs(arguments); Response response = sendRequest(req, 200); JSONArray result = new JSONArray(response.getContentAsString()); - boolean flag = true; + assertEquals(2,result.length()); for(int i=0; ichild and classname=>wca_form + arguments.clear(); + arguments.put("af", "child"); + req.setArgs(arguments); + response = sendRequest(req, 200); + result = new JSONArray(response.getContentAsString()); assertEquals(1,result.length()); + for(int i=0; igeneral and classname=>wca_form + arguments.clear(); + arguments.put("af", "general"); + 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()); + + //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()); + + + //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("n", "renderingenginetemplates"); + req.setArgs(arguments); + response = sendRequest(req, 404); + assertEquals(404,response.getStatus()); + + //data without name parameter + arguments.clear(); + arguments.put("nsp", "cm"); + req.setArgs(arguments); + response = sendRequest(req, 404); + assertEquals(404,response.getStatus()); + + //data with invalid association in wca_form + arguments.clear(); + arguments.put("nsp", "wca"); + arguments.put("n", "dublincore"); + req.setArgs(arguments); + response = sendRequest(req, 404); + assertEquals(404,response.getStatus()); + + //data with invalid association in wca_form + arguments.clear(); + arguments.put("nsp", "cm"); + arguments.put("n", "hiwelcome"); + req.setArgs(arguments); + response = sendRequest(req, 404); + assertEquals(404,response.getStatus()); + } //TODO individual check of all elements 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 222575499e..51f4a1d260 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java @@ -30,11 +30,12 @@ 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.AssociationDefinition; + import java.util.HashMap; import java.util.Map; -/* +/** * Webscript to get the Associationdefinitions for a given classname * @author Saravanan Sellathurai */ @@ -42,12 +43,15 @@ import java.util.Map; public class GetAssociationDefs extends DeclarativeWebScript { private DictionaryService dictionaryservice; - private ClassDefinition classdefinition; private DictionaryHelper dictionaryhelper; private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; + private static final String MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS = "individualproperty"; private static final String DICTIONARY_CLASS_NAME = "classname"; - + 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 REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER = "af"; + /** * Set the dictionaryService property. * @@ -74,25 +78,111 @@ public class GetAssociationDefs extends DeclarativeWebScript protected Map executeImpl(WebScriptRequest req, Status status) { 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 name = req.getParameter(REQ_URL_TEMPL_VAR_NAME); + Map model = new HashMap(); - QName classqname = null; - boolean classnameGiven = (classname != null) && (classname.length() > 0); + Map assocdef = new HashMap(); + QName assoc_qname = null; + QName class_qname = null; - if(classnameGiven) + if(associationFilter == null) { - classqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + associationFilter = "all"; } - classdefinition = this.dictionaryservice.getClass(classqname); - if(this.classdefinition != null) + //validate association filter + if(this.dictionaryhelper.isValidAssociationFilter(associationFilter) == false) { - model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.classdefinition.getAssociations().values()); - return model; + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the associationFilter - " + associationFilter + " - parameter in the URL"); + } + + //validate classname + if(this.dictionaryhelper.isValidClassname(classname) == true) + { + class_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); } 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"); + } + + //validate namespaceprefix + 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 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); + } + } + + // validate the condition, if name is present and namespaceprefix is null => if the name is a valid + 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)); + } + + // 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 + assoc_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespaceprefix + "_" + name)); + if(this.dictionaryservice.getClass(class_qname).getAssociations().get(assoc_qname)== 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 + { + 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 + if(associationFilter.equals("child")) + { + model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(class_qname).getChildAssociations().values()); + } + + 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()); + } + } + return model; + } } \ No newline at end of file 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 08f335fb0f..ed09ff1d48 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.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; @@ -82,11 +83,11 @@ public class GetClassDetail extends DeclarativeWebScript /** * @Override method from DeclarativeWebScript */ - protected Map executeImpl(WebScriptRequest req, Status status) + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) { - String classfilter = req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER); - String namespaceprefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX); - String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME); + 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; Map classdef = new HashMap(); @@ -94,102 +95,104 @@ public class GetClassDetail extends DeclarativeWebScript Map> assocdef = new HashMap>(); Map model = new HashMap(); - boolean cfGiven = (classfilter != null) && (classfilter.length() > 0); - boolean nspGiven = (namespaceprefix != null) && (namespaceprefix.length() > 0); - boolean nameGiven = (name != null) && (name.length() > 0); - boolean ignoreCheck ,isValidClassfilter ,isValidTriplet, isValidTwins ,hasData; - ignoreCheck = isValidClassfilter = isValidTriplet = isValidTwins = hasData = false; - - classname = namespaceprefix + "_" + name; - isValidClassfilter = (cfGiven ) && (classfilter.equals(CLASS_FILTER_OPTION_TYPE1) || classfilter.equals(CLASS_FILTER_OPTION_TYPE2) || classfilter.equals(CLASS_FILTER_OPTION_TYPE3)); - - if (cfGiven && nspGiven && nameGiven) + Collection qnames = null; + QName class_qname = null; + QName myModel = null; + + //if classfilter is not given, then it defaults to all + if(classfilter == null) { - // in this case, even if the classfilter is absurd, like asking for a type, but classname (namespaceprefix+" _"+name) in reality is an aspect,then it ignores the classfilter - // and fetches the correct results provided the classname is a valid one, classname should be of type either aspect or type and not a property name or association name... - isValidTriplet = this.dictionaryhelper.isValidPrefix(namespaceprefix) && isValidClassfilter && this.dictionaryhelper.isValidClassname(classname); - } - else if (cfGiven && nspGiven && !nameGiven) - { - isValidTwins = isValidClassfilter && this.dictionaryhelper.isValidPrefix(namespaceprefix); - } - else if (cfGiven && !nspGiven && !nameGiven) - { - //since classfilter is given and namespaceprefix, name is not given , we can ignore the check for particular qname for classname - ignoreCheck = isValidClassfilter; - } - else if (!cfGiven && !nspGiven && !nameGiven) - { - // if nothing is given then throw all data and ignoreCheck for particular classname - classfilter = CLASS_FILTER_OPTION_TYPE1; - ignoreCheck = true; - } - else if (!cfGiven && nspGiven && !nameGiven) - { - // if namespace alone is given , then classfilter is assumed to be all and considered as valid twins - classfilter = CLASS_FILTER_OPTION_TYPE1; - isValidTwins = this.dictionaryhelper.isValidPrefix(namespaceprefix); - } - else if (!cfGiven && nspGiven && nameGiven){ - //if namespace and name are given , then classfilter is assumed to be all (as we don't know whether its a aspect or a type ) and considered as valid twins - classfilter = CLASS_FILTER_OPTION_TYPE1; - isValidTwins = this.dictionaryhelper.isValidPrefix(namespaceprefix) && this.dictionaryhelper.isValidClassname(classname); - } - else if (!cfGiven && !nspGiven && nameGiven) - { - //this case is considered an invalid option so throws all aspects and types and considered as hasNothing - classfilter = CLASS_FILTER_OPTION_TYPE1; - ignoreCheck = true; + classfilter = "all"; } - if ((isValidTriplet) || (isValidTwins) || (ignoreCheck)) - { - Collection qname = null; - int maxIteration = 1; - if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) maxIteration = 2; - else if(classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) qname = this.dictionaryservice.getAllTypes(); - else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) qname = this.dictionaryservice.getAllAspects(); - - boolean flipflag = true; - - for (int i=0; i if namespaceprefix is given, then name has to be validated along with it + 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 name parameter if present along with the namespaceprefix + if(name != null) + { + classname = namespaceprefix + "_" + name; + if(this.dictionaryhelper.isValidClassname(classname) == false) { - if(flipflag) qname = this.dictionaryservice.getAllAspects(); - else qname = this.dictionaryservice.getAllTypes(); - flipflag = false; + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL"); } - - for(QName qnameObj: qname) - { - String url = this.dictionaryhelper.getNamespaceURIfromQname(qnameObj); - if(ignoreCheck || url.equals(this.dictionaryhelper.getPrefixesAndUrlsMap().get(namespaceprefix))) - { - if(isValidTriplet) qnameObj = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); - 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()); - if (isValidTriplet) break; - } - }// end of for loop - }// end of for loop - - hasData = true; - - } // end of else block - - if(hasData) - { - 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; + 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()); + } + 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); + for(QName qnameObj:this.dictionaryservice.getAllModels()) + { + if(qnameObj.getNamespaceURI().equals(namespaceQname)) + { + name = qnameObj.getLocalName(); + myModel = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespaceprefix + "_" + name)); + + // check the classfilter to pull out either all or tyype or aspects + if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) + { + qnames = this.dictionaryservice.getAspects(myModel); + qnames.addAll(this.dictionaryservice.getTypes(myModel)); + } + else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) + { + qnames = this.dictionaryservice.getTypes(myModel); + } + else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) + { + qnames = this.dictionaryservice.getAspects(myModel); + } + } + } + } } - else + + // if namespaceprefix is null, then check the classfilter to pull out either all or type or aspects + if(myModel == null) { - throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); - } + if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) + { + qnames = this.dictionaryservice.getAllAspects(); + qnames.addAll(this.dictionaryservice.getAllTypes()); + } + else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) + { + qnames = this.dictionaryservice.getAllTypes(); + } + else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) + { + qnames = 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()); + } + } + 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 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 5792c2fa64..c6bdb49b92 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java @@ -81,7 +81,7 @@ public class GetClassDetails extends DeclarativeWebScript { String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); - Map model = new HashMap(); + Map model = new HashMap(3); QName qname = null; Map classdef = new HashMap(); Map> propdef = new HashMap>(); 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 718e9a1a5f..9352fa507e 100644 --- a/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java @@ -30,7 +30,7 @@ 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; @@ -44,11 +44,13 @@ import java.util.Map; public class GetPropertyDefs extends DeclarativeWebScript { private DictionaryService dictionaryservice; - private ClassDefinition classdefinition; private DictionaryHelper dictionaryhelper; private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; + private static final String MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS = "individualproperty"; private static final String DICTIONARY_CLASS_NAME = "classname"; + private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp"; + private static final String REQ_URL_TEMPL_VAR_NAME = "n"; /** * Set the dictionaryService property. @@ -77,26 +79,69 @@ public class GetPropertyDefs extends DeclarativeWebScript protected Map executeImpl(WebScriptRequest req, Status status) { 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); + Map model = new HashMap(); - QName qname = null; - boolean classnameGiven = (classname != null) && (classname.length() > 0); - - if(classnameGiven) + QName class_qname = null; + QName property_qname = null; + + //validate the classname + if(this.dictionaryhelper.isValidClassname(classname) == true) { - qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); - } - classdefinition = this.dictionaryservice.getClass(qname); - - if(this.classdefinition != null) - { - model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.classdefinition.getProperties().values()); - return model; + class_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); } 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"); + } + + //validate namespaceprefix + 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 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 type "+ classname); + } + } + + // 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()); + } + + return model; + } } \ No newline at end of file