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:
Saravanan Sellathurai
2008-11-05 23:35:56 +00:00
parent 7c282a6eff
commit 2b78da7c38
12 changed files with 380 additions and 119 deletions

View File

@@ -33,9 +33,9 @@
"isTargetMany" : ${assocdefs.isTargetMany()?string} "isTargetMany" : ${assocdefs.isTargetMany()?string}
}, },
<#if assocdefs.isChild() == true> <#if assocdefs.isChild() == true>
"url" : "${url.serviceContext + "/api/classes/"+ url.templateArgs.classname + "/childassociation/"+ assocdefs.name.toPrefixString()?replace(":","_")}" "url" : "${"/api/classes/" + url.templateArgs.classname + "/childassociation/" + assocdefs.name.toPrefixString()?replace(":","_")}"
<#else> <#else>
"url" : "${url.serviceContext + "/api/classes/"+ url.templateArgs.classname + "/association/"+ assocdefs.name.toPrefixString()?replace(":","_")}" "url" : "${"/api/classes/" + url.templateArgs.classname + "/association/" + assocdefs.name.toPrefixString()?replace(":","_")}"
</#if> </#if>
} }
</#escape> </#escape>

View File

@@ -1,74 +1,90 @@
<#import "propertydefinition.lib.ftl" as propertyDefLib/> <#macro classDefJSON classdefs key>
<#import "assocdefinition.lib.ftl" as assocDefLib/> <#escape x as jsonUtils.encodeJSONString(x)>
<#macro classDefJSON classdefs> {
<#escape x as jsonUtils.encodeJSONString(x)> <#if classdefs.name?exists>
{ "name" : "${classdefs.name.toPrefixString()}",
<#if classdefs.name?exists>
"name" : "${classdefs.name.toPrefixString()}",
</#if> </#if>
<#if classdefs.isAspect() == true> <#if classdefs.isAspect() == true>
"isAspect" : true, "isAspect" : true,
<#else> <#else>
"isAspect" : false, "isAspect" : false,
</#if> </#if>
<#if classdefs.title?exists> <#if classdefs.title?exists>
"title" : "${classdefs.title}", "title" : "${classdefs.title}",
</#if> </#if>
<#if classdefs.description?exists> <#if classdefs.description?exists>
"description" : "${classdefs.description}", "description" : "${classdefs.description}",
</#if> </#if>
"properties" : "parent" : {
{ <#if classdefs.parentName?exists>
<#list propertydefs as propertydefs> "name" : "${classdefs.parentName.toPrefixString()}",
"${propertydefs.name.toPrefixString()}": "title" : "${classdefs.parentName.getLocalName()}",
{ "url" : "${"/api/classes/" + classdefs.parentName.toPrefixString()?replace(":","_")}"
<#if propertydefs.name?exists> </#if>
"name" : "${propertydefs.name.toPrefixString()}", },
</#if> "defaultAspects" : {
<#if propertydefs.title?exists> <#if classdefs.defaultAspects?exists>
"title" : "${propertydefs.title}", <#list classdefs.defaultAspects as aspectdefs>
</#if> "${aspectdefs.name.toPrefixString()}" : {
"url" : "${url.serviceContext + "/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/property/" + propertydefs.name.toPrefixString()?replace(":","_")}" "name" : "${aspectdefs.name}",
}<#if propertydefs_has_next>,</#if> <#if aspectdefs.title?exists>
</#list> "title" : "${aspectdefs.title}",
}, </#if>
"associations" : "url" : "${"/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/property/" + aspectdefs.name.toPrefixString()?replace(":","_")}"
{ }<#if aspectdefs_has_next>,</#if>
<#list assocdefs as assocdefs> </#list>
<#if assocdefs.isChild() == false> </#if>
"${assocdefs.name.toPrefixString()}": },
{ "properties" : {
<#if assocdefs.name?exists> <#list propertydefs[key] as propertydefs>
"name" : "${assocdefs.name.toPrefixString()}", "${propertydefs.name.toPrefixString()}": {
</#if> <#if propertydefs.name?exists>
<#if assocdefs.title?exists> "name" : "${propertydefs.name.toPrefixString()}",
"title" : "${assocdefs.title}", </#if>
</#if> <#if propertydefs.title?exists>
"url" : "${url.serviceContext + "/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/association/" + assocdefs.name.toPrefixString()?replace(":","_")}" "title" : "${propertydefs.title}",
} </#if>
</#if> "url" : "${"/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/property/" + propertydefs.name.toPrefixString()?replace(":","_")}"
<#if assocdefs_has_next>,</#if> }<#if propertydefs_has_next>,</#if>
</#list> </#list>
}, },
"childassociations" : "associations" : {
{ <#assign flag = false>
<#list assocdefs as assocdefs> <#list assocdefs[key] as assocdefs>
<#if assocdefs.isChild() == true> <#if (assocdefs.isChild()==false)&&(flag== true)><#assign flag = false>,</#if>
"${assocdefs.name.toPrefixString()}": <#if assocdefs.isChild() == false>
{ <#assign flag=true>
<#if assocdefs.name?exists> "${assocdefs.name.toPrefixString()}": {
"name" : "${assocdefs.name.toPrefixString()}", <#if assocdefs.name?exists>
</#if> "name" : "${assocdefs.name.toPrefixString()}",
<#if assocdefs.title?exists> </#if>
"title" : "${assocdefs.title}", <#if assocdefs.title?exists>
</#if> "title" : "${assocdefs.title}",
"url" : "${url.serviceContext + "/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/childassociation/" + assocdefs.name.toPrefixString()?replace(":","_")}" </#if>
} "url" : "${"/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/association/" + assocdefs.name.toPrefixString()?replace(":","_")}"
</#if> }
<#if assocdefs_has_next>,</#if> </#if>
</#list> </#list>
}, },
"url" : "${url.serviceContext + "/api/classes/" + classdefs.name.toPrefixString()?replace(":","_")}" "childassociations" : {
<#assign flag = false>
<#list assocdefs[key] as assocdefs>
<#if (assocdefs.isChild()==true)&&(flag== true)><#assign flag = false>,</#if>
<#if assocdefs.isChild() == true>
<#assign flag=true>
"${assocdefs.name.toPrefixString()}": {
<#if assocdefs.name?exists>
"name" : "${assocdefs.name.toPrefixString()}",
</#if>
<#if assocdefs.title?exists>
"title" : "${assocdefs.title}",
</#if>
"url" : "${"/api/classes/" + classdefs.name.toPrefixString()?replace(":","_") + "/childassociation/" + assocdefs.name.toPrefixString()?replace(":","_")}"
}
</#if>
</#list>
},
"url" : "${"/api/classes/" + classdefs.name.toPrefixString()?replace(":","_")}"
} }
</#escape> </#escape>
</#macro> </#macro>

View File

@@ -1,4 +1,7 @@
<#import "definitions.lib.ftl" as classDefLib/> <#import "classdetails.lib.ftl" as classdetailsDefLib/>
[
<@classDefLib.classDefJSON classdefs=classdefs/> <#list classdefs as classdefs>
<@classdetailsDefLib.classDefJSON classdefs=classdefs key = classdefs_index/>
<#if classdefs_has_next>,</#if>
</#list>
]

View File

@@ -1,4 +1,5 @@
<#import "classdetails.lib.ftl" as classdetailsDefLib/> <#import "classdetails.lib.ftl" as classdetailsDefLib/>
<#list classdefs as classdefs>
<@classdetailsDefLib.classDefJSON classdefs=classdefs/> <@classdetailsDefLib.classDefJSON classdefs=classdefs key = classdefs_index/>
<#if classdefs_has_next>,</#if>
</#list>

View File

@@ -16,23 +16,24 @@
"defaultValues" : "", "defaultValues" : "",
</#if> </#if>
<#if propertydefs.dataType?exists> <#if propertydefs.dataType?exists>
"dataType" : "${propertydefs.dataType.title}", "dataType" : "${propertydefs.dataType.name.toPrefixString()}",
</#if> </#if>
"multiValued" : "${propertydefs.multiValued?string}", "multiValued" : ${propertydefs.multiValued?string},
"mandatory" : "${propertydefs.mandatory?string}", "mandatory" : ${propertydefs.mandatory?string},
"enforced" : "${propertydefs.mandatoryEnforced?string}", "enforced" : ${propertydefs.mandatoryEnforced?string},
"protected" : "${propertydefs.protected?string}", "protected" : ${propertydefs.protected?string},
"indexed" : "${propertydefs.indexed?string}", "indexed" : ${propertydefs.indexed?string},
"indexedAtomically" : "${propertydefs.indexedAtomically?string}", "indexedAtomically" : ${propertydefs.indexedAtomically?string},
"constraints" : "constraints" :
[ [
<#--
<#if propertydefs.constraints?exists> <#if propertydefs.constraints?exists>
<#list propertydefs.constraints as constraintdefs> <#list propertydefs.constraints as constraintdefs>
"name" : "${constraintdefs.name}" "name" : "${constraintdefs.name}"
</#list> </#list>
</#if> </#if>-->
], ],
"url" : "${url.serviceContext + "/api/classes/" + url.templateArgs.classname + "/property/" + propertydefs.name.toPrefixString()?replace(":","_")}" "url" : "${"/api/classes/" + url.templateArgs.classname + "/property/" + propertydefs.name.toPrefixString()?replace(":","_")}"
} }
</#escape> </#escape>
</#macro> </#macro>

View File

@@ -559,6 +559,11 @@
<property name="dictionaryHelper" ref="dictionaryWebScriptHelper"/> <property name="dictionaryHelper" ref="dictionaryWebScriptHelper"/>
</bean> </bean>
<!-- GET CLASS DETAIL - GIVEN A NAMESPACEPREFEIX , CLASSFILTER, NAME -->
<bean id="webscript.org.alfresco.repository.dictionary.getclassdetail.get" class="org.alfresco.repo.web.scripts.dictionary.GetClassDetail" parent="webscript">
<property name="dictionaryService" ref="DictionaryService"/>
<property name="dictionaryHelper" ref="dictionaryWebScriptHelper"/>
</bean>
<!-- GET PROPERTY DEFINITION --> <!-- GET PROPERTY DEFINITION -->
<bean id="webscript.org.alfresco.repository.dictionary.getproperty.get" class="org.alfresco.repo.web.scripts.dictionary.GetPropertyDef" parent="webscript"> <bean id="webscript.org.alfresco.repository.dictionary.getproperty.get" class="org.alfresco.repo.web.scripts.dictionary.GetPropertyDef" parent="webscript">
@@ -596,10 +601,10 @@
<property name="dictionaryHelper" ref="dictionaryWebScriptHelper"/> <property name="dictionaryHelper" ref="dictionaryWebScriptHelper"/>
</bean> </bean>
<!-- Dictionary Service Web Script Helper Class --> <!-- Dictionary Service Web Script Helper Class -->
<bean id="dictionaryWebScriptHelper" class="org.alfresco.repo.web.scripts.dictionary.DictionaryHelper" init-method="init"> <bean id="dictionaryWebScriptHelper" class="org.alfresco.repo.web.scripts.dictionary.DictionaryHelper" init-method="init">
<property name="namespaceService" ref="NamespaceService"/> <property name="namespaceService" ref="NamespaceService"/>
<property name="dictionaryService" ref="DictionaryService"/>
</bean> </bean>

View File

@@ -24,7 +24,9 @@
*/ */
package org.alfresco.repo.web.scripts.dictionary; 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.NamespaceService;
import org.alfresco.service.namespace.QName;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -41,6 +43,7 @@ public class DictionaryHelper
private Map<String, String> prefixesAndUrlsMap; private Map<String, String> prefixesAndUrlsMap;
private Map<String, String> urlsAndPrefixesMap; private Map<String, String> urlsAndPrefixesMap;
private Collection<String> prefixes; private Collection<String> prefixes;
private DictionaryService dictionaryservice;
/** /**
* Set the namespaceService property. * Set the namespaceService property.
@@ -52,6 +55,16 @@ public class DictionaryHelper
this.namespaceservice = namespaceservice; 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. * 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 * @param className the class name as cm_person
@@ -83,13 +101,26 @@ public class DictionaryHelper
return result; 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 * checks whether the classname (eg.cm_author) is a valid one
*/ */
public boolean isValidClassname(String classname) public boolean isValidClassname(String classname)
{ {
boolean result = false; 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; return result;
} }
@@ -137,7 +168,7 @@ public class DictionaryHelper
/* /*
* returns a string map or prefixes and urls - with prefix as the key * 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; return prefixesAndUrlsMap;
} }
@@ -145,7 +176,7 @@ public class DictionaryHelper
/* /*
* returns a string map of urls and prefixes - with url as the key * 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; return urlsAndPrefixesMap;
} }

View File

@@ -30,6 +30,7 @@ import org.alfresco.web.scripts.TestWebScriptServer.Response;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONArray;
/* /*
* Unit Test for Dictionaryervice * Unit Test for Dictionaryervice
@@ -60,13 +61,13 @@ public class DictionaryServiceTest extends BaseWebScriptTest
assertEquals("cm:created", result.get("name")); assertEquals("cm:created", result.get("name"));
assertEquals("Created Date", result.get("title")); assertEquals("Created Date", result.get("title"));
assertEquals("Created Date", result.get("description")); assertEquals("Created Date", result.get("description"));
assertEquals("Date and Time", result.get("dataType")); assertEquals("d:datetime", result.get("dataType"));
assertEquals("false", result.get("multiValued")); assertEquals(false, result.get("multiValued"));
assertEquals("true", result.get("mandatory")); assertEquals(true, result.get("mandatory"));
assertEquals("true", result.get("enforced")); assertEquals(true, result.get("enforced"));
assertEquals("true", result.get("protected")); assertEquals(true, result.get("protected"));
assertEquals("true", result.get("indexed")); assertEquals(true, result.get("indexed"));
assertEquals("true", result.get("indexedAtomically")); assertEquals(true, result.get("indexedAtomically"));
response = sendRequest(new GetRequest("/api/classes/cm_hi/property/cm_welcome"), 404); response = sendRequest(new GetRequest("/api/classes/cm_hi/property/cm_welcome"), 404);
assertEquals(404,response.getStatus()); assertEquals(404,response.getStatus());
@@ -91,6 +92,145 @@ public class DictionaryServiceTest extends BaseWebScriptTest
assertEquals(404,response.getStatus()); 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 //TODO individual check of all elements
public void testGetAssociatoinDef() throws Exception public void testGetAssociatoinDef() throws Exception
{ {

View File

@@ -31,10 +31,13 @@ import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.ClassDefinition; 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.HashMap;
import java.util.Map; import java.util.Map;
/* /**
* Webscript to get the Classdefinitions using classfilter , namespaceprefix and name * Webscript to get the Classdefinitions using classfilter , namespaceprefix and name
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
@@ -42,13 +45,17 @@ import java.util.Map;
public class GetClassDetail extends DeclarativeWebScript public class GetClassDetail extends DeclarativeWebScript
{ {
private DictionaryService dictionaryservice; private DictionaryService dictionaryservice;
private ClassDefinition classdefinition;
private DictionaryHelper dictionaryhelper; private DictionaryHelper dictionaryhelper;
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs"; private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
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_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n"; 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 namespaceprefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME); String name = req.getParameter(REQ_URL_TEMPL_VAR_NAME);
String classname = null; 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>(); Map<String, Object> model = new HashMap<String, Object>();
QName qname = null;
boolean cfGiven = (classfilter != null) && (classfilter.length() > 0); boolean cfGiven = (classfilter != null) && (classfilter.length() > 0);
boolean nspGiven = (namespaceprefix != null) && (namespaceprefix.length() > 0); boolean nspGiven = (namespaceprefix != null) && (namespaceprefix.length() > 0);
boolean nameGiven = (name != null) && (name.length() > 0); boolean nameGiven = (name != null) && (name.length() > 0);
boolean ignoreCheck , hasNothing ,isValidClassfilter ,isValidTriples, isValidTwins ,hasData = false;
if(cfGiven && nspGiven && nameGiven) classname = namespaceprefix + "_" + name;
{ isValidClassfilter = (cfGiven ) && (classfilter.equals(CLASS_FILTER_OPTION_TYPE1) || classfilter.equals(CLASS_FILTER_OPTION_TYPE2) || classfilter.equals(CLASS_FILTER_OPTION_TYPE3));
classname = namespaceprefix + "_" + name; hasNothing = (!cfGiven && !nspGiven && !nameGiven);
qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); ignoreCheck =(cfGiven && !nspGiven && !nameGiven) && isValidClassfilter;
} isValidTriples = (cfGiven && nspGiven && nameGiven) && this.dictionaryhelper.isValidPrefix(namespaceprefix) && isValidClassfilter && this.dictionaryhelper.isValidClassname(classname);
classdefinition = this.dictionaryservice.getClass(qname); 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; return model;
} }
else else

View File

@@ -29,12 +29,16 @@ import org.alfresco.web.scripts.Status;
import org.alfresco.web.scripts.WebScriptException; import org.alfresco.web.scripts.WebScriptException;
import org.alfresco.web.scripts.WebScriptRequest; import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.service.namespace.QName; 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.DictionaryService;
import org.alfresco.service.cmr.dictionary.ClassDefinition; 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.HashMap;
import java.util.Map; import java.util.Map;
/* /**
* Webscript to get the Classdefinitions for a classname eg. =>cm_author * Webscript to get the Classdefinitions for a classname eg. =>cm_author
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
@@ -44,7 +48,6 @@ public class GetClassDetails extends DeclarativeWebScript
private DictionaryService dictionaryservice; private DictionaryService dictionaryservice;
private DictionaryHelper dictionaryhelper; private DictionaryHelper dictionaryhelper;
private ClassDefinition classdefinition;
private static final String MODEL_PROP_KEY_CLASS_DETAILS = "classdefs"; private static final String MODEL_PROP_KEY_CLASS_DETAILS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
@@ -80,19 +83,26 @@ public class GetClassDetails extends DeclarativeWebScript
Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> model = new HashMap<String, Object>();
QName qname = null; 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 classnameGiven = (classname != null) && (classname.length() > 0);
boolean hasData = false;
if(classnameGiven) if(classnameGiven && this.dictionaryhelper.isValidClassname(classname))
{ {
qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(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(hasData)
if(this.classdefinition != null)
{ {
model.put(MODEL_PROP_KEY_CLASS_DETAILS, this.classdefinition); model.put(MODEL_PROP_KEY_CLASS_DETAILS, classdef.values());
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.classdefinition.getProperties().values()); model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.classdefinition.getAssociations().values()); model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
return model; return model;
} }
else else

View File

@@ -34,8 +34,9 @@ import org.alfresco.service.cmr.dictionary.ClassDefinition;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/* /**
* Webscript to get the Propertydefinition for a given classname and propname * Webscript to get the Propertydefinition for a given classname and propname
*
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */

View File

@@ -34,8 +34,10 @@ import org.alfresco.service.cmr.dictionary.ClassDefinition;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/* /**
*
* Webscript to get the Propertydefinitions for a given classname eg. =>cm_person * Webscript to get the Propertydefinitions for a given classname eg. =>cm_person
*
* @author Saravanan Sellathurai * @author Saravanan Sellathurai
*/ */
@@ -85,6 +87,7 @@ public class GetPropertyDefs extends DeclarativeWebScript
qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname));
} }
classdefinition = this.dictionaryservice.getClass(qname); classdefinition = this.dictionaryservice.getClass(qname);
if(this.classdefinition != null) if(this.classdefinition != null)
{ {
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.classdefinition.getProperties().values()); model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.classdefinition.getProperties().values());