diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml index 9f4a5eca6a..0d6f8ccc87 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-webscript-context.xml @@ -504,18 +504,32 @@ - + - + parent="abstractActionDefinitionsGet" /> + parent="abstractActionDefinitionsGet" /> + + + + + + + + + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-classes.get.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-classes.get.desc.xml new file mode 100644 index 0000000000..fbcd9b30e8 --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-classes.get.desc.xml @@ -0,0 +1,8 @@ + + Get RM/DM related class definitions + Gets the RM/DM related collection of class definitions - parameters classfilter, namespaceprefix and name. + /api/rm/classes?cf={classFilter?}&nsp={namespacePrefix?}&n={name?} + argument + user + required + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-classes.get.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-classes.get.json.ftl new file mode 100644 index 0000000000..5c76c5d56f --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-classes.get.json.ftl @@ -0,0 +1 @@ +<#include "classes.get.json.ftl"> \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-properties.get.desc.xml b/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-properties.get.desc.xml new file mode 100644 index 0000000000..83fa618a06 --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-properties.get.desc.xml @@ -0,0 +1,9 @@ + + Get RM/DM property definitions + Gets the collection of RM/DM property definitions. + /api/rm/classes/{classname}/properties?nsp={namespacePrefix?}&n={name?} + /api/rm/properties?nsp={namespacePrefix?}&n={name?} + argument + user + required + \ No newline at end of file diff --git a/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-properties.get.json.ftl b/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-properties.get.json.ftl new file mode 100644 index 0000000000..5a404f184d --- /dev/null +++ b/rm-server/config/alfresco/templates/webscripts/org/alfresco/repository/dictionary/rm-properties.get.json.ftl @@ -0,0 +1 @@ +<#include "properties.get.json.ftl"> \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmClassesGet.java b/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmClassesGet.java new file mode 100644 index 0000000000..500b66263a --- /dev/null +++ b/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmClassesGet.java @@ -0,0 +1,242 @@ +/* + * Copyright (C) 2005-2013 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.web.scripts.dictionary; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.service.cmr.dictionary.AssociationDefinition; +import org.alfresco.service.cmr.dictionary.ClassDefinition; +import org.alfresco.service.cmr.dictionary.PropertyDefinition; +import org.alfresco.service.cmr.site.SiteService; +import org.alfresco.service.namespace.QName; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * Webscript to get the Classdefinitions using classfilter , namespaceprefix and name + * + * This class makes it possible to get only RM related class definitions + * @see ClassesGet for the original implementation + * + * @author Tuna Aksoy + * @since 2.1 + */ +public class RmClassesGet extends DictionaryWebServiceBase implements RecordsManagementModel +{ + 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 CLASS_FILTER_OPTION_TYPE1 = "all"; + private static final String CLASS_FILTER_OPTION_TYPE2 = "aspect"; + private static final String CLASS_FILTER_OPTION_TYPE3 = "type"; + + private static final String REQ_URL_TEMPL_VAR_CLASS_FILTER = "cf"; + private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp"; + private static final String REQ_URL_TEMPL_VAR_NAME = "n"; + + /** Site service*/ + private SiteService siteService; + + /** + * @param siteService the site service to set + */ + public void setSiteService(SiteService siteService) + { + this.siteService = siteService; + } + + /** + * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache) + */ + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + { + return executeImpl(req, status, cache, RmDictionaryWebServiceUtils.isRmSite(req, siteService)); + } + + /** + * Execute custom Java logic + * + * @param req Web Script request + * @param status Web Script status + * @param cache Web Script cache + * @param isRM indicates whether the request comes from an RM site or not + * @return custom service model + */ + private Map executeImpl(WebScriptRequest req, Status status, Cache cache, boolean isRM) + { + String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER)); + String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX)); + String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME)); + String className = null; + + Map classdef = new HashMap(); + Map> propdef = new HashMap>(); + Map> assocdef = new HashMap>(); + Map model = new HashMap(); + + List qnames = new ArrayList(); + QName classQname = null; + QName myModel = null; + + //if classfilter is not given, then it defaults to all + if (classFilter == null) + { + classFilter = "all"; + } + + //validate classfilter + if (isValidClassFilter(classFilter) == false) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL"); + } + + //name alone has no meaning without namespaceprefix + if (namespacePrefix == null && name != null) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed"); + } + + //validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it + if (namespacePrefix != null) + { + //validate name parameter if present along with the namespaceprefix + if (name != null) + { + className = namespacePrefix + "_" + name; + if (isValidClassname(className) == false) + { + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL"); + } + classQname = QName.createQName(getFullNamespaceURI(className)); + classdef.put(classQname, this.dictionaryservice.getClass(classQname)); + propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values()); + assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values()); + } + else + { + //if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix + String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix); + for (QName qnameObj : this.dictionaryservice.getAllModels()) + { + if (qnameObj.getNamespaceURI().equals(namespaceUri)) + { + name = qnameObj.getLocalName(); + myModel = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name)); + + // check the classfilter to pull out either all or type or aspects + if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) + { + qnames.addAll(this.dictionaryservice.getAspects(myModel)); + qnames.addAll(this.dictionaryservice.getTypes(myModel)); + } + else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) + { + qnames.addAll(this.dictionaryservice.getTypes(myModel)); + } + else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) + { + qnames.addAll(this.dictionaryservice.getAspects(myModel)); + } + } + } + } + } + + // if namespacePrefix is null, then check the class filter to pull out either all, type or aspects + if (myModel == null) + { + if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1)) + { + qnames.addAll(getAspects(isRM)); + qnames.addAll(getTypes(isRM)); + } + else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3)) + { + qnames.addAll(getTypes(isRM)); + } + else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2)) + { + qnames.addAll(getAspects(isRM)); + } + } + + if (classdef.isEmpty() == true) + { + for (QName qnameObj : qnames) + { + 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()); + } + } + + List classDefinitions = new ArrayList(classdef.values()); + Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator()); + model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions); + model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values()); + model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values()); + + return model; + } + + /** + * Returns the names of the types depending on {@link isRM} parameter + * + * @param isRM if true only RM related types will be retrieved + * @return The names of the types defined within the specified model or all of them depending on {@link isRM} parameter + */ + private Collection getTypes(boolean isRM) + { + if (isRM == true) + { + return this.dictionaryservice.getTypes(RM_MODEL); + } + else + { + return this.dictionaryservice.getAllTypes(); + } + } + + /** + * Returns the names of the aspects depending on {@link isRM} parameter + * + * @param isRM if true only RM related aspects will be retrieved + * @return The names of the aspects defined within the specified model or all of them depending on {@link isRM} parameter + */ + private Collection getAspects(boolean isRM) + { + if (isRM == true) + { + return this.dictionaryservice.getAspects(RM_MODEL); + } + else + { + return this.dictionaryservice.getAllAspects(); + } + } +} diff --git a/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmDictionaryWebServiceUtils.java b/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmDictionaryWebServiceUtils.java new file mode 100644 index 0000000000..1aea9f2d0f --- /dev/null +++ b/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmDictionaryWebServiceUtils.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2005-2013 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.web.scripts.dictionary; + +import org.alfresco.service.cmr.site.SiteInfo; +import org.alfresco.service.cmr.site.SiteService; +import org.apache.commons.lang.StringUtils; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * Util class for dictionary web services + * + * @author Tuna Aksoy + * @since 2.1 + */ +public class RmDictionaryWebServiceUtils +{ + private static final String SITE_ID = "siteId"; + private static final String SITE_PRESET = "rm-site-dashboard"; + + public static boolean isRmSite(WebScriptRequest req, SiteService siteService) + { + boolean isRmSite = false; + String siteId = req.getParameter(SITE_ID); + if (StringUtils.isNotBlank(siteId) == true) + { + SiteInfo site = siteService.getSite(siteId); + if (site != null) + { + if (site.getSitePreset().equals(SITE_PRESET) == true) + { + isRmSite = true; + } + } + } + return isRmSite; + } +} diff --git a/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmPropertiesGet.java b/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmPropertiesGet.java new file mode 100644 index 0000000000..f19ffb9a23 --- /dev/null +++ b/rm-server/source/java/org/alfresco/repo/web/scripts/dictionary/RmPropertiesGet.java @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2005-2013 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.web.scripts.dictionary; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; +import org.alfresco.service.cmr.dictionary.PropertyDefinition; +import org.alfresco.service.cmr.site.SiteService; +import org.alfresco.service.namespace.QName; +import org.springframework.extensions.webscripts.Cache; +import org.springframework.extensions.webscripts.Status; +import org.springframework.extensions.webscripts.WebScriptException; +import org.springframework.extensions.webscripts.WebScriptRequest; + +/** + * Webscript to get the Propertydefinitions for a given classname eg. =>cm_person + * + * This class makes it possible to get only RM related property definitions + * @see PropertiesGet for the original implementation + * + * @author Tuna Aksoy + * @since 2.1 + */ +public class RmPropertiesGet extends DictionaryWebServiceBase implements RecordsManagementModel +{ + private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs"; + private static final String DICTIONARY_CLASS_NAME = "classname"; + private static final String PARAM_NAME = "name"; + private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp"; + + /** Site service*/ + private SiteService siteService; + + /** + * @param siteService the site service to set + */ + public void setSiteService(SiteService siteService) + { + this.siteService = siteService; + } + + /** + * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache) + */ + protected Map executeImpl(WebScriptRequest req, Status status, Cache cache) + { + return executeImpl(req, status, cache, RmDictionaryWebServiceUtils.isRmSite(req, siteService)); + } + + /** + * Execute custom Java logic + * + * @param req Web Script request + * @param status Web Script status + * @param cache Web Script cache + * @param isRM indicates whether the request comes from an RM site or not + * @return custom service model + */ + private Map executeImpl(WebScriptRequest req, Status status, Cache cache, boolean isRM) + { + QName classQName = null; + String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME); + if (className != null && className.length() != 0) + { + classQName = createClassQName(className); + if (classQName == null) + { + // Error + throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL"); + } + } + + String[] names = req.getParameterValues(PARAM_NAME); + + String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX); + String namespaceURI = null; + if (namespacePrefix != null) + { + namespaceURI = this.namespaceService.getNamespaceURI(namespacePrefix); + } + + Map propMap = null; + if (classQName == null) + { + if (names != null) + { + propMap = new HashMap(names.length); + for (String name : names) + { + QName propQName = QName.createQName(name, namespaceService); + PropertyDefinition propDef = dictionaryservice.getProperty(propQName); + if (propDef != null) + { + propMap.put(propQName, propDef); + } + } + } + else + { + Collection propQNames = getProperties(isRM); + propMap = new HashMap(propQNames.size()); + for (QName propQName : propQNames) + { + propMap.put(propQName, dictionaryservice.getProperty(propQName)); + } + } + + } + else + { + // Get all the property definitions for the class + propMap = dictionaryservice.getClass(classQName).getProperties(); + } + + // Filter the properties by URI + List props = new ArrayList(propMap.size()); + for (Map.Entry entry : propMap.entrySet()) + { + if ((namespaceURI != null && + namespaceURI.equals(entry.getKey().getNamespaceURI()) == true) || + namespaceURI == null) + { + props.add(entry.getValue()); + } + } + + // Order property definitions by title + Collections.sort(props, new DictionaryComparators.PropertyDefinitionComparator()); + + // Pass list of property definitions to template + Map model = new HashMap(); + model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props); + return model; + } + + /** + * Returns the names of the properties depending on {@link isRM} parameter + * + * @param isRM if true only RM related properties will be retrieved + * @return The names of the properties defined within the specified model or all of them depending on {@link isRM} parameter + */ + private Collection getProperties(boolean isRM) + { + if (isRM == true) + { + return dictionaryservice.getProperties(RM_MODEL); + } + else + { + return dictionaryservice.getAllProperties(null); + } + } +}