A records management administrator can select aspects and types relevant to RM when defining rules with aspect or type related conditions 

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@47244 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-02-27 17:25:01 +00:00
parent a926a9fc75
commit 5c5259d1de
8 changed files with 508 additions and 4 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> 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<String, Object> 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<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>();
List<QName> qnames = new ArrayList<QName>();
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<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(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<QName> 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<QName> getAspects(boolean isRM)
{
if (isRM == true)
{
return this.dictionaryservice.getAspects(RM_MODEL);
}
else
{
return this.dictionaryservice.getAllAspects();
}
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String, Object> 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<String, Object> 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<QName, PropertyDefinition> propMap = null;
if (classQName == null)
{
if (names != null)
{
propMap = new HashMap<QName, PropertyDefinition>(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<QName> propQNames = getProperties(isRM);
propMap = new HashMap<QName, PropertyDefinition>(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<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
for (Map.Entry<QName, PropertyDefinition> 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<String, Object> model = new HashMap<String, Object>();
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<QName> getProperties(boolean isRM)
{
if (isRM == true)
{
return dictionaryservice.getProperties(RM_MODEL);
}
else
{
return dictionaryservice.getAllProperties(null);
}
}
}