Subclasses webscript implementation for dictionary service and unit test

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12010 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Saravanan Sellathurai
2008-11-20 00:03:19 +00:00
parent e29c573862
commit 2a9b4c5967
8 changed files with 340 additions and 80 deletions

View File

@@ -322,8 +322,8 @@ public class DictionaryServiceTest extends BaseWebScriptTest
* 4 no no no Array of classes [returns all classes of both type and aspects in the entire repository]
* 5 no yes yes single class [returns a single class of a valid namespaceprefix:name combination]
* 6 no yes no Array of classes [returns an array of all aspects and types under particular namespaceprefix]
* 7 no no yes Array of all classes [since name alone doesn't makes any meaning]
* 8 yes no yes
* 7 no no yes 404 error [since name alone doesn't makes any meaning]
* 8 yes no yes 404 error [since name alone doesn't makes any meaning]
* Test cases are provided for all the above scenarios
*/
@@ -578,88 +578,21 @@ public class DictionaryServiceTest extends BaseWebScriptTest
}
assertEquals(200,response.getStatus());
//check for a name alone without classfilter and namespaceprefix option [case-type:7]
//check for a name alone without classfilter and namespaceprefix option [case-type:7] => returns 404 error
arguments.clear();
arguments.put("n", "cmobject");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(193, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
//check for a name alone without classfilter and namespaceprefix option [case-type:7]
arguments.clear();
arguments.put("n", "thumbnailed");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(193, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
//check for a type under cm with name cmobject and no namespaceprefix [case-type:8]
//check for a type under cm with name cmobject and no namespaceprefix [case-type:8] => returns 404 error
arguments.clear();
arguments.put("cf", "type");
arguments.put("n", "cmobject");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(107, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
//check for a type under cm with name cmobject and no namespaceprefix [case-type:8]
arguments.clear();
arguments.put("cf", "aspect");
arguments.put("n", "thumbnailed");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(86, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
//check for a type under cm with name cmobject and no namespaceprefix [case-type:8]
arguments.clear();
arguments.put("cf", "all");
arguments.put("n", "thumbnailed");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(193, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
// Test with wrong data
//check for all aspects under cm without option=>name
@@ -721,6 +654,83 @@ public class DictionaryServiceTest extends BaseWebScriptTest
assertEquals(200,response.getStatus());
}
public void testSubClassDetails() throws Exception
{
GetRequest req = new GetRequest(URL_SITES + "/sys_base/subclasses");
Map< String, String > arguments = new HashMap< String, String >();
arguments.put("r", "true");
req.setArgs(arguments);
Response response = sendRequest(req, 200);
assertEquals(200,response.getStatus());
response = sendRequest(req, 200);
JSONArray result = new JSONArray(response.getContentAsString());
assertEquals(104, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
arguments.clear();
arguments.put("r", "false");
req.setArgs(arguments);
response = sendRequest(req, 200);
assertEquals(200,response.getStatus());
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(17, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
assertEquals(200,response.getStatus());
arguments.clear();
arguments.put("r", "false");
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 200);
assertEquals(200,response.getStatus());
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(2, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
arguments.clear();
arguments.put("r", "true");
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 200);
assertEquals(200,response.getStatus());
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(13, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(200,response.getStatus());
}
public void testGetAssociatoinDef() throws Exception
{
GetRequest req = new GetRequest(URL_SITES + "/cm_person/association/cm_avatar");
@@ -751,6 +761,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest
if(result.getJSONObject(i).get("name").equals("wca:renderingenginetemplates"))
validateAssociation(result.getJSONObject(i));
}
assertEquals(200,response.getStatus());
//validate with associationfilter=>child and classname=>wca_form
arguments.clear();
@@ -764,6 +775,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest
if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults"))
validateChildAssociation(result.getJSONObject(i));
}
assertEquals(200,response.getStatus());
//validate with associationfilter=>general and classname=>wca_form
arguments.clear();
@@ -822,6 +834,20 @@ public class DictionaryServiceTest extends BaseWebScriptTest
validateChildAssociation(result.getJSONObject(i));
}
//look for childassociation in the class wca_form , with a name parameter
arguments.clear();
arguments.put("af", "child");
arguments.put("n", "formworkflowdefaults");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(1,result.length());
for(int i=0; i<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults"))
validateChildAssociation(result.getJSONObject(i));
}
//look for childassociation in the class wca_form , with no name parameter
arguments.clear();
arguments.put("af", "child");

View File

@@ -123,7 +123,7 @@ public class GetAssociationDefs extends DeclarativeWebScript
}
}
// validate the condition, if name is present and namespaceprefix is null => if the name is a valid
// validate the condition, if name is present and namespaceprefix is null
if(name !=null && namespaceprefix == null)
{
assoc_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(this.dictionaryhelper.getPrefix(classname) + "_" + name));
@@ -154,12 +154,12 @@ public class GetAssociationDefs extends DeclarativeWebScript
model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(class_qname).getChildAssociations().get(assoc_qname));
}
else
{
{ //association filter is either general or all
model.put(MODEL_PROP_KEY_INDIVIDUAL_PROPERTY_DEFS, this.dictionaryservice.getClass(class_qname).getAssociations().get(assoc_qname));
}
}
else
{ //if both name and namespaceprefix are not given, then if the assocfilter is a child =>pull only the childassociations, else if general=> pull
{ // this point is always reached, if both name and namespaceprefix are not given OR Just namespaceprefix is alone given
if(associationFilter.equals("child"))
{
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.dictionaryservice.getClass(class_qname).getChildAssociations().values());

View File

@@ -111,6 +111,11 @@ public class GetClassDetail extends DeclarativeWebScript
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classfilter + " provided in the URL");
}
if(namespaceprefix == null && name != null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
//validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
if(namespaceprefix != null)
{

View File

@@ -0,0 +1,208 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.repo.web.scripts.dictionary;
import org.alfresco.web.scripts.Cache;
import org.alfresco.web.scripts.DeclarativeWebScript;
import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
*
* Webscript to get the Sub-Classdefinitions using classfilter , namespaceprefix and name
* @author Saravanan Sellathurai
*/
public class GetSubClassesDef extends DeclarativeWebScript
{
private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN = "r";
//private static final String REQ_URL_TEMPL_VAR_CLASS_FILTER = "cf";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n";
private static final String DICTIONARY_CLASS_NAME = "classname";
/**
* Set the dictionaryService property.
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryservice = dictionaryService;
}
/**
* Set the dictionaryhelper class
*
* @param dictionaryService The dictionary service instance to set
*/
public void setDictionaryHelper(DictionaryHelper dictionaryhelper)
{
this.dictionaryhelper = dictionaryhelper;
}
/**
* @Override method from DeclarativeWebScript
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
String namespaceprefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
String recursive_value = this.dictionaryhelper.getValidInput(req.getParameter(REQ_URL_TEMPL_IMMEDIATE_SUB_TYPE_CHILDREN));
boolean recursive = true;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
Map<String, Object> model = new HashMap<String, Object>();
QName classQName = null;
String namespaceUri = null;
Collection <QName> qname = null;
boolean isAspect = false;
boolean ignoreCheck = false;
// validate recursive parameter => can be either true or false or null
if(recursive_value == null)
{
recursive = true;
}
else if(recursive_value.equalsIgnoreCase("true"))
{
recursive = true;
}
else if (recursive_value.equalsIgnoreCase("false"))
{
recursive = false;
}
else
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the value for the parameter recursive=> " + recursive_value +" can only be either true or false");
}
//validate the classname
if(this.dictionaryhelper.isValidClassname(classname) == true)
{
classQName = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname));
if(this.dictionaryhelper.isValidTypeorAspect(classname) == true)
{
isAspect = true;
}
}
else
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classname - " + classname + " parameter in the URL");
}
// collect the subaspects or subtypes of the class
if(isAspect == true)
{
qname = this.dictionaryservice.getSubAspects(classQName, recursive);
}
else
{
qname = this.dictionaryservice.getSubTypes(classQName, recursive);
}
//validate the namespaceprefix parameter
if(namespaceprefix != null)
{
if(this.dictionaryhelper.isValidPrefix(namespaceprefix) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " - parameter in the URL");
}
}
//validate the name parameter
if(name != null)
{
if(this.dictionaryhelper.isValidModelName(name) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name parameter - " + name + " in the URL");
}
}
//validate the name parameter
if (namespaceprefix == null && name != null)
{
namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(this.dictionaryhelper.getPrefixFromModelName(name));
}
if (namespaceprefix != null && name == null)
{
namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespaceprefix);
}
if(namespaceprefix == null && name == null)
{
namespaceUri = null;
ignoreCheck = true;
}
if (namespaceprefix != null && name != null)
{
if(this.dictionaryhelper.isValidClassname(namespaceprefix + "_" + name) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the namespaceprefix - " + namespaceprefix + " and name - "+ name + " - parameter in the URL");
}
namespaceUri = this.dictionaryhelper.getNamespaceURIfromPrefix(namespaceprefix);
}
for(QName qnameObj: qname)
{
if(ignoreCheck || qnameObj.getNamespaceURI().equals(namespaceUri))
{
classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
}
}
model.put(MODEL_PROP_KEY_CLASS_DEFS, classdef.values());
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
return model;
}
}