From 236db9d1575ed7026bf311cfbbd7662e6cd0224f Mon Sep 17 00:00:00 2001 From: Saravanan Sellathurai Date: Mon, 3 Nov 2008 16:21:55 +0000 Subject: [PATCH] First iteration of Dictionaryservice REST API - readonly webscripts for dictionaryservice git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@11656 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../dictionary/assocdefinition.lib.ftl | 38 +++++ .../dictionary/classdetails.lib.ftl | 46 ++++++ .../repository/dictionary/definitions.lib.ftl | 18 +++ .../dictionary/getassociationdef.get.desc.xml | 8 + .../dictionary/getassociationdef.get.json.ftl | 3 + .../getassociationdefs.get.desc.xml | 8 + .../getassociationdefs.get.json.ftl | 9 ++ .../dictionary/getchildassoc.get.desc.xml | 8 + .../dictionary/getchildassoc.get.json.ftl | 3 + .../dictionary/getchildassocs.get.desc.xml | 8 + .../dictionary/getchildassocs.get.json.ftl | 9 ++ .../dictionary/getclassdetail.get.desc.xml | 8 + .../dictionary/getclassdetail.get.json.ftl | 4 + .../dictionary/getclassdetails.get.desc.xml | 8 + .../dictionary/getclassdetails.get.json.ftl | 4 + .../dictionary/getproperties.get.desc.xml | 8 + .../dictionary/getproperties.get.json.ftl | 7 + .../dictionary/getproperty.get.desc.xml | 8 + .../dictionary/getproperty.get.json.ftl | 3 + .../dictionary/propertydefinition.lib.ftl | 38 +++++ .../scripts/dictionary/DictionaryHelper.java | 152 ++++++++++++++++++ .../dictionary/DictionaryServiceTest.java | 139 ++++++++++++++++ .../scripts/dictionary/GetAssociationDef.java | 103 ++++++++++++ .../dictionary/GetAssociationDefs.java | 98 +++++++++++ .../dictionary/GetChildAssociationDef.java | 103 ++++++++++++ .../dictionary/GetChildAssociationDefs.java | 90 +++++++++++ .../scripts/dictionary/GetClassDetail.java | 109 +++++++++++++ .../scripts/dictionary/GetClassDetails.java | 104 ++++++++++++ .../scripts/dictionary/GetPropertyDef.java | 103 ++++++++++++ .../scripts/dictionary/GetPropertyDefs.java | 99 ++++++++++++ 30 files changed, 1346 insertions(+) create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/assocdefinition.lib.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/classdetails.lib.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/definitions.lib.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.json.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.json.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassoc.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassoc.get.json.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassocs.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassocs.get.json.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetail.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetail.get.json.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetails.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetails.get.json.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.json.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.desc.xml create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.json.ftl create mode 100644 config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/propertydefinition.lib.ftl create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDef.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/GetChildAssociationDef.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/GetChildAssociationDefs.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDef.java create mode 100644 source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/assocdefinition.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/assocdefinition.lib.ftl new file mode 100644 index 0000000000..5160c92737 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/assocdefinition.lib.ftl @@ -0,0 +1,38 @@ +<#macro assocDefJSON assocdefs> +<#escape x as jsonUtils.encodeJSONString(x)> + { + <#if assocdefs.name?exists> + "name" : "${assocdefs.name}", + + <#if assocdefs.title?exists> + "title" : "${assocdefs.title}", + + <#if assocdefs.description?exists> + "description" : "${assocdefs.description}", + + <#if assocdefs.isChild() == true> + "isChild" : true, + <#else> + "isChild" : false, + + <#if assocdefs.isProtected() == true> + "protected" : true, + <#else> + "protected" : false, + + "source" : + { + "class" : "${assocdefs.getSourceClass().name}", + "isSourceMandatory" : ${assocdefs.isSourceMandatory()?string}, + "isSourceMany" : ${assocdefs.isSourceMany()?string} + }, + "target" : + { + "class" : "${assocdefs.getTargetClass()}", + "isTargetMandatory" : ${assocdefs.isTargetMandatory()?string}, + "isTargetMany" : ${assocdefs.isTargetMany()?string} + }, + "url" : "${url.serviceContext + "/api/classes" + assocdefs.name}" + } + + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/classdetails.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/classdetails.lib.ftl new file mode 100644 index 0000000000..405fe912e1 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/classdetails.lib.ftl @@ -0,0 +1,46 @@ +<#import "propertydefinition.lib.ftl" as propertyDefLib/> +<#import "assocdefinition.lib.ftl" as assocDefLib/> +<#macro classDefJSON classdefs> + <#escape x as jsonUtils.encodeJSONString(x)> + { + <#if classdefs.name?exists> + "name" : "${classdefs.name}", + + <#if classdefs.isAspect() == true> + "isAspect" : true, + <#else> + "isAspect" : false, + + <#if classdefs.title?exists> + "title" : "${classdefs.title}", + + <#if classdefs.description?exists> + "description" : "${classdefs.description}", + + "properties" : + [ + <#list propertydefs as propertydefs> + <@propertyDefLib.propertyDefJSON propertydefs=propertydefs/> + <#if propertydefs_has_next>, + + ], + "associations" : + [ + <#list assocdefs as assocdefs> + <@assocDefLib.assocDefJSON assocdefs=assocdefs/> + <#if assocdefs_has_next>, + + ], + "childassociations" : + [ + <#list assocdefs as assocdefs> + <#if assocdefs.isChild() == true> + <@assocDefLib.assocDefJSON assocdefs=assocdefs/> + <#if assocdefs_has_next>, + + + ], + "url" : "${url.serviceContext + "/api/classes" + classdefs.name}" + } + + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/definitions.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/definitions.lib.ftl new file mode 100644 index 0000000000..b4e563fec7 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/definitions.lib.ftl @@ -0,0 +1,18 @@ +<#macro classDefJSON classdefs> + <#escape x as jsonUtils.encodeJSONString(x)> + { + <#if classdefs.name?exists> + "name" : "${classdefs.name}", + + <#if classdefs.title?exists> + "title" : "${classdefs.title}", + + <#if classdefs.description?exists> + "description" : "${classdefs.description}", + + <#if classdefs.isAspect?exists> + "isAspect" : "it does exist" + + } + + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.desc.xml new file mode 100644 index 0000000000..675ba4877c --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.desc.xml @@ -0,0 +1,8 @@ + + Get Association Definitions + Get the collection of association definitions + /api/classes/{classname}/association/{assocname} + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.json.ftl new file mode 100644 index 0000000000..c66856a5fb --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdef.get.json.ftl @@ -0,0 +1,3 @@ +<#import "assocdefinition.lib.ftl" as assocDefLib/> + +<@assocDefLib.assocDefJSON assocdefs=assocdefs/> \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.desc.xml new file mode 100644 index 0000000000..74f0b6db09 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.desc.xml @@ -0,0 +1,8 @@ + + Get Association Definitions + Get the collection of association definitions for a given classname + /api/classes/{classname}/associations + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.json.ftl new file mode 100644 index 0000000000..77cb1a0bba --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getassociationdefs.get.json.ftl @@ -0,0 +1,9 @@ +<#import "assocdefinition.lib.ftl" as assocDefLib/> +[ + <#list assocdefs as assocdefs> + <#if assocdefs.isChild() == false> + <@assocDefLib.assocDefJSON assocdefs=assocdefs/> + <#if assocdefs_has_next>, + + +] \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassoc.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassoc.get.desc.xml new file mode 100644 index 0000000000..ab54b5fd58 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassoc.get.desc.xml @@ -0,0 +1,8 @@ + + Get Child Association Definitions + Get the collection of child association definitions + /api/classes/{classname}/childassociation/{assocname} + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassoc.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassoc.get.json.ftl new file mode 100644 index 0000000000..c66856a5fb --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassoc.get.json.ftl @@ -0,0 +1,3 @@ +<#import "assocdefinition.lib.ftl" as assocDefLib/> + +<@assocDefLib.assocDefJSON assocdefs=assocdefs/> \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassocs.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassocs.get.desc.xml new file mode 100644 index 0000000000..53a3a11b18 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassocs.get.desc.xml @@ -0,0 +1,8 @@ + + Get Child Assocation Definitions + Get the collection of child association definitions for a given classname + /api/classes/{classname}/childassociations + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassocs.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassocs.get.json.ftl new file mode 100644 index 0000000000..ad4c012b03 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getchildassocs.get.json.ftl @@ -0,0 +1,9 @@ +<#import "assocdefinition.lib.ftl" as assocDefLib/> +[ + <#list assocdefs as assocdefs> + <#if assocdefs.isChild() == true> + <@assocDefLib.assocDefJSON assocdefs=assocdefs/> + <#if assocdefs_has_next>, + + +] \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetail.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetail.get.desc.xml new file mode 100644 index 0000000000..52345bb352 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetail.get.desc.xml @@ -0,0 +1,8 @@ + + Get Class Definitions + Get the collection of class definitions + /api/classes?cf={classFilter?}&nsp={namespacePrefix?}&n={name?} + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetail.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetail.get.json.ftl new file mode 100644 index 0000000000..88af28847a --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetail.get.json.ftl @@ -0,0 +1,4 @@ +<#import "definitions.lib.ftl" as classDefLib/> + +<@classDefLib.classDefJSON classdefs=classdefs/> + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetails.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetails.get.desc.xml new file mode 100644 index 0000000000..85bfb855d3 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetails.get.desc.xml @@ -0,0 +1,8 @@ + + Get Class Definitions + Get the collection of class definitions for a given classname + /api/classes/{className} + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetails.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetails.get.json.ftl new file mode 100644 index 0000000000..1ac2325ebd --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getclassdetails.get.json.ftl @@ -0,0 +1,4 @@ +<#import "classdetails.lib.ftl" as classdetailsDefLib/> + +<@classdetailsDefLib.classDefJSON classdefs=classdefs/> + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.desc.xml new file mode 100644 index 0000000000..28c0911fe7 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.desc.xml @@ -0,0 +1,8 @@ + + Get Property Definitions + Get the collection of property definitions + /api/classes/{classname}/properties + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.json.ftl new file mode 100644 index 0000000000..372c966a48 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperties.get.json.ftl @@ -0,0 +1,7 @@ +<#import "propertydefinition.lib.ftl" as propertyDefLib/> +[ +<#list propertydefs as propertydefs> + <@propertyDefLib.propertyDefJSON propertydefs=propertydefs/> + <#if propertydefs_has_next>, + +] \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.desc.xml new file mode 100644 index 0000000000..da09c369a8 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.desc.xml @@ -0,0 +1,8 @@ + + Get Property Definitions + Get the collection of property definitions for a given classname and property name + /api/classes/{classname}/property/{propname} + + user + required + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.json.ftl new file mode 100644 index 0000000000..0a1c659b86 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/getproperty.get.json.ftl @@ -0,0 +1,3 @@ +<#import "propertydefinition.lib.ftl" as propertyDefLib/> + +<@propertyDefLib.propertyDefJSON propertydefs=propertydefs/> \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/propertydefinition.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/propertydefinition.lib.ftl new file mode 100644 index 0000000000..6adc12e4f6 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/propertydefinition.lib.ftl @@ -0,0 +1,38 @@ +<#macro propertyDefJSON propertydefs> + <#escape x as jsonUtils.encodeJSONString(x)> + { + <#if propertydefs.name?exists> + "name" : "${propertydefs.name}", + + <#if propertydefs.title?exists> + "title" : "${propertydefs.title}", + + <#if propertydefs.description?exists> + "description" : "${propertydefs.description}", + + <#if propertydefs.defaultValues?exists> + "defaultValues" : "${propertydefs.defaultValues}", + <#else> + "defaultValues" : "", + + <#if propertydefs.dataType?exists> + "dataType" : "${propertydefs.dataType.title}", + + "multiValued" : "${propertydefs.multiValued?string}", + "mandatory" : "${propertydefs.mandatory?string}", + "enforced" : "${propertydefs.mandatoryEnforced?string}", + "protected" : "${propertydefs.protected?string}", + "indexed" : "${propertydefs.indexed?string}", + "indexedAtomically" : "${propertydefs.indexedAtomically?string}", + "constraints" : + [ + <#if propertydefs.constraints?exists> + <#list propertydefs.constraints as constraintdefs> + "name" : "${constraintdefs.name}" + + + ], + "url" : "${url.serviceContext + "/api/classes" + propertydefs.name}" + } + + diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java new file mode 100644 index 0000000000..a01a75af5b --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryHelper.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.service.namespace.NamespaceService; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/* + * Helper class for Dictionary Service webscripts + * @author Saravanan Sellathurai + */ + +public class DictionaryHelper +{ + private static final String NAME_DELIMITER = "_"; + private NamespaceService namespaceservice; + private Map prefixesAndUrlsMap; + private Map urlsAndPrefixesMap; + private Collection prefixes; + + /** + * Set the namespaceService property. + * + * @param namespaceService The namespace service instance to set + */ + public void setNamespaceService(NamespaceService namespaceservice) + { + this.namespaceservice = namespaceservice; + } + + /** + * Init method. + */ + public void init() + { + this.prefixes = this.namespaceservice.getPrefixes(); + this.prefixesAndUrlsMap = new HashMap(prefixes.size()); + this.urlsAndPrefixesMap = new HashMap(prefixes.size()); + for (String prefix : prefixes) + { + String url = this.namespaceservice.getNamespaceURI(prefix); + this.prefixesAndUrlsMap.put(prefix, url); + this.urlsAndPrefixesMap.put(url, prefix); + } + } + + /** + * + * @param className the class name as cm_person + * @return String the full name in the following format {namespaceuri}shorname + */ + public String getFullNamespaceURI(String classname) + { + String result = null; + String prefix = this.getPrefix(classname); + String url = this.prefixesAndUrlsMap.get(prefix); + String name = this.getShortName(classname); + result = "{" + url + "}"+ name; + 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; + return result; + } + + /* + * checks whether the prefix is a valid one + */ + public boolean isValidPrefix(String prefix) + { + boolean result = false; + if(this.prefixes.contains(prefix)) result = true; + return result; + } + + + /* + * returns the prefix from the classname of the format cm_person + * here cm represents the prefix + */ + public String getPrefix(String classname) + { + String prefix = null; + int index = classname.indexOf(NAME_DELIMITER); + if (index > 0) + { + prefix = classname.substring(0, index); + } + return prefix; + } + + /* + * returns the shortname from the classname of the format cm_person + * here person represents the shortname + */ + public String getShortName(String classname) + { + String shortname = null; + int index = classname.indexOf(NAME_DELIMITER); + if (index > 0) + { + shortname = classname.substring(index+1); + } + return shortname; + } + + /* + * returns a string map or prefixes and urls - with prefix as the key + */ + public Map prefixesAndUrlsMap() + { + return prefixesAndUrlsMap; + } + + /* + * returns a string map of urls and prefixes - with url as the key + */ + public Map urlsAndPrefixesMap() + { + return urlsAndPrefixesMap; + } +} diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java new file mode 100644 index 0000000000..9c28d4593f --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/DictionaryServiceTest.java @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.repo.web.scripts.BaseWebScriptTest; +import org.alfresco.web.scripts.TestWebScriptServer.GetRequest; +import org.alfresco.web.scripts.TestWebScriptServer.Response; +import java.util.HashMap; +import java.util.Map; +import org.json.JSONObject; + +/* + * Unit Test for Dictionaryervice + * @author Saravanan Sellathurai + */ + +public class DictionaryServiceTest extends BaseWebScriptTest +{ + private static final String URL_SITES = "/api/classes"; + + @Override + protected void setUp() throws Exception + { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + } + //TODO individual check of all elements + 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("{http://www.alfresco.org/model/content/1.0}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")); + response = sendRequest(new GetRequest("/api/classes/cm_hi/property/cm_welcome"), 404); + assertEquals(404,response.getStatus()); + + } + + //TODO individual check of all elements + public void testGetPropertyDefs() throws Exception + { + Response response = sendRequest(new GetRequest("/api/classes/cm_auditable/properties"), 200); + assertEquals(200,response.getStatus()); + response = sendRequest(new GetRequest("/api/classes/cm_welcome/properties"), 404); + assertEquals(404,response.getStatus()); + } + + //TODO individual check of all elements + public void testGetClassDetail() throws Exception + { + GetRequest req = new GetRequest(URL_SITES + "/cm_auditable"); + Response response = sendRequest(req, 200); + assertEquals(200,response.getStatus()); + response = sendRequest(new GetRequest("/api/classes/cmsara_hi"), 404); + assertEquals(404,response.getStatus()); + } + + //TODO individual check of all elements + 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("{http://www.alfresco.org/model/content/1.0}avatar", result.get("name")); + assertEquals(false, result.get("isChild")); + assertEquals(false, result.get("protected")); + assertEquals(200,response.getStatus()); + response = sendRequest(new GetRequest(URL_SITES +"/cm_personalbe/association/cms_avatarsara"), 404); + assertEquals(404,response.getStatus()); + } + + //TODO individual check of all elements + public void testGetAssociatoinDefs() throws Exception + { + GetRequest req = new GetRequest(URL_SITES + "/cm_person/associations"); + Response response = sendRequest(req, 200); + assertEquals(200,response.getStatus()); + response = sendRequest(new GetRequest(URL_SITES +"/cmsa_personalbe/associations"), 404); + assertEquals(404,response.getStatus()); + } + + //TODO individual check of all elements + public void testGetChildAssociatoinDef() throws Exception + { + GetRequest req = new GetRequest(URL_SITES + "/cm_thumbnailed/childassociation/cm_thumbnails"); + Response response = sendRequest(req, 200); + assertEquals(200,response.getStatus()); + response = sendRequest(new GetRequest(URL_SITES +"/cm_thumbnailed:sara/childassociation/cm:thumbnails"), 404); + assertEquals(404,response.getStatus()); + + } + + //TODO individual check of all elements + public void testGetChildAssociatoinDefs() throws Exception + { + GetRequest req = new GetRequest(URL_SITES + "/cm_thumbnailed/childassociations"); + Response response = sendRequest(req, 200); + assertEquals(200,response.getStatus()); + response = sendRequest(new GetRequest(URL_SITES +"/cm_thumbnailed:sara/childassociations"), 404); + assertEquals(404,response.getStatus()); + } + +} diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDef.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDef.java new file mode 100644 index 0000000000..870c625eef --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDef.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import java.util.HashMap; +import java.util.Map; + +/* + * Webscript to get the Associationdefinition for a given classname and association-name + * @author Saravanan Sellathurai + */ + +public class GetAssociationDef 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 DICTIONARY_CLASS_NAME = "classname"; + private static final String DICTIONARY_ASSOCIATION_NAME = "assocname"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + /** + * @Override method from DeclarativeWebScript + */ + protected Map executeImpl(WebScriptRequest req, Status status) + { + String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String assocname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_NAME); + Map model = new HashMap(); + QName classqname = null; + QName assocqname = null; + boolean classnameGiven = (classname != null) && (classname.length() > 0); + boolean assocnameGiven = (assocname != null) && (assocname.length() > 0); + + if(classnameGiven && assocnameGiven) + { + classqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + assocqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(assocname)); + } + classdefinition = this.dictionaryservice.getClass(classqname); + + if(this.classdefinition != null) + { + model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.classdefinition.getAssociations().get(assocqname)); + return model; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } + } + +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java new file mode 100644 index 0000000000..222575499e --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetAssociationDefs.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import java.util.HashMap; +import java.util.Map; + +/* + * Webscript to get the Associationdefinitions for a given classname + * @author Saravanan Sellathurai + */ + +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 DICTIONARY_CLASS_NAME = "classname"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + /** + * @Override method from DeclarativeWebScript + */ + protected Map executeImpl(WebScriptRequest req, Status status) + { + String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + Map model = new HashMap(); + QName classqname = null; + boolean classnameGiven = (classname != null) && (classname.length() > 0); + + if(classnameGiven) + { + classqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + } + classdefinition = this.dictionaryservice.getClass(classqname); + + if(this.classdefinition != null) + { + model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.classdefinition.getAssociations().values()); + return model; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } + } + +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetChildAssociationDef.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetChildAssociationDef.java new file mode 100644 index 0000000000..42cdbebe68 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetChildAssociationDef.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import java.util.HashMap; +import java.util.Map; + +/* + * Webscript to get the ChildAssociationdefinitions for a given classname and child-association-name + * @author Saravanan Sellathurai + */ + +public class GetChildAssociationDef 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 DICTIONARY_ASSOCIATION_NAME = "assocname"; + private static final String DICTIONARY_CLASS_NAME = "classname"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + /** + * @Override method from DeclarativeWebScript + */ + protected Map executeImpl(WebScriptRequest req, Status status) + { + String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String assocname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_ASSOCIATION_NAME); + Map model = new HashMap(); + QName classqname = null; + QName assocqname = null; + boolean classnameGiven = (classname != null) && (classname.length() > 0); + boolean assocnameGiven = (assocname != null) && (assocname.length() > 0); + + if(classnameGiven && assocnameGiven) + { + classqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + assocqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(assocname)); + } + classdefinition = this.dictionaryservice.getClass(classqname); + + if(this.classdefinition != null) + { + model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.classdefinition.getChildAssociations().get(assocqname)); + return model; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } + } + +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetChildAssociationDefs.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetChildAssociationDefs.java new file mode 100644 index 0000000000..0a6c95dfed --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetChildAssociationDefs.java @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import java.util.HashMap; +import java.util.Map; + +public class GetChildAssociationDefs 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 DICTIONARY_CLASS_NAME = "classname"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + /** + * @Override method from DeclarativeWebScript + */ + protected Map executeImpl(WebScriptRequest req, Status status) + { + String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + Map model = new HashMap(); + QName classqname = null; + boolean classnameGiven = (classname != null) && (classname.length() > 0); + + if(classnameGiven){ + classqname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + } + classdefinition = this.dictionaryservice.getClass(classqname); + if(this.classdefinition != null){ + model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, this.classdefinition.getChildAssociations().values()); + return model; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } + } + +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java new file mode 100644 index 0000000000..9bfd6b397d --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetail.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import java.util.HashMap; +import java.util.Map; + +/* + * Webscript to get the Classdefinitions using classfilter , namespaceprefix and name + * @author Saravanan Sellathurai + */ + +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 REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp"; + private static final String REQ_URL_TEMPL_VAR_NAME = "n"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + /** + * @Override method from DeclarativeWebScript + */ + protected Map executeImpl(WebScriptRequest req, Status status) + { + 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 classname = null; + + Map model = new HashMap(); + QName qname = null; + boolean cfGiven = (classfilter != null) && (classfilter.length() > 0); + boolean nspGiven = (namespaceprefix != null) && (namespaceprefix.length() > 0); + boolean nameGiven = (name != null) && (name.length() > 0); + + if(cfGiven && nspGiven && nameGiven) + { + classname = namespaceprefix + "_" + name; + qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + } + classdefinition = this.dictionaryservice.getClass(qname); + + if(this.classdefinition != null) + { + model.put(MODEL_PROP_KEY_CLASS_DEFS, this.classdefinition); + return model; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } + } + + } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java new file mode 100644 index 0000000000..089f1a4a69 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetClassDetails.java @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import java.util.HashMap; +import java.util.Map; + +/* + * Webscript to get the Classdefinitions for a classname eg. =>cm_author + * @author Saravanan Sellathurai + */ + +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"; + private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs"; + private static final String DICTIONARY_CLASS_NAME = "className"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryHelper The dictionary helper instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + /** + * @Override method from DeclarativeWebScript + */ + protected Map executeImpl(WebScriptRequest req, Status status) + { + String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + + Map model = new HashMap(); + QName qname = null; + boolean classnameGiven = (classname != null) && (classname.length() > 0); + + if(classnameGiven) + { + qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + } + + classdefinition = this.dictionaryservice.getClass(qname); + if(this.classdefinition != null) + { + 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()); + return model; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } + } + +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDef.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDef.java new file mode 100644 index 0000000000..7867361a94 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDef.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import java.util.HashMap; +import java.util.Map; + +/* + * Webscript to get the Propertydefinition for a given classname and propname + * @author Saravanan Sellathurai + */ + +public class GetPropertyDef 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 DICTIONARY_CLASS_NAME = "classname"; + private static final String DICTIONARY_PROPERTY_NAME = "propname"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + /** + * @Override method from DeclarativeWebScript + */ + protected Map executeImpl(WebScriptRequest req, Status status) + { + String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + String propertyname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_PROPERTY_NAME); + Map model = new HashMap(); + QName qname = null; + QName propname = null; + boolean classnameGiven = (classname != null) && (classname.length() > 0); + boolean propertynameGiven = (propertyname != null) && (propertyname.length() > 0); + + if(classnameGiven && propertynameGiven) + { + qname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(classname)); + propname = QName.createQName(this.dictionaryhelper.getFullNamespaceURI(propertyname)); + } + classdefinition = this.dictionaryservice.getClass(qname); + + if(this.classdefinition != null) + { + model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, this.classdefinition.getProperties().get(propname)); + return model; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } + } + +} \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java new file mode 100644 index 0000000000..8b22d545c8 --- /dev/null +++ b/source/java/org/alfresco/repo/web/scripts/dictionary/GetPropertyDefs.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.web.scripts.DeclarativeWebScript; +import org.alfresco.web.scripts.Status; +import org.alfresco.web.scripts.WebScriptException; +import org.alfresco.web.scripts.WebScriptRequest; +import org.alfresco.service.namespace.QName; +import org.alfresco.service.cmr.dictionary.DictionaryService; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import java.util.HashMap; +import java.util.Map; + +/* + * Webscript to get the Propertydefinitions for a given classname eg. =>cm_person + * @author Saravanan Sellathurai + */ + +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 DICTIONARY_CLASS_NAME = "classname"; + + /** + * Set the dictionaryService property. + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryService(DictionaryService dictionaryService) + { + this.dictionaryservice = dictionaryService; + } + + /** + * Set the dictionaryhelper class + * + * @param dictionaryService The dictionary service instance to set + */ + public void setDictionaryHelper(DictionaryHelper dictionaryhelper) + { + this.dictionaryhelper = dictionaryhelper; + } + + + /** + * @Override method from DeclarativeWebScript + */ + protected Map executeImpl(WebScriptRequest req, Status status) + { + String classname = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + + Map model = new HashMap(); + QName qname = null; + boolean classnameGiven = (classname != null) && (classname.length() > 0); + + if(classnameGiven) + { + 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; + } + else + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "The exact parameter has not been provided in the URL"); + } + } + +} \ No newline at end of file