mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Updates GetClassDetail using classfilter and namespaceprefix for the webscript
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11712 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,7 +24,9 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.dictionary;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -41,6 +43,7 @@ public class DictionaryHelper
|
||||
private Map<String, String> prefixesAndUrlsMap;
|
||||
private Map<String, String> urlsAndPrefixesMap;
|
||||
private Collection<String> prefixes;
|
||||
private DictionaryService dictionaryservice;
|
||||
|
||||
/**
|
||||
* Set the namespaceService property.
|
||||
@@ -52,6 +55,16 @@ public class DictionaryHelper
|
||||
this.namespaceservice = namespaceservice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the dictionaryService property.
|
||||
*
|
||||
* @param dictionaryService The dictionary service instance to set
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryservice = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method.
|
||||
*/
|
||||
@@ -68,6 +81,11 @@ public class DictionaryHelper
|
||||
}
|
||||
}
|
||||
|
||||
public String getNamespaceURIfromQname(QName qname){
|
||||
return qname.getNamespaceURI();
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param className the class name as cm_person
|
||||
@@ -83,13 +101,26 @@ public class DictionaryHelper
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param className the class name as cm_person
|
||||
* @return String the full name in the following format {namespaceuri}shorname
|
||||
*/
|
||||
public String getNamespaceURIfromPrefix(String prefix)
|
||||
{
|
||||
String result = null;
|
||||
if(this.isValidPrefix(prefix)) result = this.prefixesAndUrlsMap.get(prefix);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* checks whether the classname (eg.cm_author) is a valid one
|
||||
*/
|
||||
public boolean isValidClassname(String classname)
|
||||
{
|
||||
boolean result = false;
|
||||
if(this.isValidPrefix(this.getPrefix(classname))) result = true;
|
||||
QName qname = QName.createQName(this.getFullNamespaceURI(classname));
|
||||
if(this.isValidPrefix(this.getPrefix(classname))&& this.dictionaryservice.getClass(qname)!=null) result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -137,7 +168,7 @@ public class DictionaryHelper
|
||||
/*
|
||||
* returns a string map or prefixes and urls - with prefix as the key
|
||||
*/
|
||||
public Map<String, String> prefixesAndUrlsMap()
|
||||
public Map<String, String> getPrefixesAndUrlsMap()
|
||||
{
|
||||
return prefixesAndUrlsMap;
|
||||
}
|
||||
@@ -145,7 +176,7 @@ public class DictionaryHelper
|
||||
/*
|
||||
* returns a string map of urls and prefixes - with url as the key
|
||||
*/
|
||||
public Map<String, String> urlsAndPrefixesMap()
|
||||
public Map<String, String> getUrlsAndPrefixesMap()
|
||||
{
|
||||
return urlsAndPrefixesMap;
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ import org.alfresco.web.scripts.TestWebScriptServer.Response;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONArray;
|
||||
|
||||
/*
|
||||
* Unit Test for Dictionaryervice
|
||||
@@ -60,13 +61,13 @@ public class DictionaryServiceTest extends BaseWebScriptTest
|
||||
assertEquals("cm:created", result.get("name"));
|
||||
assertEquals("Created Date", result.get("title"));
|
||||
assertEquals("Created Date", result.get("description"));
|
||||
assertEquals("Date and Time", result.get("dataType"));
|
||||
assertEquals("false", result.get("multiValued"));
|
||||
assertEquals("true", result.get("mandatory"));
|
||||
assertEquals("true", result.get("enforced"));
|
||||
assertEquals("true", result.get("protected"));
|
||||
assertEquals("true", result.get("indexed"));
|
||||
assertEquals("true", result.get("indexedAtomically"));
|
||||
assertEquals("d:datetime", result.get("dataType"));
|
||||
assertEquals(false, result.get("multiValued"));
|
||||
assertEquals(true, result.get("mandatory"));
|
||||
assertEquals(true, result.get("enforced"));
|
||||
assertEquals(true, result.get("protected"));
|
||||
assertEquals(true, result.get("indexed"));
|
||||
assertEquals(true, result.get("indexedAtomically"));
|
||||
response = sendRequest(new GetRequest("/api/classes/cm_hi/property/cm_welcome"), 404);
|
||||
assertEquals(404,response.getStatus());
|
||||
|
||||
@@ -91,6 +92,145 @@ public class DictionaryServiceTest extends BaseWebScriptTest
|
||||
assertEquals(404,response.getStatus());
|
||||
}
|
||||
|
||||
//TODO individual check of all elements
|
||||
|
||||
public void testGetClassDetails() throws Exception
|
||||
{
|
||||
GetRequest req = new GetRequest(URL_SITES);
|
||||
Map< String, String > arguments = new HashMap< String, String >();
|
||||
arguments.put("cf", "aspect");
|
||||
arguments.put("nsp", "cm");
|
||||
arguments.put("n", "dublincore");
|
||||
req.setArgs(arguments);
|
||||
Response response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//check for all aspects under cm without option=>name
|
||||
arguments.clear();
|
||||
arguments.put("cf", "type");
|
||||
arguments.put("nsp", "wca");
|
||||
arguments.put("n", "rendition");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//check for all aspects under cm without option=>name
|
||||
arguments.clear();
|
||||
arguments.put("cf", "type");
|
||||
arguments.put("nsp", "wca");
|
||||
arguments.put("n", "rendition");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//check for all aspects under cm without option=>name
|
||||
arguments.clear();
|
||||
arguments.put("cf", "aspect");
|
||||
arguments.put("nsp", "cm");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//check for all types under cm without option=>name
|
||||
arguments.clear();
|
||||
arguments.put("cf", "type");
|
||||
arguments.put("nsp", "cm");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//check for all data under cm without option=>name
|
||||
arguments.clear();
|
||||
arguments.put("cf", "all");
|
||||
arguments.put("nsp", "cm");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//check for all dictionary data without option=>name and option=>namespaceprefix
|
||||
arguments.clear();
|
||||
arguments.put("cf", "all");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//check for all aspect dictionary data without option=>name and option=>namespaceprefix
|
||||
arguments.clear();
|
||||
arguments.put("cf", "aspect");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
//check for all types dictionary data without option=>name and option=>namespaceprefix
|
||||
arguments.clear();
|
||||
arguments.put("cf", "type");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
|
||||
|
||||
// Test with wrong data
|
||||
//check for all aspects under cm without option=>name
|
||||
arguments.clear();
|
||||
arguments.put("cf", "aspects");
|
||||
arguments.put("nsp", "cm");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 404);
|
||||
assertEquals(404,response.getStatus());
|
||||
|
||||
//check for all types under cm without option=>name
|
||||
arguments.clear();
|
||||
arguments.put("cf", "types");
|
||||
arguments.put("nsp", "cmd");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 404);
|
||||
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
|
||||
arguments.clear();
|
||||
arguments.put("cf", "allsara");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 404);
|
||||
assertEquals(404,response.getStatus());
|
||||
|
||||
//check for all aspect dictionary data without option=>name and option=>namespaceprefix
|
||||
arguments.clear();
|
||||
arguments.put("cf", "aspectb");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 404);
|
||||
assertEquals(404,response.getStatus());
|
||||
|
||||
//check for all types dictionary data without option=>name and option=>namespaceprefix
|
||||
arguments.clear();
|
||||
arguments.put("cf", "typesa");
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 404);
|
||||
assertEquals(404,response.getStatus());
|
||||
|
||||
//check for aspects under cm with an invalid name dublincoresara
|
||||
arguments.clear();
|
||||
arguments.put("cf", "aspectss");
|
||||
arguments.put("nsp", "cmsd");
|
||||
arguments.put("n", "dublincoresara");
|
||||
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
|
||||
arguments.clear();
|
||||
req.setArgs(arguments);
|
||||
response = sendRequest(req, 200);
|
||||
assertEquals(200,response.getStatus());
|
||||
}
|
||||
|
||||
//TODO individual check of all elements
|
||||
public void testGetAssociatoinDef() throws Exception
|
||||
{
|
||||
|
@@ -31,10 +31,13 @@ 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 Classdefinitions using classfilter , namespaceprefix and name
|
||||
* @author Saravanan Sellathurai
|
||||
*/
|
||||
@@ -42,13 +45,17 @@ import java.util.Map;
|
||||
public class GetClassDetail extends DeclarativeWebScript
|
||||
{
|
||||
private DictionaryService dictionaryservice;
|
||||
private ClassDefinition classdefinition;
|
||||
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_VAR_CLASS_FILTER = "cf";
|
||||
|
||||
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 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";
|
||||
|
||||
@@ -81,23 +88,66 @@ public class GetClassDetail extends DeclarativeWebScript
|
||||
String namespaceprefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
|
||||
String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
|
||||
String classname = null;
|
||||
|
||||
|
||||
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 qname = null;
|
||||
|
||||
boolean cfGiven = (classfilter != null) && (classfilter.length() > 0);
|
||||
boolean nspGiven = (namespaceprefix != null) && (namespaceprefix.length() > 0);
|
||||
boolean nameGiven = (name != null) && (name.length() > 0);
|
||||
boolean ignoreCheck , hasNothing ,isValidClassfilter ,isValidTriples, isValidTwins ,hasData = false;
|
||||
|
||||
if(cfGiven && nspGiven && nameGiven)
|
||||
{
|
||||
classname = namespaceprefix + "_" + name;
|
||||
qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname));
|
||||
}
|
||||
classdefinition = this.dictionaryservice.getClass(qname);
|
||||
classname = namespaceprefix + "_" + name;
|
||||
isValidClassfilter = (cfGiven ) && (classfilter.equals(CLASS_FILTER_OPTION_TYPE1) || classfilter.equals(CLASS_FILTER_OPTION_TYPE2) || classfilter.equals(CLASS_FILTER_OPTION_TYPE3));
|
||||
hasNothing = (!cfGiven && !nspGiven && !nameGiven);
|
||||
ignoreCheck =(cfGiven && !nspGiven && !nameGiven) && isValidClassfilter;
|
||||
isValidTriples = (cfGiven && nspGiven && nameGiven) && this.dictionaryhelper.isValidPrefix(namespaceprefix) && isValidClassfilter && this.dictionaryhelper.isValidClassname(classname);
|
||||
isValidTwins = (cfGiven && nspGiven)&& isValidClassfilter && this.dictionaryhelper.isValidPrefix(namespaceprefix);
|
||||
|
||||
if(this.classdefinition != null)
|
||||
if ((isValidTriples) || (isValidTwins) || (ignoreCheck) || (hasNothing))
|
||||
{
|
||||
Collection<QName> qname = null;
|
||||
int maxIteration = 1;
|
||||
if (hasNothing || 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 flag = true;
|
||||
|
||||
for (int i=0; i<maxIteration; i++)
|
||||
{
|
||||
if (maxIteration==2)
|
||||
{
|
||||
if(flag) qname = this.dictionaryservice.getAllAspects();
|
||||
else qname = this.dictionaryservice.getAllTypes();
|
||||
flag = false;
|
||||
}
|
||||
|
||||
for(QName qnameObj: qname)
|
||||
{
|
||||
String url = this.dictionaryhelper.getNamespaceURIfromQname(qnameObj);
|
||||
if(hasNothing || ignoreCheck || url.equals(this.dictionaryhelper.getPrefixesAndUrlsMap().get(namespaceprefix)))
|
||||
{
|
||||
if(isValidTriples) 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 (isValidTriples) break;
|
||||
}
|
||||
}// end of for loop
|
||||
}// end of for loop
|
||||
|
||||
hasData = true;
|
||||
|
||||
} // end of else block
|
||||
|
||||
if(hasData)
|
||||
{
|
||||
model.put(MODEL_PROP_KEY_CLASS_DEFS, this.classdefinition);
|
||||
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
|
||||
|
@@ -29,12 +29,16 @@ 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.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.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Webscript to get the Classdefinitions for a classname eg. =>cm_author
|
||||
* @author Saravanan Sellathurai
|
||||
*/
|
||||
@@ -44,7 +48,6 @@ public class GetClassDetails extends DeclarativeWebScript
|
||||
|
||||
private DictionaryService dictionaryservice;
|
||||
private DictionaryHelper dictionaryhelper;
|
||||
private ClassDefinition classdefinition;
|
||||
|
||||
private static final String MODEL_PROP_KEY_CLASS_DETAILS = "classdefs";
|
||||
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
|
||||
@@ -80,19 +83,26 @@ public class GetClassDetails extends DeclarativeWebScript
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>();
|
||||
QName qname = null;
|
||||
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>>();
|
||||
boolean classnameGiven = (classname != null) && (classname.length() > 0);
|
||||
boolean hasData = false;
|
||||
|
||||
if(classnameGiven)
|
||||
if(classnameGiven && this.dictionaryhelper.isValidClassname(classname))
|
||||
{
|
||||
qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname));
|
||||
hasData = true;
|
||||
classdef.put(qname, this.dictionaryservice.getClass(qname));
|
||||
propdef.put(qname, this.dictionaryservice.getClass(qname).getProperties().values());
|
||||
assocdef.put(qname, this.dictionaryservice.getClass(qname).getAssociations().values());
|
||||
}
|
||||
|
||||
classdefinition = this.dictionaryservice.getClass(qname);
|
||||
if(this.classdefinition != null)
|
||||
if(hasData)
|
||||
{
|
||||
model.put(MODEL_PROP_KEY_CLASS_DETAILS, this.classdefinition);
|
||||
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.classdefinition.getProperties().values());
|
||||
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.classdefinition.getAssociations().values());
|
||||
model.put(MODEL_PROP_KEY_CLASS_DETAILS, classdef.values());
|
||||
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
|
||||
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
|
||||
return model;
|
||||
}
|
||||
else
|
||||
|
@@ -34,8 +34,9 @@ import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Webscript to get the Propertydefinition for a given classname and propname
|
||||
*
|
||||
* @author Saravanan Sellathurai
|
||||
*/
|
||||
|
||||
|
@@ -34,8 +34,10 @@ import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/*
|
||||
/**
|
||||
*
|
||||
* Webscript to get the Propertydefinitions for a given classname eg. =>cm_person
|
||||
*
|
||||
* @author Saravanan Sellathurai
|
||||
*/
|
||||
|
||||
@@ -85,6 +87,7 @@ public class GetPropertyDefs extends DeclarativeWebScript
|
||||
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());
|
||||
|
Reference in New Issue
Block a user