Let git handle line endings for us.

This commit is contained in:
Tom Page
2016-09-27 13:55:53 +01:00
parent 5c90f386f4
commit e673d7ab03
930 changed files with 118901 additions and 118872 deletions

View File

@@ -1,241 +1,241 @@
/*
* Copyright (C) 2005-2014 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, RmDictionaryWebServiceUtils.isRmSite(req, siteService));
}
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, 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))
{
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))
{
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())
{
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(dictionaryservice));
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());
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
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)
{
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)
{
return this.dictionaryservice.getAspects(RM_MODEL);
}
else
{
return this.dictionaryservice.getAllAspects();
}
}
}
/*
* Copyright (C) 2005-2014 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, RmDictionaryWebServiceUtils.isRmSite(req, siteService));
}
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, 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))
{
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))
{
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())
{
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(dictionaryservice));
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());
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
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)
{
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)
{
return this.dictionaryservice.getAspects(RM_MODEL);
}
else
{
return this.dictionaryservice.getAllAspects();
}
}
}

View File

@@ -1,56 +1,56 @@
/*
* Copyright (C) 2005-2014 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 final class RmDictionaryWebServiceUtils
{
private static final String SITE_ID = "siteId";
private static final String SITE_PRESET = "rm-site-dashboard";
private RmDictionaryWebServiceUtils()
{
// Will not be called
}
public static boolean isRmSite(WebScriptRequest req, SiteService siteService)
{
boolean isRmSite = false;
String siteId = req.getParameter(SITE_ID);
if (StringUtils.isNotBlank(siteId))
{
SiteInfo site = siteService.getSite(siteId);
if (site != null && site.getSitePreset().equals(SITE_PRESET))
{
isRmSite = true;
}
}
return isRmSite;
}
}
/*
* Copyright (C) 2005-2014 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 final class RmDictionaryWebServiceUtils
{
private static final String SITE_ID = "siteId";
private static final String SITE_PRESET = "rm-site-dashboard";
private RmDictionaryWebServiceUtils()
{
// Will not be called
}
public static boolean isRmSite(WebScriptRequest req, SiteService siteService)
{
boolean isRmSite = false;
String siteId = req.getParameter(SITE_ID);
if (StringUtils.isNotBlank(siteId))
{
SiteInfo site = siteService.getSite(siteId);
if (site != null && site.getSitePreset().equals(SITE_PRESET))
{
isRmSite = true;
}
}
return isRmSite;
}
}

View File

@@ -1,175 +1,175 @@
/*
* Copyright (C) 2005-2014 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, RmDictionaryWebServiceUtils.isRmSite(req, siteService));
}
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, 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())) ||
namespaceURI == null)
{
props.add(entry.getValue());
}
}
// Order property definitions by title
Collections.sort(props, new DictionaryComparators.PropertyDefinitionComparator(dictionaryservice));
// Pass list of property definitions to template
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
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)
{
return dictionaryservice.getProperties(RM_MODEL);
}
else
{
return dictionaryservice.getAllProperties(null);
}
}
}
/*
* Copyright (C) 2005-2014 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, RmDictionaryWebServiceUtils.isRmSite(req, siteService));
}
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, 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())) ||
namespaceURI == null)
{
props.add(entry.getValue());
}
}
// Order property definitions by title
Collections.sort(props, new DictionaryComparators.PropertyDefinitionComparator(dictionaryservice));
// Pass list of property definitions to template
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
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)
{
return dictionaryservice.getProperties(RM_MODEL);
}
else
{
return dictionaryservice.getAllProperties(null);
}
}
}

View File

@@ -1,99 +1,99 @@
/*
* Copyright (C) 2005-2014 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.roles;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.script.admin.RoleDeclarativeWebScript;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Abstract class for adding/removing a user/group to/from a role
* This class contains the common methods needed in the sub classes.
*
* @author Tuna Aksoy
* @since 2.1
*/
public class AbstractRmAuthorities extends RoleDeclarativeWebScript
{
/** Constants for the url parameters */
private static final String ROLE_ID = "roleId";
private static final String AUTHORITY_NAME = "authorityName";
/**
* Util method for getting the nodeRef from the request
*
* @param req The webscript request
* @return The nodeRef passed in the request
*/
protected NodeRef getFilePlan(WebScriptRequest req)
{
NodeRef filePlan = super.getFilePlan(req);
if (filePlan == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No filePlan was provided on the URL.");
}
return filePlan;
}
/**
* Util method for getting the roleId from the request
*
* @param req The webscript request
* @return The role id passed in the request
*/
protected String getRoleId(WebScriptRequest req)
{
return getParamValue(req, ROLE_ID);
}
/**
* Util method for getting the authorityName from the request
*
* @param req The webscript request
* @return The authorityName passed in the request
*/
protected String getAuthorityName(WebScriptRequest req)
{
return getParamValue(req, AUTHORITY_NAME);
}
/**
* Helper method to get the value of parameter from the request
*
* @param req The webscript request
* @param param The name of the parameter for which the value is requested
* @return The value for the requested parameter
*/
private String getParamValue(WebScriptRequest req, String param)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String authorityName = templateVars.get(param);
if (StringUtils.isBlank(authorityName))
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No '" + param + "' was provided on the URL.");
}
return authorityName;
}
}
/*
* Copyright (C) 2005-2014 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.roles;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.script.admin.RoleDeclarativeWebScript;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Abstract class for adding/removing a user/group to/from a role
* This class contains the common methods needed in the sub classes.
*
* @author Tuna Aksoy
* @since 2.1
*/
public class AbstractRmAuthorities extends RoleDeclarativeWebScript
{
/** Constants for the url parameters */
private static final String ROLE_ID = "roleId";
private static final String AUTHORITY_NAME = "authorityName";
/**
* Util method for getting the nodeRef from the request
*
* @param req The webscript request
* @return The nodeRef passed in the request
*/
protected NodeRef getFilePlan(WebScriptRequest req)
{
NodeRef filePlan = super.getFilePlan(req);
if (filePlan == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No filePlan was provided on the URL.");
}
return filePlan;
}
/**
* Util method for getting the roleId from the request
*
* @param req The webscript request
* @return The role id passed in the request
*/
protected String getRoleId(WebScriptRequest req)
{
return getParamValue(req, ROLE_ID);
}
/**
* Util method for getting the authorityName from the request
*
* @param req The webscript request
* @return The authorityName passed in the request
*/
protected String getAuthorityName(WebScriptRequest req)
{
return getParamValue(req, AUTHORITY_NAME);
}
/**
* Helper method to get the value of parameter from the request
*
* @param req The webscript request
* @param param The name of the parameter for which the value is requested
* @return The value for the requested parameter
*/
private String getParamValue(WebScriptRequest req, String param)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String authorityName = templateVars.get(param);
if (StringUtils.isBlank(authorityName))
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No '" + param + "' was provided on the URL.");
}
return authorityName;
}
}

View File

@@ -1,53 +1,53 @@
/*
* Copyright (C) 2005-2014 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.roles;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript for removing a user or a group from a role
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmAuthoritiesDelete extends AbstractRmAuthorities
{
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
String roleId = getRoleId(req);
String authorityName = getAuthorityName(req);
filePlanRoleService.unassignRoleFromAuthority(filePlan, roleId, authorityName);
return new HashMap<String, Object>();
}
}
/*
* Copyright (C) 2005-2014 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.roles;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript for removing a user or a group from a role
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmAuthoritiesDelete extends AbstractRmAuthorities
{
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
String roleId = getRoleId(req);
String authorityName = getAuthorityName(req);
filePlanRoleService.unassignRoleFromAuthority(filePlan, roleId, authorityName);
return new HashMap<String, Object>();
}
}

View File

@@ -1,53 +1,53 @@
/*
* Copyright (C) 2005-2014 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.roles;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript for adding a user or a group to a role
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmAuthoritiesPost extends AbstractRmAuthorities
{
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
String roleId = getRoleId(req);
String authorityName = getAuthorityName(req);
filePlanRoleService.assignRoleToAuthority(filePlan, roleId, authorityName);
return new HashMap<String, Object>();
}
}
/*
* Copyright (C) 2005-2014 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.roles;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript for adding a user or a group to a role
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmAuthoritiesPost extends AbstractRmAuthorities
{
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
String roleId = getRoleId(req);
String authorityName = getAuthorityName(req);
filePlanRoleService.assignRoleToAuthority(filePlan, roleId, authorityName);
return new HashMap<String, Object>();
}
}

View File

@@ -1,81 +1,81 @@
/*
* Copyright (C) 2005-2014 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.rule;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionCondition;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to get the RM related action condition definition list.
*
* @author Roy Wetherall
* @since 2.1
*/
public class RmActionConditionDefinitionsGet extends DeclarativeWebScript
{
private ActionService actionService;
private RecordsManagementActionService recordsManagementActionService;
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
public void setRecordsManagementActionService(RecordsManagementActionService recordsManagementActionService)
{
this.recordsManagementActionService = recordsManagementActionService;
}
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
List<ActionConditionDefinition> dmDefs = actionService.getActionConditionDefinitions();
List<RecordsManagementActionCondition> conditions = recordsManagementActionService.getRecordsManagementActionConditions();
List<ActionConditionDefinition> defs = new ArrayList<ActionConditionDefinition>(dmDefs.size()+conditions.size());
defs.addAll(dmDefs);
for (RecordsManagementActionCondition condition: conditions)
{
if (condition.isPublicCondition())
{
defs.add(condition.getRecordsManagementActionConditionDefinition());
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("actionconditiondefinitions", defs);
return model;
}
}
/*
* Copyright (C) 2005-2014 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.rule;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionCondition;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to get the RM related action condition definition list.
*
* @author Roy Wetherall
* @since 2.1
*/
public class RmActionConditionDefinitionsGet extends DeclarativeWebScript
{
private ActionService actionService;
private RecordsManagementActionService recordsManagementActionService;
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
public void setRecordsManagementActionService(RecordsManagementActionService recordsManagementActionService)
{
this.recordsManagementActionService = recordsManagementActionService;
}
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
List<ActionConditionDefinition> dmDefs = actionService.getActionConditionDefinitions();
List<RecordsManagementActionCondition> conditions = recordsManagementActionService.getRecordsManagementActionConditions();
List<ActionConditionDefinition> defs = new ArrayList<ActionConditionDefinition>(dmDefs.size()+conditions.size());
defs.addAll(dmDefs);
for (RecordsManagementActionCondition condition: conditions)
{
if (condition.isPublicCondition())
{
defs.add(condition.getRecordsManagementActionConditionDefinition());
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("actionconditiondefinitions", defs);
return model;
}
}

View File

@@ -1,71 +1,71 @@
/*
* Copyright (C) 2005-2014 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.rule;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to get the RM related action definition list.
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmActionDefinitionsGet extends DeclarativeWebScript
{
private RecordsManagementActionService recordsManagementActionService;
public void setRecordsManagementActionService(RecordsManagementActionService recordsManagementActionService)
{
this.recordsManagementActionService = recordsManagementActionService;
}
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
List<RecordsManagementAction> actions = recordsManagementActionService.getRecordsManagementActions();
Set<ActionDefinition> defs = new HashSet<ActionDefinition>(actions.size());
for (RecordsManagementAction action : actions)
{
if (action.isPublicAction())
{
defs.add(action.getRecordsManagementActionDefinition());
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("actiondefinitions", defs);
return model;
}
}
/*
* Copyright (C) 2005-2014 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.rule;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to get the RM related action definition list.
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmActionDefinitionsGet extends DeclarativeWebScript
{
private RecordsManagementActionService recordsManagementActionService;
public void setRecordsManagementActionService(RecordsManagementActionService recordsManagementActionService)
{
this.recordsManagementActionService = recordsManagementActionService;
}
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
List<RecordsManagementAction> actions = recordsManagementActionService.getRecordsManagementActions();
Set<ActionDefinition> defs = new HashSet<ActionDefinition>(actions.size());
for (RecordsManagementAction action : actions)
{
if (action.isPublicAction())
{
defs.add(action.getRecordsManagementActionDefinition());
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("actiondefinitions", defs);
return model;
}
}

View File

@@ -1,304 +1,304 @@
/*
* Copyright (C) 2005-2014 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.substitutionsuggestions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.action.parameter.ParameterProcessorComponent;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.namespace.QName;
import org.apache.cxf.common.util.StringUtils;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to get substitution suggestions
* given a text fragment (e.g. date.month for 'mon').
*
* @author Mark Hibbins
* @since 2.2
*/
public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
{
private static final String FRAGMENT_PARAMETER = "fragment";
private static final String PATH_PARAMETER = "path";
private static final String UNFILED_PARAMETER = "unfiled";
private static final String UNFILED = "true";
private static final String SUBSTITUTIONS_MODEL_KEY = "substitutions";
private static final String CREATE_CAPABILITY = "Create";
private static final String VIEW_CAPABILITY = "ViewRecords";
private static final int DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH = 0;
private static final int DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS = 10;
private int pathSubstitutionMaximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS;
private int substitutionMinimumFragmentSize = DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH;
private ParameterProcessorComponent parameterProcessorComponent;
private NodeService nodeService;
private FilePlanService filePlanService;
private CapabilityService capabilityService;
/**
* Set the parameter processor component bean
*
* @param parameterProcessorComponent
*/
public void setParameterProcessorComponent(ParameterProcessorComponent parameterProcessorComponent)
{
this.parameterProcessorComponent = parameterProcessorComponent;
}
/**
* Set the parameter processor component bean
*
* @param parameterProcessorComponent
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param filePlanService file plan service
*/
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
/**
* @param filePlanService file plan service
*/
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
/**
* Set the minimum fragment size to process for suggestion processing
*
* @param maximumNumberSuggestions
*/
public void setSubstitutionMinimumFragmentSize(int substitutionMinimumFragmentSize)
{
this.substitutionMinimumFragmentSize = Math.max(substitutionMinimumFragmentSize, DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH);
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setPathSubstitutionMaximumNumberSuggestions(int pathSubstitutionMaximumNumberSuggestions)
{
this.pathSubstitutionMaximumNumberSuggestions = (pathSubstitutionMaximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS: pathSubstitutionMaximumNumberSuggestions);
}
/**
* Return a list of substitutions for the given fragment.
*
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String fragment = req.getParameter(FRAGMENT_PARAMETER);
String path = req.getParameter(PATH_PARAMETER);
String unfiledString = req.getParameter(UNFILED_PARAMETER);
boolean unfiled = (unfiledString != null) && UNFILED.equals(unfiledString);
List<String> substitutionSuggestions = new ArrayList<String>();
if((fragment != null) && (fragment.length() >= this.substitutionMinimumFragmentSize))
{
substitutionSuggestions.addAll(getSubPathSuggestions(req, path, fragment, unfiled));
substitutionSuggestions.addAll(this.parameterProcessorComponent.getSubstitutionSuggestions(fragment));
}
Map<String, Object> model = new HashMap<String, Object>();
model.put(SUBSTITUTIONS_MODEL_KEY, substitutionSuggestions);
return model;
}
/**
* Return a list of path suggestions for the path fragment supplied.
*
* @param path
* @param fragment
* @return
*/
private List<String> getSubPathSuggestions(WebScriptRequest req, final String path, final String fragment, boolean unfiled) {
List<String> pathSuggestions = new ArrayList<String>();
if((path != null) && path.startsWith("/") && (fragment != null))
{
String[] pathFragments = path.split("/");
NodeRef currentNode = getFilePlan(req, unfiled);
for(String pathFragment : pathFragments)
{
// ignore empty elements of the path produced by split
if(!pathFragment.isEmpty())
{
boolean foundThisPathFragment = false;
List<ChildAssociationRef> children = nodeService.getChildAssocs(currentNode);
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
String fileName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
if(fileName.equals(pathFragment) && isNodeRefAppropriateForPathSuggestion(childNodeRef, unfiled))
{
foundThisPathFragment = true;
currentNode = childNodeRef;
break;
}
}
if(!foundThisPathFragment)
{
currentNode = null;
break;
}
}
}
if(currentNode != null)
{
String lowerCaseFragment = fragment.toLowerCase();
List<ChildAssociationRef> children = nodeService.getChildAssocs(currentNode);
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
String fileName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
if((fragment.isEmpty() || fileName.toLowerCase().startsWith(lowerCaseFragment)) && isNodeRefAppropriateForPathSuggestion(childNodeRef, unfiled))
{
pathSuggestions.add("/" + fileName);
if(pathSuggestions.size() >= pathSubstitutionMaximumNumberSuggestions)
{
break;
}
}
}
}
}
return pathSuggestions;
}
/**
* Utility method to get the file plan from the passed parameters.
*
* @param req
* @return
*/
protected NodeRef getFilePlan(WebScriptRequest req, boolean unfiled)
{
NodeRef filePlan = null;
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String siteId = templateVars.get("siteid");
if (siteId != null)
{
filePlan = filePlanService.getFilePlanBySiteId(siteId);
}
if (filePlan == null)
{
String storeType = templateVars.get("store_type");
String storeId = templateVars.get("store_id");
String id = templateVars.get("id");
if (!StringUtils.isEmpty(storeType) &&
!StringUtils.isEmpty(storeId) &&
!StringUtils.isEmpty(id))
{
StoreRef storeRef = new StoreRef(storeType, storeId);
NodeRef nodeRef = new NodeRef(storeRef, id);
if (filePlanService.isFilePlan(nodeRef))
{
filePlan = nodeRef;
}
}
}
if (filePlan == null)
{
// Assume we are in a legacy repository and we will grab the default file plan
filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
}
return unfiled ? filePlanService.getUnfiledContainer(filePlan) : filePlan;
}
/**
* Identifies record category and record folder types of nodeRef
*
* @param nodeRef Instance of NodeRef to be tested
* @return True if the passed NodeRef instance is a record category or record folder
*/
private boolean isNodeRefAppropriateForPathSuggestion(NodeRef nodeRef, boolean unfiled)
{
// check node type
QName type = nodeService.getType(nodeRef);
boolean isCorrectType = (!unfiled
&& (RecordsManagementModel.TYPE_RECORD_FOLDER.equals(type) || RecordsManagementModel.TYPE_RECORD_CATEGORY
.equals(type)) || (unfiled && RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(type)));
// check permissions
boolean canView = false;
if(isCorrectType)
{
Capability createCapability = capabilityService.getCapability(CREATE_CAPABILITY);
Capability viewCapability = capabilityService.getCapability(VIEW_CAPABILITY);
if ((createCapability != null) && (viewCapability != null))
{
List<String> requiredCapabilities = new ArrayList<String>();
requiredCapabilities.add(CREATE_CAPABILITY);
requiredCapabilities.add(VIEW_CAPABILITY);
Map<Capability, AccessStatus> map = capabilityService.getCapabilitiesAccessState(nodeRef, requiredCapabilities);
if (map.containsKey(createCapability) && map.containsKey(viewCapability))
{
AccessStatus createAccessStatus = map.get(createCapability);
AccessStatus viewAccessStatus = map.get(viewCapability);
if (createAccessStatus.equals(AccessStatus.ALLOWED) && viewAccessStatus.equals(AccessStatus.ALLOWED))
{
canView = true;
}
}
}
}
return isCorrectType && canView;
}
/*
* Copyright (C) 2005-2014 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.substitutionsuggestions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.capability.Capability;
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.action.parameter.ParameterProcessorComponent;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.namespace.QName;
import org.apache.cxf.common.util.StringUtils;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to get substitution suggestions
* given a text fragment (e.g. date.month for 'mon').
*
* @author Mark Hibbins
* @since 2.2
*/
public class RmSubstitutionSuggestionsGet extends DeclarativeWebScript
{
private static final String FRAGMENT_PARAMETER = "fragment";
private static final String PATH_PARAMETER = "path";
private static final String UNFILED_PARAMETER = "unfiled";
private static final String UNFILED = "true";
private static final String SUBSTITUTIONS_MODEL_KEY = "substitutions";
private static final String CREATE_CAPABILITY = "Create";
private static final String VIEW_CAPABILITY = "ViewRecords";
private static final int DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH = 0;
private static final int DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS = 10;
private int pathSubstitutionMaximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS;
private int substitutionMinimumFragmentSize = DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH;
private ParameterProcessorComponent parameterProcessorComponent;
private NodeService nodeService;
private FilePlanService filePlanService;
private CapabilityService capabilityService;
/**
* Set the parameter processor component bean
*
* @param parameterProcessorComponent
*/
public void setParameterProcessorComponent(ParameterProcessorComponent parameterProcessorComponent)
{
this.parameterProcessorComponent = parameterProcessorComponent;
}
/**
* Set the parameter processor component bean
*
* @param parameterProcessorComponent
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param filePlanService file plan service
*/
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
/**
* @param filePlanService file plan service
*/
public void setCapabilityService(CapabilityService capabilityService)
{
this.capabilityService = capabilityService;
}
/**
* Set the minimum fragment size to process for suggestion processing
*
* @param maximumNumberSuggestions
*/
public void setSubstitutionMinimumFragmentSize(int substitutionMinimumFragmentSize)
{
this.substitutionMinimumFragmentSize = Math.max(substitutionMinimumFragmentSize, DEFAULT_SUBSTITUTION_MINIMUM_FRAGMENT_LENGTH);
}
/**
* Set the maxmimum number of suggestions returned from the global property
*
* @param maximumNumberSuggestions
*/
public void setPathSubstitutionMaximumNumberSuggestions(int pathSubstitutionMaximumNumberSuggestions)
{
this.pathSubstitutionMaximumNumberSuggestions = (pathSubstitutionMaximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_PATH_SUGGESTIONS: pathSubstitutionMaximumNumberSuggestions);
}
/**
* Return a list of substitutions for the given fragment.
*
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
String fragment = req.getParameter(FRAGMENT_PARAMETER);
String path = req.getParameter(PATH_PARAMETER);
String unfiledString = req.getParameter(UNFILED_PARAMETER);
boolean unfiled = (unfiledString != null) && UNFILED.equals(unfiledString);
List<String> substitutionSuggestions = new ArrayList<String>();
if((fragment != null) && (fragment.length() >= this.substitutionMinimumFragmentSize))
{
substitutionSuggestions.addAll(getSubPathSuggestions(req, path, fragment, unfiled));
substitutionSuggestions.addAll(this.parameterProcessorComponent.getSubstitutionSuggestions(fragment));
}
Map<String, Object> model = new HashMap<String, Object>();
model.put(SUBSTITUTIONS_MODEL_KEY, substitutionSuggestions);
return model;
}
/**
* Return a list of path suggestions for the path fragment supplied.
*
* @param path
* @param fragment
* @return
*/
private List<String> getSubPathSuggestions(WebScriptRequest req, final String path, final String fragment, boolean unfiled) {
List<String> pathSuggestions = new ArrayList<String>();
if((path != null) && path.startsWith("/") && (fragment != null))
{
String[] pathFragments = path.split("/");
NodeRef currentNode = getFilePlan(req, unfiled);
for(String pathFragment : pathFragments)
{
// ignore empty elements of the path produced by split
if(!pathFragment.isEmpty())
{
boolean foundThisPathFragment = false;
List<ChildAssociationRef> children = nodeService.getChildAssocs(currentNode);
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
String fileName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
if(fileName.equals(pathFragment) && isNodeRefAppropriateForPathSuggestion(childNodeRef, unfiled))
{
foundThisPathFragment = true;
currentNode = childNodeRef;
break;
}
}
if(!foundThisPathFragment)
{
currentNode = null;
break;
}
}
}
if(currentNode != null)
{
String lowerCaseFragment = fragment.toLowerCase();
List<ChildAssociationRef> children = nodeService.getChildAssocs(currentNode);
for (ChildAssociationRef childAssoc : children) {
NodeRef childNodeRef = childAssoc.getChildRef();
String fileName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
if((fragment.isEmpty() || fileName.toLowerCase().startsWith(lowerCaseFragment)) && isNodeRefAppropriateForPathSuggestion(childNodeRef, unfiled))
{
pathSuggestions.add("/" + fileName);
if(pathSuggestions.size() >= pathSubstitutionMaximumNumberSuggestions)
{
break;
}
}
}
}
}
return pathSuggestions;
}
/**
* Utility method to get the file plan from the passed parameters.
*
* @param req
* @return
*/
protected NodeRef getFilePlan(WebScriptRequest req, boolean unfiled)
{
NodeRef filePlan = null;
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String siteId = templateVars.get("siteid");
if (siteId != null)
{
filePlan = filePlanService.getFilePlanBySiteId(siteId);
}
if (filePlan == null)
{
String storeType = templateVars.get("store_type");
String storeId = templateVars.get("store_id");
String id = templateVars.get("id");
if (!StringUtils.isEmpty(storeType) &&
!StringUtils.isEmpty(storeId) &&
!StringUtils.isEmpty(id))
{
StoreRef storeRef = new StoreRef(storeType, storeId);
NodeRef nodeRef = new NodeRef(storeRef, id);
if (filePlanService.isFilePlan(nodeRef))
{
filePlan = nodeRef;
}
}
}
if (filePlan == null)
{
// Assume we are in a legacy repository and we will grab the default file plan
filePlan = filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
}
return unfiled ? filePlanService.getUnfiledContainer(filePlan) : filePlan;
}
/**
* Identifies record category and record folder types of nodeRef
*
* @param nodeRef Instance of NodeRef to be tested
* @return True if the passed NodeRef instance is a record category or record folder
*/
private boolean isNodeRefAppropriateForPathSuggestion(NodeRef nodeRef, boolean unfiled)
{
// check node type
QName type = nodeService.getType(nodeRef);
boolean isCorrectType = (!unfiled
&& (RecordsManagementModel.TYPE_RECORD_FOLDER.equals(type) || RecordsManagementModel.TYPE_RECORD_CATEGORY
.equals(type)) || (unfiled && RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(type)));
// check permissions
boolean canView = false;
if(isCorrectType)
{
Capability createCapability = capabilityService.getCapability(CREATE_CAPABILITY);
Capability viewCapability = capabilityService.getCapability(VIEW_CAPABILITY);
if ((createCapability != null) && (viewCapability != null))
{
List<String> requiredCapabilities = new ArrayList<String>();
requiredCapabilities.add(CREATE_CAPABILITY);
requiredCapabilities.add(VIEW_CAPABILITY);
Map<Capability, AccessStatus> map = capabilityService.getCapabilitiesAccessState(nodeRef, requiredCapabilities);
if (map.containsKey(createCapability) && map.containsKey(viewCapability))
{
AccessStatus createAccessStatus = map.get(createCapability);
AccessStatus viewAccessStatus = map.get(viewCapability);
if (createAccessStatus.equals(AccessStatus.ALLOWED) && viewAccessStatus.equals(AccessStatus.ALLOWED))
{
canView = true;
}
}
}
}
return isCorrectType && canView;
}
}