Dictionary REST API refactoring and bug fixing

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18574 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2010-02-11 03:40:07 +00:00
parent 09bbebf81e
commit d611d1d7e3
11 changed files with 197 additions and 478 deletions

View File

@@ -1,22 +1,8 @@
<#import "propertydefinition.lib.ftl" as propertyDefLib/> <#import "propertydefinition.lib.ftl" as propertyDefLib/>
<#if propertydefs?exists>
<#if individualproperty?exists == false>
[ [
</#if>
<#list propertydefs as propertydefinitions> <#list propertydefs as propertydefinitions>
<#if individualproperty?exists>
<#if propertydefinitions.name == individualproperty.name>
<@propertyDefLib.propertyDefJSON propertydefs=propertydefinitions/>
<#break>
</#if>
<#else>
<@propertyDefLib.propertyDefJSON propertydefs=propertydefinitions/> <@propertyDefLib.propertyDefJSON propertydefs=propertydefinitions/>
<#if propertydefinitions_has_next>,</#if> <#if propertydefinitions_has_next>,</#if>
</#if>
</#list> </#list>
<#if individualproperty?exists == false>
] ]
</#if>
<#else>
{}
</#if>

View File

@@ -544,9 +544,9 @@
<!-- DICTIONARY Service REST API --> <!-- DICTIONARY Service REST API -->
<!-- --> <!-- -->
<bean id="webscript.dictionary" abstract="true" parent="webscript"> <bean id="webscript.dictionary" abstract="true" parent="webscript" init-method="init">
<property name="dictionaryService" ref="DictionaryService"/> <property name="dictionaryService" ref="DictionaryService"/>
<property name="dictionaryHelper" ref="dictionaryWebScriptHelper"/> <property name="namespaceService" ref="NamespaceService"/>
</bean> </bean>
<bean id="webscript.org.alfresco.repository.dictionary.classes.get" class="org.alfresco.repo.web.scripts.dictionary.ClassesGet" parent="webscript.dictionary"/> <bean id="webscript.org.alfresco.repository.dictionary.classes.get" class="org.alfresco.repo.web.scripts.dictionary.ClassesGet" parent="webscript.dictionary"/>
@@ -557,12 +557,6 @@
<bean id="webscript.org.alfresco.repository.dictionary.association.get" class="org.alfresco.repo.web.scripts.dictionary.AssociationGet" parent="webscript.dictionary"/> <bean id="webscript.org.alfresco.repository.dictionary.association.get" class="org.alfresco.repo.web.scripts.dictionary.AssociationGet" parent="webscript.dictionary"/>
<bean id="webscript.org.alfresco.repository.dictionary.associations.get" class="org.alfresco.repo.web.scripts.dictionary.AssociationsGet" parent="webscript.dictionary"/> <bean id="webscript.org.alfresco.repository.dictionary.associations.get" class="org.alfresco.repo.web.scripts.dictionary.AssociationsGet" parent="webscript.dictionary"/>
<!-- Dictionary Service Web Script Helper Class -->
<bean id="dictionaryWebScriptHelper" class="org.alfresco.repo.web.scripts.dictionary.DictionaryHelper" init-method="init">
<property name="namespaceService" ref="NamespaceService"/>
<property name="dictionaryService" ref="DictionaryService"/>
</bean>
<!-- GET IMAP SERVER STATUS --> <!-- GET IMAP SERVER STATUS -->
<bean id="webscript.org.alfresco.repository.imap.imap-enabled.get" class="org.alfresco.repo.imap.scripts.ServerStatusWebScript" parent="webscript"> <bean id="webscript.org.alfresco.repository.imap.imap-enabled.get" class="org.alfresco.repo.imap.scripts.ServerStatusWebScript" parent="webscript">
<property name="imapServerEnabled"><value>${imap.server.enabled}</value></property> <property name="imapServerEnabled"><value>${imap.server.enabled}</value></property>

View File

@@ -24,51 +24,26 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import java.util.HashMap;
import java.util.Map;
/* /*
* Webscript to get the Associationdefinition for a given classname and association-name * Webscript to get the Associationdefinition for a given classname and association-name
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
public class AssociationGet extends DeclarativeWebScript public class AssociationGet extends DictionaryWebServiceBase
{ {
private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String DICTIONARY_CLASS_NAME = "classname"; private static final String DICTIONARY_CLASS_NAME = "classname";
private static final String DICTIONARY_ASSOCIATION_NAME = "assocname"; private static final String DICTIONARY_ASSOCIATION_NAME = "assocname";
/**
* Set the dictionaryService property.
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryservice = dictionaryService;
}
/**
* Set the dictionaryhelper class
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryHelper(DictionaryHelper dictionaryhelper)
{
this.dictionaryhelper = dictionaryhelper;
}
/** /**
* @Override method from DeclarativeWebScript * @Override method from DeclarativeWebScript
*/ */
@@ -81,19 +56,19 @@ public class AssociationGet extends DeclarativeWebScript
QName associationQname = null; QName associationQname = null;
//validate the classname //validate the classname
if(this.dictionaryhelper.isValidClassname(className) == false) if(isValidClassname(className) == false)
{ {
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");
} }
classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); classQname = QName.createQName(getFullNamespaceURI(className));
if(associationName == null) if(associationName == null)
{ {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association name in the URL"); throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter association name in the URL");
} }
associationQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(associationName)); associationQname = QName.createQName(getFullNamespaceURI(associationName));
if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname) != null) if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname) != null)
{ {

View File

@@ -24,28 +24,23 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import java.util.HashMap;
import java.util.Map;
/** /**
* Webscript to get the Associationdefinitions for a given classname * Webscript to get the Associationdefinitions for a given classname
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
public class AssociationsGet extends DeclarativeWebScript public class AssociationsGet extends DictionaryWebServiceBase
{ {
private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; 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 MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS = "individualproperty";
private static final String DICTIONARY_CLASS_NAME = "classname"; private static final String DICTIONARY_CLASS_NAME = "classname";
@@ -53,26 +48,6 @@ public class AssociationsGet extends DeclarativeWebScript
private static final String REQ_URL_TEMPL_VAR_NAME = "n"; private static final String REQ_URL_TEMPL_VAR_NAME = "n";
private static final String REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER = "af"; private static final String REQ_URL_TEMPL_VAR_ASSOCIATION_FILTER = "af";
/**
* Set the dictionaryService property.
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryservice = dictionaryService;
}
/**
* Set the dictionaryhelper class
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryHelper(DictionaryHelper dictionaryhelper)
{
this.dictionaryhelper = dictionaryhelper;
}
/** /**
* @Override method from DeclarativeWebScript * @Override method from DeclarativeWebScript
*/ */
@@ -94,15 +69,15 @@ public class AssociationsGet extends DeclarativeWebScript
} }
//validate association filter //validate association filter
if(this.dictionaryhelper.isValidAssociationFilter(associationFilter) == false) if(isValidAssociationFilter(associationFilter) == false)
{ {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the associationFilter - " + associationFilter + " - parameter in the URL"); throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the associationFilter - " + associationFilter + " - parameter in the URL");
} }
//validate classname //validate classname
if(this.dictionaryhelper.isValidClassname(className) == true) if(isValidClassname(className) == true)
{ {
classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); classQname = QName.createQName(getFullNamespaceURI(className));
} }
else else
{ {
@@ -140,13 +115,8 @@ public class AssociationsGet extends DeclarativeWebScript
// if both namespaceprefix and name parameters are given then, the combination namespaceprefix_name is used as the index to create the 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) 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 // validate the class combination namespaceprefix_name
associationQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespacePrefix + "_" + name)); associationQname = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname)== null) if(this.dictionaryservice.getClass(classQname).getAssociations().get(associationQname)== null)
{ {

View File

@@ -24,56 +24,30 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; package org.alfresco.repo.web.scripts.dictionary;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/** /**
* Webscript to get the Classdefinitions for a classname eg. =>cm_author * Webscript to get the Classdefinitions for a classname eg. =>cm_author
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
public class ClassGet extends DeclarativeWebScript public class ClassGet extends DictionaryWebServiceBase
{ {
private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_CLASS_DETAILS = "classdefs"; private static final String MODEL_PROP_KEY_CLASS_DETAILS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String DICTIONARY_CLASS_NAME = "className"; private static final String DICTIONARY_CLASS_NAME = "className";
/**
* Set the dictionaryService property.
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryservice = dictionaryService;
}
/**
* Set the dictionaryhelper class
*
* @param dictionaryHelper The dictionary helper instance to set
*/
public void setDictionaryHelper(DictionaryHelper dictionaryhelper)
{
this.dictionaryhelper = dictionaryhelper;
}
/** /**
* @Override method from DeclarativeWebScript * @Override method from DeclarativeWebScript
*/ */
@@ -88,9 +62,9 @@ public class ClassGet extends DeclarativeWebScript
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>(); Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
//validate the classname and throw appropriate error message //validate the classname and throw appropriate error message
if(this.dictionaryhelper.isValidClassname(className) == true) if(isValidClassname(className) == true)
{ {
classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); classQname = QName.createQName(getFullNamespaceURI(className));
classdef.put(classQname, this.dictionaryservice.getClass(classQname)); classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values()); propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values()); assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());

View File

@@ -24,32 +24,28 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
/** /**
* Webscript to get the Classdefinitions using classfilter , namespaceprefix and name * Webscript to get the Classdefinitions using classfilter , namespaceprefix and name
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
public class ClassesGet extends DeclarativeWebScript public class ClassesGet extends DictionaryWebServiceBase
{ {
private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs"; private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
@@ -62,34 +58,14 @@ public class ClassesGet extends DeclarativeWebScript
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp"; 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_NAME = "n";
/**
* Set the dictionaryService property.
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryservice = dictionaryService;
}
/**
* Set the dictionaryhelper class
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryHelper(DictionaryHelper dictionaryhelper)
{
this.dictionaryhelper = dictionaryhelper;
}
/** /**
* @Override method from DeclarativeWebScript * @Override method from DeclarativeWebScript
*/ */
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{ {
String classFilter = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER)); String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
String namespacePrefix = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX)); String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
String name = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME)); String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
String className = null; String className = null;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>(); Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
@@ -108,7 +84,7 @@ public class ClassesGet extends DeclarativeWebScript
} }
//validate classfilter //validate classfilter
if(this.dictionaryhelper.isValidClassFilter(classFilter) == false) if(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");
} }
@@ -122,20 +98,15 @@ public class ClassesGet extends DeclarativeWebScript
//validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it //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)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespacePrefix + " parameter in the URL");
}
//validate name parameter if present along with the namespaceprefix //validate name parameter if present along with the namespaceprefix
if(name != null) if(name != null)
{ {
className = namespacePrefix + "_" + name; className = namespacePrefix + "_" + name;
if(this.dictionaryhelper.isValidClassname(className) == false) if(isValidClassname(className) == false)
{ {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL"); throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL");
} }
classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); classQname = QName.createQName(getFullNamespaceURI(className));
classdef.put(classQname, this.dictionaryservice.getClass(classQname)); classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values()); propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values()); assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
@@ -143,13 +114,13 @@ public class ClassesGet extends DeclarativeWebScript
else 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 //if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
String namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespacePrefix); String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
for(QName qnameObj:this.dictionaryservice.getAllModels()) for(QName qnameObj:this.dictionaryservice.getAllModels())
{ {
if(qnameObj.getNamespaceURI().equals(namespaceUri)) if(qnameObj.getNamespaceURI().equals(namespaceUri))
{ {
name = qnameObj.getLocalName(); name = qnameObj.getLocalName();
myModel = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespacePrefix + "_" + name)); myModel = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
// check the classfilter to pull out either all or type or aspects // 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))

View File

@@ -210,27 +210,18 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
req.setArgs(arguments); req.setArgs(arguments);
Response response = sendRequest(req, 200); Response response = sendRequest(req, 200);
assertEquals(200,response.getStatus()); assertEquals(200,response.getStatus());
JSONObject resultSet = new JSONObject(response.getContentAsString());
validatePropertyDef(resultSet);
// both name and namespaceprefix parameters are needed //JSONObject resultSet = new JSONObject(response.getContentAsString());
arguments.clear(); //validatePropertyDef(resultSet);
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
// both name and namespaceprefix parameters are needed JSONArray result = new JSONArray(response.getContentAsString());
arguments.clear(); assertEquals(200,response.getStatus());
arguments.put("n", "created"); assertEquals(5, result.length());
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
//validate with no parameter => returns an array of property definitions //validate with no parameter => returns an array of property definitions
arguments.clear(); arguments.clear();
response = sendRequest(req, 200); response = sendRequest(req, 200);
JSONArray result = new JSONArray(response.getContentAsString()); result = new JSONArray(response.getContentAsString());
assertEquals(200,response.getStatus()); assertEquals(200,response.getStatus());
assertEquals(result.length()>0, true); assertEquals(result.length()>0, true);
for(int i=0; i<result.length(); i++) for(int i=0; i<result.length(); i++)
@@ -241,46 +232,6 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
} }
} }
//wrong data
arguments.clear();
response = sendRequest(new GetRequest("/api/classes/cm_welcome/properties"), 404);
assertEquals(404,response.getStatus());
//ask for a property which is not present in cm_auditable => results a null object
arguments.clear();
arguments.put("n", "dublincore");
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 200);
resultSet = new JSONObject(response.getContentAsString());
assertEquals(0,resultSet.length());
assertEquals(200,response.getStatus());
// with invalid namespace parameter
arguments.clear();
arguments.put("nsp", "sara");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
// 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, 200);
resultSet = new JSONObject(response.getContentAsString());
assertEquals(0,resultSet.length());
arguments.clear();
arguments.put("nsp", "wcm");
arguments.put("n", "created");
req.setArgs(arguments);
response = sendRequest(req, 200);
resultSet = new JSONObject(response.getContentAsString());
assertEquals(0,resultSet.length());
} }
public void testGetClassDetail() throws Exception public void testGetClassDetail() throws Exception
@@ -604,14 +555,6 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
response = sendRequest(req, 404); response = sendRequest(req, 404);
assertEquals(404,response.getStatus()); assertEquals(404,response.getStatus());
//check for all data under cm without option=>name
arguments.clear();
arguments.put("cf", "all");
arguments.put("nsp", "cmbb");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
//check for all dictionary data without option=>name and option=>namespaceprefix //check for all dictionary data without option=>name and option=>namespaceprefix
arguments.clear(); arguments.clear();
arguments.put("cf", "a<EFBFBD>&llsara"); arguments.put("cf", "a<EFBFBD>&llsara");
@@ -633,13 +576,6 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
response = sendRequest(req, 404); response = sendRequest(req, 404);
assertEquals(404,response.getStatus()); assertEquals(404,response.getStatus());
//check with an invalid namespaceprefix
arguments.clear();
arguments.put("nsp", "cmsd");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
//check for all types dictionary data without option=>name and option=>namespaceprefix and option=>classfilter //check for all types dictionary data without option=>name and option=>namespaceprefix and option=>classfilter
arguments.clear(); arguments.clear();
req.setArgs(arguments); req.setArgs(arguments);
@@ -727,15 +663,6 @@ public class DictionaryRestApiTest extends BaseWebScriptTest
response = sendRequest(req, 404); response = sendRequest(req, 404);
assertEquals(404,response.getStatus()); assertEquals(404,response.getStatus());
//wrong data
// invalid namespaceprefix
arguments.clear();
arguments.put("r", "true");
arguments.put("nsp", "wcms");
req.setArgs(arguments);
response = sendRequest(req, 404); // need to have an option to filter by name as well
assertEquals(404,response.getStatus());
// invalid name and namespaceprefix // invalid name and namespaceprefix
arguments.clear(); arguments.clear();
arguments.put("r", "true"); arguments.put("r", "true");

View File

@@ -24,29 +24,35 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; package org.alfresco.repo.web.scripts.dictionary;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.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.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.namespace.InvalidQNameException;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
/* /*
* Helper class for Dictionary Service webscripts * Base class for Dictionary web scripts
*
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
public abstract class DictionaryWebServiceBase extends DeclarativeWebScript
public class DictionaryHelper
{ {
private static final String NAME_DELIMITER = "_"; private static final String NAME_DELIMITER = "_";
private NamespaceService namespaceservice;
private Map<String, String> prefixesAndUrlsMap; private Map<String, String> prefixesAndUrlsMap;
private Map<String, String> urlsAndPrefixesMap; private Map<String, String> urlsAndPrefixesMap;
private Collection<String> prefixes;
private DictionaryService dictionaryservice; /** Namespace service */
protected NamespaceService namespaceService;
/** Dictionary service */
protected DictionaryService dictionaryservice;
private static final String CLASS_FILTER_OPTION_TYPE1 = "all"; 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_TYPE2 = "aspect";
@@ -63,7 +69,7 @@ public class DictionaryHelper
*/ */
public void setNamespaceService(NamespaceService namespaceservice) public void setNamespaceService(NamespaceService namespaceservice)
{ {
this.namespaceservice = namespaceservice; this.namespaceService = namespaceservice;
} }
/** /**
@@ -81,17 +87,41 @@ public class DictionaryHelper
*/ */
public void init() public void init()
{ {
this.prefixes = this.namespaceservice.getPrefixes(); Collection<String> prefixes = this.namespaceService.getPrefixes();
this.prefixesAndUrlsMap = new HashMap<String, String>(prefixes.size()); this.prefixesAndUrlsMap = new HashMap<String, String>(prefixes.size());
this.urlsAndPrefixesMap = new HashMap<String, String>(prefixes.size()); this.urlsAndPrefixesMap = new HashMap<String, String>(prefixes.size());
for (String prefix : prefixes) for (String prefix : prefixes)
{ {
String url = this.namespaceservice.getNamespaceURI(prefix); String url = this.namespaceService.getNamespaceURI(prefix);
this.prefixesAndUrlsMap.put(prefix, url); this.prefixesAndUrlsMap.put(prefix, url);
this.urlsAndPrefixesMap.put(url, prefix); this.urlsAndPrefixesMap.put(url, prefix);
} }
} }
protected QName createClassQName(String className)
{
QName result = null;
int index = className.indexOf(NAME_DELIMITER);
if (index > 0)
{
String prefix = className.substring(0, index);
String shortName = className.substring(index+1);
String url = namespaceService.getNamespaceURI(prefix);
if (url != null && url.length() != 0 &&
shortName != null && shortName.length() != 0)
{
QName classQName = QName.createQName(url, shortName);
if (dictionaryservice.getClass(classQName) != null)
{
result = classQName;
}
}
}
return result;
}
/** /**
* *
* @param qname * @param qname
@@ -124,23 +154,6 @@ public class DictionaryHelper
} }
} }
/**
*
* @param className the class name as cm_person
* @return String the full name in the following format {namespaceuri}shorname
*/
public String getNamespaceURIfromPrefix(String prefix)
{
if(this.isValidPrefix(prefix) == true)
{
return this.prefixesAndUrlsMap.get(prefix);
}
else
{
return null;
}
}
/** /**
* *
* @param classname - checks whether the classname is valid , gets the classname as input e.g cm_person * @param classname - checks whether the classname is valid , gets the classname as input e.g cm_person
@@ -152,8 +165,8 @@ public class DictionaryHelper
try try
{ {
qname = QName.createQName(this.getFullNamespaceURI(classname)); qname = QName.createQName(this.getFullNamespaceURI(classname));
if ((this.isValidPrefix(this.getPrefix(classname)) == true) && if (//(isValidPrefix(getPrefix(classname)) == true) &&
this.dictionaryservice.getClass(qname) != null) dictionaryservice.getClass(qname) != null)
{ {
return true; return true;
} }
@@ -170,17 +183,19 @@ public class DictionaryHelper
* @param prefix - 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 * @return true if the prefix is valid or false
*/ */
public boolean isValidPrefix(String prefix) // public boolean isValidPrefix(String prefix)
{ // {
if(this.prefixes.contains(prefix) == true) // this.namespaceservice.
{ //
return true; // if(this.prefixes.contains(prefix) == true)
} // {
else // return true;
{ // }
return false; // else
} // {
} // return false;
// }
// }
/** /**
* *

View File

@@ -24,16 +24,17 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; package org.alfresco.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import java.util.HashMap;
import java.util.Map;
/** /**
* *
@@ -42,37 +43,11 @@ import java.util.Map;
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
public class PropertiesGet extends DeclarativeWebScript public class PropertiesGet extends DictionaryWebServiceBase
{ {
private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; 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 DICTIONARY_CLASS_NAME = "classname";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp"; 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.
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryservice = dictionaryService;
}
/**
* Set the dictionaryhelper class
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryHelper(DictionaryHelper dictionaryhelper)
{
this.dictionaryhelper = dictionaryhelper;
}
/** /**
* @Override method from DeclarativeWebScript * @Override method from DeclarativeWebScript
@@ -80,51 +55,41 @@ public class PropertiesGet extends DeclarativeWebScript
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) protected Map<String, Object> 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); if (className == null || className.length() == 0)
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
Map<String, Object> model = new HashMap<String, Object>();
QName classQname = null;
QName propertyQname = null;
//validate the className
if(this.dictionaryhelper.isValidClassname(className) == true)
{ {
classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); // Error
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
} }
else QName classQName = createClassQName(className);
if (classQName == null)
{ {
// Error
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 for the presence of both name and namespaceprefix String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
if((name == null && namespacePrefix != null) ||
(name != null && namespacePrefix == null)) String namespaceURI = null;
if (namespacePrefix != null)
{ {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing either name or namespacePrefix parameter in the URL - both combination of name and namespacePrefix is needed"); namespaceURI = this.namespaceService.getNamespaceURI(namespacePrefix);
} }
// if both namespacePrefix and name parameters are given then, the combination namespacePrefix_name is used as the index to create the propertyqname Map<QName, PropertyDefinition> propMap = dictionaryservice.getClass(classQName).getProperties();
if(name != null && namespacePrefix != null) List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet())
{ {
if(this.dictionaryhelper.isValidPrefix(namespacePrefix) == false) if ((namespaceURI != null &&
namespaceURI.equals(entry.getKey().getNamespaceURI()) == true) ||
namespaceURI == null)
{ {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespacePrefix - " + namespacePrefix + " - parameter in the URL"); props.add(entry.getValue());
} }
// validate the class combination namespacePrefix_name
propertyQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(namespacePrefix + "_" + name));
if(this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname) != null)
{
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());
}
}
else
{
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.dictionaryservice.getClass(classQname).getProperties().values());
} }
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
return model; return model;
} }

View File

@@ -24,16 +24,14 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; package org.alfresco.repo.web.scripts.dictionary;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache; import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status; import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException; import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest; import org.springframework.extensions.webscripts.WebScriptRequest;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import java.util.HashMap;
import java.util.Map;
/** /**
* Webscript to get the Propertydefinition for a given classname and propname * Webscript to get the Propertydefinition for a given classname and propname
@@ -41,35 +39,12 @@ import java.util.Map;
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
public class PropertyGet extends DeclarativeWebScript public class PropertyGet extends DictionaryWebServiceBase
{ {
private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String DICTIONARY_CLASS_NAME = "classname"; private static final String DICTIONARY_CLASS_NAME = "classname";
private static final String DICTIONARY_PROPERTY_NAME = "propname"; private static final String DICTIONARY_PROPERTY_NAME = "propname";
/**
* Set the dictionaryService property.
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryservice = dictionaryService;
}
/**
* Set the dictionaryhelper class
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryHelper(DictionaryHelper dictionaryhelper)
{
this.dictionaryhelper = dictionaryhelper;
}
/** /**
* @Override method from DeclarativeWebScript * @Override method from DeclarativeWebScript
*/ */
@@ -82,12 +57,12 @@ public class PropertyGet extends DeclarativeWebScript
QName propertyQname = null; QName propertyQname = null;
//validate the classname //validate the classname
if(this.dictionaryhelper.isValidClassname(className) == false) if(isValidClassname(className) == false)
{ {
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");
} }
classQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); classQname = QName.createQName(getFullNamespaceURI(className));
//validate the presence of property name //validate the presence of property name
if(propertyName == null) if(propertyName == null)
@@ -95,7 +70,7 @@ public class PropertyGet extends DeclarativeWebScript
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter propertyname in the URL"); throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing parameter propertyname in the URL");
} }
propertyQname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(propertyName)); propertyQname = QName.createQName(getFullNamespaceURI(propertyName));
if(this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname) != null) if(this.dictionaryservice.getClass(classQname).getProperties().get(propertyQname) != null)
{ {

View File

@@ -24,31 +24,27 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; package org.alfresco.repo.web.scripts.dictionary;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/** /**
* 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 * @author Saravanan Sellathurai
*/ */
public class SubClassesGet extends DeclarativeWebScript public class SubClassesGet extends DictionaryWebServiceBase
{ {
private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs"; private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
@@ -59,26 +55,6 @@ public class SubClassesGet extends DeclarativeWebScript
private static final String REQ_URL_TEMPL_VAR_NAME = "n"; private static final String REQ_URL_TEMPL_VAR_NAME = "n";
private static final String DICTIONARY_CLASS_NAME = "classname"; private static final String DICTIONARY_CLASS_NAME = "classname";
/**
* Set the dictionaryService property.
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryservice = dictionaryService;
}
/**
* Set the dictionaryhelper class
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryHelper(DictionaryHelper dictionaryhelper)
{
this.dictionaryhelper = dictionaryhelper;
}
/** /**
* @Override method from DeclarativeWebScript * @Override method from DeclarativeWebScript
*/ */
@@ -87,7 +63,7 @@ public class SubClassesGet extends DeclarativeWebScript
String name = req.getParameter(REQ_URL_TEMPL_VAR_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);
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
String recursiveValue = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN)); String recursiveValue = getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN));
boolean recursive = true; boolean recursive = true;
@@ -121,10 +97,10 @@ public class SubClassesGet extends DeclarativeWebScript
} }
//validate the className //validate the className
if(this.dictionaryhelper.isValidClassname(className) == true) if(isValidClassname(className) == true)
{ {
classQName = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(className)); classQName = QName.createQName(getFullNamespaceURI(className));
if(this.dictionaryhelper.isValidTypeorAspect(className) == true) if(isValidTypeorAspect(className) == true)
{ {
isAspect = true; isAspect = true;
} }
@@ -144,19 +120,10 @@ public class SubClassesGet extends DeclarativeWebScript
qname = this.dictionaryservice.getSubTypes(classQName, recursive); qname = this.dictionaryservice.getSubTypes(classQName, recursive);
} }
//validate the namespaceprefix parameter
if(namespacePrefix != null)
{
if(this.dictionaryhelper.isValidPrefix(namespacePrefix) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespacePrefix - " + namespacePrefix + " - parameter in the URL");
}
}
//validate the name parameter //validate the name parameter
if(name != null) if(name != null)
{ {
if(this.dictionaryhelper.isValidModelName(name) == false) if(isValidModelName(name) == false)
{ {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name parameter - " + name + " in the URL"); throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name parameter - " + name + " in the URL");
} }
@@ -165,12 +132,12 @@ public class SubClassesGet extends DeclarativeWebScript
//validate the name parameter //validate the name parameter
if (namespacePrefix == null && name != null) if (namespacePrefix == null && name != null)
{ {
namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(this.dictionaryhelper.getPrefixFromModelName(name)); namespaceUri = namespaceService.getNamespaceURI(getPrefixFromModelName(name));
} }
if (namespacePrefix != null && name == null) if (namespacePrefix != null && name == null)
{ {
namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespacePrefix); namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
} }
if(namespacePrefix == null && name == null) if(namespacePrefix == null && name == null)
@@ -181,11 +148,11 @@ public class SubClassesGet extends DeclarativeWebScript
if (namespacePrefix != null && name != null) if (namespacePrefix != null && name != null)
{ {
if(this.dictionaryhelper.isValidClassname(namespacePrefix + "_" + name) == false) if(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 = namespaceService.getNamespaceURI(namespacePrefix);
} }
for(QName qnameObj: qname) for(QName qnameObj: qname)