Changes to dictionary service webscripts

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11997 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Saravanan Sellathurai
2008-11-19 16:31:20 +00:00
parent e53443521a
commit e29c573862
12 changed files with 959 additions and 255 deletions

View File

@@ -1,7 +1,7 @@
<webscript>
<shortname>Get Association Definitions</shortname>
<description>Get the collection of association definitions for a given classname </description>
<url>/api/classes/{classname}/associations</url>
<url>/api/classes/{classname}/associations?af={associationFilter?}&amp;nsp={namespacePrefix?}&amp;n={name?}</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>

View File

@@ -1,7 +1,11 @@
<#import "assocdefinition.lib.ftl" as assocDefLib/>
[
<#list assocdefs as assocdefs>
<#if assocdefs.isChild() == false>
<#if individualproperty?exists>
<#if assocdefs.name == individualproperty.name>
<@assocDefLib.assocDefJSON assocdefs=assocdefs/>
</#if>
<#else>
<@assocDefLib.assocDefJSON assocdefs=assocdefs/>
<#if assocdefs_has_next>,</#if>
</#if>

View File

@@ -1,7 +1,7 @@
<webscript>
<shortname>Get Property Definitions</shortname>
<description>Get the collection of property definitions</description>
<url>/api/classes/{classname}/properties</url>
<url>/api/classes/{classname}/properties?nsp={namespacePrefix?}&amp;n={name?}</url>
<format default="json"/>
<authentication>user</authentication>
<transaction>required</transaction>

View File

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

View File

@@ -26,12 +26,15 @@
"indexedAtomically" : ${propertydefs.indexedAtomically?string},
"constraints" :
[
<#--
<#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><#if key_has_next>,</#if>
</#list>
</#if>-->
}<#if constraintdefs_has_next>,</#if>
</#list>
</#if>
],
"url" : "${"/api/classes/" + url.templateArgs.classname + "/property/" + propertydefs.name.toPrefixString()?replace(":","_")}"
}

View File

@@ -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<String> 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,17 +92,24 @@ 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)
{
try
{
String result = null;
String prefix = this.getPrefix(classname);
@@ -100,6 +118,11 @@ public class DictionaryHelper
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)
{
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,8 +297,9 @@ public class DictionaryHelper
return prefix;
}
/*
* returns the shortname from the classname of the format cm_person
/**
* @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<String, String> getPrefixesAndUrlsMap()
{

View File

@@ -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<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("cm:created"))
assertEquals(true, validatePropertyDef(result.getJSONObject(i)));
{
validatePropertyDef(result.getJSONObject(i));
}
}
// validate without namespaceprefix parameter
arguments.clear();
arguments.put("n", "created");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(200,response.getStatus());
assertEquals(1, result.length());
for(int i=0; i<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("cm:created"))
{
validatePropertyDef(result.getJSONObject(i));
}
}
//validate with no parameter => 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; i<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("cm:created"))
{
validatePropertyDef(result.getJSONObject(i));
}
}
//wrong data
arguments.clear();
response = sendRequest(new GetRequest("/api/classes/cm_welcome/properties"), 404);
assertEquals(404,response.getStatus());
//with invalid name parameter
arguments.clear();
arguments.put("n", "dublincore");
arguments.put("nsp", "cm");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,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
arguments.clear();
arguments.put("nsp", "cm");
arguments.put("n", "create");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
// name is valid here, but the namespaceprefix is different from the classname i.e classname is of cm and given namespaceprefix is wcm - which contradicts
arguments.clear();
arguments.put("nsp", "wcm");
arguments.put("n", "created");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
}
public void testGetClassDetail() throws Exception
@@ -182,14 +297,15 @@ public class DictionaryServiceTest extends BaseWebScriptTest
GetRequest req = new GetRequest(URL_SITES + "/cm_thumbnailed");
Response response = sendRequest(req, 200);
JSONObject result = new JSONObject(response.getContentAsString());
assertEquals(10, result.length());
assertEquals(200,response.getStatus());
assertEquals(true, validateAspectClass(result));
validateAspectClass(result);
req = new GetRequest(URL_SITES + "/cm_cmobject");
response = sendRequest(req, 200);
result = new JSONObject(response.getContentAsString());
assertEquals(10, result.length());
assertEquals(200,response.getStatus());
assertEquals(true, validateTypeClass(result));
validateTypeClass(result);
response = sendRequest(new GetRequest("/api/classes/cm_hi"), 404);
assertEquals(404,response.getStatus());
@@ -198,7 +314,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest
public void testGetClassDetails() throws Exception
{
/**
* There are seven scenarios with getting class details , all are optional fields
* There are eight scenarios with getting class details , all are optional fields
* Classfilter namespaceprefix name Returns
* 1 yes yes yes single class
* 2 yes yes no Array of classes [returns array of classes of the particular namespaceprefix]
@@ -207,7 +323,7 @@ public class DictionaryServiceTest extends BaseWebScriptTest
* 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
* Test cases are provided for all the above scenarios
*/
@@ -221,12 +337,15 @@ public class DictionaryServiceTest extends BaseWebScriptTest
req.setArgs(arguments);
Response response = sendRequest(req, 200);
JSONArray result = new JSONArray(response.getContentAsString());
boolean flag = false;
assertEquals(1, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) flag = validateAspectClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
assertEquals(true , flag);
}
//check array length
assertEquals(200,response.getStatus());
//check for a type under cm with name cmobject [case-type:1]
@@ -237,12 +356,14 @@ 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<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a type under cm with name cmobject [case-type:1]
@@ -253,12 +374,14 @@ 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<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a type under cm without options=>name, 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; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a aspect under cm without options=>name [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; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) flag = validateAspectClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for all aspects under cm without options=>name [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; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) flag = validateAspectClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for all type under cm without options=>name, 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; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for all aspect under cm without options=>name, 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<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) flag = validateAspectClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for all aspect and type in the repository when nothing is given [case-type:4]
arguments.clear();
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
flag = false;
assertEquals(193, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) flag = validateAspectClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for all aspect and type in the repository when nothing is given [case-type:4]
arguments.clear();
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
flag = false;
assertEquals(193, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a classname [namespaceprefix:name => 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<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a classname [namespaceprefix:name => 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<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) flag = validateAspectClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a namespaceprefix [namespaceprefix => 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<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) flag = validateAspectClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed"))
{
validateAspectClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a namespaceprefix [namespaceprefix => 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<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a namespaceprefix [namespaceprefix => 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; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a name alone without classfilter and namespaceprefix option [case-type:7]
@@ -439,12 +584,14 @@ public class DictionaryServiceTest extends BaseWebScriptTest
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
flag = false;
assertEquals(193, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:cmobject")) flag = validateTypeClass(result.getJSONObject(i));
if (result.getJSONObject(i).get("name").equals("cm:cmobject"))
{
validateTypeClass(result.getJSONObject(i));
}
}
assertEquals(true , flag);
assertEquals(200,response.getStatus());
//check for a name alone without classfilter and namespaceprefix option [case-type:7]
@@ -453,12 +600,65 @@ public class DictionaryServiceTest extends BaseWebScriptTest
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
flag = false;
assertEquals(193, result.length());
for(int i=0; i<result.length(); i++)
{
if (result.getJSONObject(i).get("name").equals("cm:thumbnailed")) flag = validateAspectClass(result.getJSONObject(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", "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(true , flag);
assertEquals(200,response.getStatus());
// Test with wrong data
@@ -521,33 +721,200 @@ public class DictionaryServiceTest extends BaseWebScriptTest
assertEquals(200,response.getStatus());
}
public void testGetAssociatoinDef() throws Exception
{
GetRequest req = new GetRequest(URL_SITES + "/cm_person/association/cm_avatar");
Response response = sendRequest(req, 200);
JSONObject result = new JSONObject(response.getContentAsString());
assertEquals(true, validateAssociationDef(result));
validateAssociationDef(result);
response = sendRequest(new GetRequest(URL_SITES +"/cm_personalbe/association/cms_avatarsara"), 404);
assertEquals(404,response.getStatus());
}
public void testGetAssociatoinDefs() throws Exception
{
GetRequest req = new GetRequest(URL_SITES + "/cm_person/associations");
//validate with associationfilter=>all 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; i<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("cm:avatar"))
flag = validateAssociationDef(result.getJSONObject(i));
if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults"))
validateChildAssociation(result.getJSONObject(i));
}
assertEquals(true, flag);
for(int i=0; i<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("wca:renderingenginetemplates"))
validateAssociation(result.getJSONObject(i));
}
//validate with associationfilter=>child 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; i<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults"))
validateChildAssociation(result.getJSONObject(i));
}
//validate with associationfilter=>general 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<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("wca:renderingenginetemplates"))
validateAssociation(result.getJSONObject(i));
}
//look for association wca_renderingenginetemplates in the class wca_form
arguments.clear();
arguments.put("af", "general");
arguments.put("nsp", "wca");
arguments.put("n", "renderingenginetemplates");
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:renderingenginetemplates"))
validateAssociation(result.getJSONObject(i));
}
//look for childassociation wca_formworkflowdefaults in the class wca_form
arguments.clear();
arguments.put("af", "child");
arguments.put("nsp", "wca");
arguments.put("n", "formworkflowdefaults");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(1,result.length());
for(int i=0; i<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults"))
validateChildAssociation(result.getJSONObject(i));
}
//look for details on wca_formworkflowdefaults in the class wca_form
arguments.clear();
arguments.put("nsp", "wca");
arguments.put("n", "formworkflowdefaults");
req.setArgs(arguments);
response = sendRequest(req, 200);
result = new JSONArray(response.getContentAsString());
assertEquals(1,result.length());
for(int i=0; i<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");
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<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("wca:formworkflowdefaults"))
validateChildAssociation(result.getJSONObject(i));
}
//ask for an invalid childassociation => 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<result.length(); i++)
{
if(result.getJSONObject(i).get("name").equals("wca:renderingenginetemplates"))
validateAssociation(result.getJSONObject(i));
}
//wrong data
response = sendRequest(new GetRequest(URL_SITES +"/cmsa_personalbe/associations"), 404);
assertEquals(404,response.getStatus());
//ask for a child-association which is actually not a valid child of classname - wca_form
arguments.clear();
arguments.put("af", "child");
arguments.put("nsp", "wca");
arguments.put("n", "renderingenginetemplates");
req.setArgs(arguments);
response = sendRequest(req, 404);
assertEquals(404,response.getStatus());
arguments.clear();
arguments.put("af", "general");
arguments.put("nsp", "cm"); // invalid namespaceprefix => 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

View File

@@ -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,11 +43,14 @@ 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<String, Object> 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<String, Object> model = new HashMap<String, Object>();
QName classqname = null;
boolean classnameGiven = (classname != null) && (classname.length() > 0);
Map<QName, AssociationDefinition> assocdef = new HashMap<QName, AssociationDefinition>();
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;
}
}

View File

@@ -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<String, Object> executeImpl(WebScriptRequest req, Status status)
protected Map<String, Object> 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<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
@@ -94,102 +95,104 @@ public class GetClassDetail extends DeclarativeWebScript
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
Map<String, Object> model = new HashMap<String, Object>();
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;
Collection <QName> qnames = null;
QName class_qname = null;
QName myModel = null;
//if classfilter is not given, then it defaults to all
if(classfilter == null)
{
classfilter = "all";
}
//validate classfilter
if(this.dictionaryhelper.isValidClassFilter(classfilter) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classfilter + " provided in the URL");
}
//validate the namespaceprefix and name parameters => 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;
isValidClassfilter = (cfGiven ) && (classfilter.equals(CLASS_FILTER_OPTION_TYPE1) || classfilter.equals(CLASS_FILTER_OPTION_TYPE2) || classfilter.equals(CLASS_FILTER_OPTION_TYPE3));
if(this.dictionaryhelper.isValidClassname(classname) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL");
}
class_qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname));
classdef.put(class_qname, this.dictionaryservice.getClass(class_qname));
propdef.put(class_qname, this.dictionaryservice.getClass(class_qname).getProperties().values());
assocdef.put(class_qname, this.dictionaryservice.getClass(class_qname).getAssociations().values());
}
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));
if (cfGiven && nspGiven && nameGiven)
// check the classfilter to pull out either all or tyype or aspects
if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1))
{
// 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);
qnames = this.dictionaryservice.getAspects(myModel);
qnames.addAll(this.dictionaryservice.getTypes(myModel));
}
else if (cfGiven && nspGiven && !nameGiven)
else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3))
{
isValidTwins = isValidClassfilter && this.dictionaryhelper.isValidPrefix(namespaceprefix);
qnames = this.dictionaryservice.getTypes(myModel);
}
else if (cfGiven && !nspGiven && !nameGiven)
else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2))
{
//since classfilter is given and namespaceprefix, name is not given , we can ignore the check for particular qname for classname
ignoreCheck = isValidClassfilter;
qnames = this.dictionaryservice.getAspects(myModel);
}
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;
}
if ((isValidTriplet) || (isValidTwins) || (ignoreCheck))
// if namespaceprefix is null, then check the classfilter to pull out either all or type or aspects
if(myModel == null)
{
Collection<QName> 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<maxIteration; i++)
if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1))
{
if (maxIteration==2)
qnames = this.dictionaryservice.getAllAspects();
qnames.addAll(this.dictionaryservice.getAllTypes());
}
else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3))
{
if(flipflag) qname = this.dictionaryservice.getAllAspects();
else qname = this.dictionaryservice.getAllTypes();
flipflag = false;
qnames = this.dictionaryservice.getAllTypes();
}
else if (classfilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2))
{
qnames = this.dictionaryservice.getAllAspects();
}
}
for(QName qnameObj: qname)
if(classdef.isEmpty() == true)
{
String url = this.dictionaryhelper.getNamespaceURIfromQname(qnameObj);
if(ignoreCheck || url.equals(this.dictionaryhelper.getPrefixesAndUrlsMap().get(namespaceprefix)))
for(QName qnameObj: qnames)
{
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;
}
else
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL");
}
}
}

View File

@@ -81,7 +81,7 @@ public class GetClassDetails extends DeclarativeWebScript
{
String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
Map<String, Object> model = new HashMap<String, Object>();
Map<String, Object> model = new HashMap<String, Object>(3);
QName qname = null;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();

View File

@@ -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<String, Object> 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<String, Object> model = new HashMap<String, Object>();
QName qname = null;
boolean classnameGiven = (classname != null) && (classname.length() > 0);
QName class_qname = null;
QName property_qname = null;
if(classnameGiven)
//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;
}
}