mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Let git handle line endings for us.
This commit is contained in:
@@ -1,132 +1,132 @@
|
||||
/*
|
||||
* 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.action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionDefinition;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
|
||||
import org.alfresco.service.cmr.action.ActionConditionDefinition;
|
||||
import org.alfresco.service.cmr.action.ActionDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* Extended action service implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedActionServiceImpl extends ActionServiceImpl implements ApplicationContextAware
|
||||
{
|
||||
/** File plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
/** Application context */
|
||||
private ApplicationContext extendedApplicationContext;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.ActionServiceImpl#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
{
|
||||
super.setApplicationContext(applicationContext);
|
||||
extendedApplicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filePlanService file plan service
|
||||
*/
|
||||
public void setFilePlanService(FilePlanService filePlanService)
|
||||
{
|
||||
this.filePlanService = filePlanService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.ActionServiceImpl#getActionConditionDefinition(java.lang.String)
|
||||
*/
|
||||
public ActionConditionDefinition getActionConditionDefinition(String name)
|
||||
{
|
||||
// get direct access to action condition definition (i.e. ignoring public flag of executer)
|
||||
ActionConditionDefinition definition = null;
|
||||
Object bean = extendedApplicationContext.getBean(name);
|
||||
if (bean instanceof ActionConditionEvaluator)
|
||||
{
|
||||
ActionConditionEvaluator evaluator = (ActionConditionEvaluator) bean;
|
||||
definition = evaluator.getActionConditionDefintion();
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.ActionServiceImpl#getActionDefinitions(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public List<ActionDefinition> getActionDefinitions(NodeRef nodeRef)
|
||||
{
|
||||
List<ActionDefinition> result = null;
|
||||
|
||||
// first use the base implementation to get the list of action definitions
|
||||
List<ActionDefinition> actionDefinitions = super.getActionDefinitions(nodeRef);
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
// nothing to filter
|
||||
result = actionDefinitions;
|
||||
}
|
||||
else
|
||||
{
|
||||
// get the file component kind of the node reference
|
||||
FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(nodeRef);
|
||||
result = new ArrayList<ActionDefinition>(actionDefinitions.size());
|
||||
|
||||
// check each action definition
|
||||
for (ActionDefinition actionDefinition : actionDefinitions)
|
||||
{
|
||||
if (actionDefinition instanceof RecordsManagementActionDefinition)
|
||||
{
|
||||
if (kind != null)
|
||||
{
|
||||
Set<FilePlanComponentKind> applicableKinds = ((RecordsManagementActionDefinition)actionDefinition).getApplicableKinds();
|
||||
if (applicableKinds == null || applicableKinds.size() == 0 || applicableKinds.contains(kind))
|
||||
{
|
||||
// an RM action can only act on a RM artifact
|
||||
result.add(actionDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kind == null)
|
||||
{
|
||||
// a non-RM action can only act on a non-RM artifact
|
||||
result.add(actionDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionDefinition;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
|
||||
import org.alfresco.service.cmr.action.ActionConditionDefinition;
|
||||
import org.alfresco.service.cmr.action.ActionDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* Extended action service implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedActionServiceImpl extends ActionServiceImpl implements ApplicationContextAware
|
||||
{
|
||||
/** File plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
/** Application context */
|
||||
private ApplicationContext extendedApplicationContext;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.ActionServiceImpl#setApplicationContext(org.springframework.context.ApplicationContext)
|
||||
*/
|
||||
public void setApplicationContext(ApplicationContext applicationContext)
|
||||
{
|
||||
super.setApplicationContext(applicationContext);
|
||||
extendedApplicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filePlanService file plan service
|
||||
*/
|
||||
public void setFilePlanService(FilePlanService filePlanService)
|
||||
{
|
||||
this.filePlanService = filePlanService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.ActionServiceImpl#getActionConditionDefinition(java.lang.String)
|
||||
*/
|
||||
public ActionConditionDefinition getActionConditionDefinition(String name)
|
||||
{
|
||||
// get direct access to action condition definition (i.e. ignoring public flag of executer)
|
||||
ActionConditionDefinition definition = null;
|
||||
Object bean = extendedApplicationContext.getBean(name);
|
||||
if (bean instanceof ActionConditionEvaluator)
|
||||
{
|
||||
ActionConditionEvaluator evaluator = (ActionConditionEvaluator) bean;
|
||||
definition = evaluator.getActionConditionDefintion();
|
||||
}
|
||||
return definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.ActionServiceImpl#getActionDefinitions(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public List<ActionDefinition> getActionDefinitions(NodeRef nodeRef)
|
||||
{
|
||||
List<ActionDefinition> result = null;
|
||||
|
||||
// first use the base implementation to get the list of action definitions
|
||||
List<ActionDefinition> actionDefinitions = super.getActionDefinitions(nodeRef);
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
// nothing to filter
|
||||
result = actionDefinitions;
|
||||
}
|
||||
else
|
||||
{
|
||||
// get the file component kind of the node reference
|
||||
FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(nodeRef);
|
||||
result = new ArrayList<ActionDefinition>(actionDefinitions.size());
|
||||
|
||||
// check each action definition
|
||||
for (ActionDefinition actionDefinition : actionDefinitions)
|
||||
{
|
||||
if (actionDefinition instanceof RecordsManagementActionDefinition)
|
||||
{
|
||||
if (kind != null)
|
||||
{
|
||||
Set<FilePlanComponentKind> applicableKinds = ((RecordsManagementActionDefinition)actionDefinition).getApplicableKinds();
|
||||
if (applicableKinds == null || applicableKinds.size() == 0 || applicableKinds.contains(kind))
|
||||
{
|
||||
// an RM action can only act on a RM artifact
|
||||
result.add(actionDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kind == null)
|
||||
{
|
||||
// a non-RM action can only act on a non-RM artifact
|
||||
result.add(actionDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -1,248 +1,248 @@
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* Date parameter processor.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DateParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
|
||||
{
|
||||
private static final String DAY = "day";
|
||||
private static final String WEEK = "week";
|
||||
private static final String MONTH = "month";
|
||||
private static final String YEAR = "year";
|
||||
private static final String SHORT = "short";
|
||||
private static final String LONG = "long";
|
||||
private static final String NUMBER = "number";
|
||||
|
||||
private static final String SEP = ".";
|
||||
|
||||
private static final String[] ALL_FIELDS_FOR_SUBSTITUTION_QUERY = {
|
||||
DAY + SEP + SHORT,
|
||||
DAY,
|
||||
DAY + SEP + LONG,
|
||||
DAY + SEP + NUMBER,
|
||||
DAY + SEP + MONTH,
|
||||
DAY + SEP + YEAR,
|
||||
MONTH + SEP + SHORT,
|
||||
MONTH,
|
||||
MONTH + SEP + LONG,
|
||||
MONTH + SEP + NUMBER,
|
||||
YEAR + SEP + SHORT,
|
||||
YEAR,
|
||||
YEAR + SEP + LONG,
|
||||
YEAR + SEP + WEEK
|
||||
};
|
||||
|
||||
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public String process(String value, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
// the default position is to return the value un-changed
|
||||
String result = value;
|
||||
|
||||
// strip the processor name from the value
|
||||
value = stripName(value);
|
||||
|
||||
if (!value.isEmpty())
|
||||
{
|
||||
String[] values = value.split("\\.", 2);
|
||||
String field = values[0].trim();
|
||||
|
||||
if (DAY.equalsIgnoreCase(field))
|
||||
{
|
||||
result = handleDay(values);
|
||||
}
|
||||
else if (MONTH.equalsIgnoreCase(field))
|
||||
{
|
||||
result = handleMonth(values);
|
||||
}
|
||||
else if (YEAR.equalsIgnoreCase(field))
|
||||
{
|
||||
result = handleYear(values);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Cannot process the field '" + field + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String handleDay(String[] values)
|
||||
{
|
||||
String style = getStyle(values);
|
||||
String pattern;
|
||||
|
||||
if (SHORT.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "EE";
|
||||
}
|
||||
else if (LONG.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "EEEE";
|
||||
}
|
||||
else if (NUMBER.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "uu";
|
||||
}
|
||||
else if (MONTH.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "dd";
|
||||
}
|
||||
else if (YEAR.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "DDD";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The pattern 'date.day." + style + "' is not supported!");
|
||||
}
|
||||
|
||||
return new SimpleDateFormat(pattern).format(new Date());
|
||||
}
|
||||
|
||||
private String handleMonth(String[] values)
|
||||
{
|
||||
String style = getStyle(values);
|
||||
String pattern;
|
||||
|
||||
if (SHORT.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "MMM";
|
||||
}
|
||||
else if (LONG.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "MMMM";
|
||||
}
|
||||
else if (NUMBER.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "MM";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The pattern 'date.month." + style + "' is not supported!");
|
||||
}
|
||||
|
||||
return new SimpleDateFormat(pattern).format(new Date());
|
||||
}
|
||||
|
||||
private String handleYear(String[] values)
|
||||
{
|
||||
String style = getStyle(values);
|
||||
String pattern;
|
||||
|
||||
if (SHORT.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "yy";
|
||||
}
|
||||
else if (LONG.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "yyyy";
|
||||
}
|
||||
else if (WEEK.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "ww";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The pattern 'date.year." + style + "' is not supported!");
|
||||
}
|
||||
|
||||
return new SimpleDateFormat(pattern).format(new Date());
|
||||
}
|
||||
|
||||
private String getStyle(String[] values)
|
||||
{
|
||||
String style;
|
||||
|
||||
if (values.length == 1)
|
||||
{
|
||||
style = SHORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
style = values[1].trim();
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maxmimum number of suggestions returned from the global property
|
||||
*
|
||||
* @param maximumNumberSuggestions
|
||||
*/
|
||||
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
|
||||
{
|
||||
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSubstitutionSuggestions(String substitutionFragment)
|
||||
{
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
String namePrefix = this.getName() + ".";
|
||||
if(StringUtils.isBlank(substitutionFragment) || this.getName().toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
suggestions.add(namePrefix + field);
|
||||
if(suggestions.size() >= maximumNumberSuggestions)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
String prefixFieldName = namePrefix + field;
|
||||
if(prefixFieldName.toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
suggestions.add(namePrefix + field);
|
||||
if(suggestions.size() >= maximumNumberSuggestions)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* Date parameter processor.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class DateParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
|
||||
{
|
||||
private static final String DAY = "day";
|
||||
private static final String WEEK = "week";
|
||||
private static final String MONTH = "month";
|
||||
private static final String YEAR = "year";
|
||||
private static final String SHORT = "short";
|
||||
private static final String LONG = "long";
|
||||
private static final String NUMBER = "number";
|
||||
|
||||
private static final String SEP = ".";
|
||||
|
||||
private static final String[] ALL_FIELDS_FOR_SUBSTITUTION_QUERY = {
|
||||
DAY + SEP + SHORT,
|
||||
DAY,
|
||||
DAY + SEP + LONG,
|
||||
DAY + SEP + NUMBER,
|
||||
DAY + SEP + MONTH,
|
||||
DAY + SEP + YEAR,
|
||||
MONTH + SEP + SHORT,
|
||||
MONTH,
|
||||
MONTH + SEP + LONG,
|
||||
MONTH + SEP + NUMBER,
|
||||
YEAR + SEP + SHORT,
|
||||
YEAR,
|
||||
YEAR + SEP + LONG,
|
||||
YEAR + SEP + WEEK
|
||||
};
|
||||
|
||||
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public String process(String value, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
// the default position is to return the value un-changed
|
||||
String result = value;
|
||||
|
||||
// strip the processor name from the value
|
||||
value = stripName(value);
|
||||
|
||||
if (!value.isEmpty())
|
||||
{
|
||||
String[] values = value.split("\\.", 2);
|
||||
String field = values[0].trim();
|
||||
|
||||
if (DAY.equalsIgnoreCase(field))
|
||||
{
|
||||
result = handleDay(values);
|
||||
}
|
||||
else if (MONTH.equalsIgnoreCase(field))
|
||||
{
|
||||
result = handleMonth(values);
|
||||
}
|
||||
else if (YEAR.equalsIgnoreCase(field))
|
||||
{
|
||||
result = handleYear(values);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Cannot process the field '" + field + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String handleDay(String[] values)
|
||||
{
|
||||
String style = getStyle(values);
|
||||
String pattern;
|
||||
|
||||
if (SHORT.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "EE";
|
||||
}
|
||||
else if (LONG.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "EEEE";
|
||||
}
|
||||
else if (NUMBER.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "uu";
|
||||
}
|
||||
else if (MONTH.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "dd";
|
||||
}
|
||||
else if (YEAR.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "DDD";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The pattern 'date.day." + style + "' is not supported!");
|
||||
}
|
||||
|
||||
return new SimpleDateFormat(pattern).format(new Date());
|
||||
}
|
||||
|
||||
private String handleMonth(String[] values)
|
||||
{
|
||||
String style = getStyle(values);
|
||||
String pattern;
|
||||
|
||||
if (SHORT.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "MMM";
|
||||
}
|
||||
else if (LONG.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "MMMM";
|
||||
}
|
||||
else if (NUMBER.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "MM";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The pattern 'date.month." + style + "' is not supported!");
|
||||
}
|
||||
|
||||
return new SimpleDateFormat(pattern).format(new Date());
|
||||
}
|
||||
|
||||
private String handleYear(String[] values)
|
||||
{
|
||||
String style = getStyle(values);
|
||||
String pattern;
|
||||
|
||||
if (SHORT.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "yy";
|
||||
}
|
||||
else if (LONG.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "yyyy";
|
||||
}
|
||||
else if (WEEK.equalsIgnoreCase(style))
|
||||
{
|
||||
pattern = "ww";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The pattern 'date.year." + style + "' is not supported!");
|
||||
}
|
||||
|
||||
return new SimpleDateFormat(pattern).format(new Date());
|
||||
}
|
||||
|
||||
private String getStyle(String[] values)
|
||||
{
|
||||
String style;
|
||||
|
||||
if (values.length == 1)
|
||||
{
|
||||
style = SHORT;
|
||||
}
|
||||
else
|
||||
{
|
||||
style = values[1].trim();
|
||||
}
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maxmimum number of suggestions returned from the global property
|
||||
*
|
||||
* @param maximumNumberSuggestions
|
||||
*/
|
||||
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
|
||||
{
|
||||
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSubstitutionSuggestions(String substitutionFragment)
|
||||
{
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
String namePrefix = this.getName() + ".";
|
||||
if(StringUtils.isBlank(substitutionFragment) || this.getName().toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
suggestions.add(namePrefix + field);
|
||||
if(suggestions.size() >= maximumNumberSuggestions)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(String field: ALL_FIELDS_FOR_SUBSTITUTION_QUERY) {
|
||||
String prefixFieldName = namePrefix + field;
|
||||
if(prefixFieldName.toLowerCase().contains(substitutionFragment.toLowerCase()))
|
||||
{
|
||||
suggestions.add(namePrefix + field);
|
||||
if(suggestions.size() >= maximumNumberSuggestions)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
@@ -1,55 +1,55 @@
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Message parameter processor.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class MessageParameterProcessor extends ParameterProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public String process(String value, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
// the default position is to return the value un-changed
|
||||
String result = value;
|
||||
|
||||
// strip the processor name from the value
|
||||
value = stripName(value);
|
||||
if (!value.isEmpty())
|
||||
{
|
||||
result = I18NUtil.getMessage(value);
|
||||
if (result == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The message parameter processor could not resolve the message for the id " + value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* Message parameter processor.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class MessageParameterProcessor extends ParameterProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public String process(String value, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
// the default position is to return the value un-changed
|
||||
String result = value;
|
||||
|
||||
// strip the processor name from the value
|
||||
value = stripName(value);
|
||||
if (!value.isEmpty())
|
||||
{
|
||||
result = I18NUtil.getMessage(value);
|
||||
if (result == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The message parameter processor could not resolve the message for the id " + value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -1,294 +1,294 @@
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
/**
|
||||
* Node parameter processor.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class NodeParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
|
||||
{
|
||||
/** Supported data types */
|
||||
private QName[] supportedDataTypes =
|
||||
{
|
||||
DataTypeDefinition.TEXT,
|
||||
DataTypeDefinition.BOOLEAN,
|
||||
DataTypeDefinition.DATE,
|
||||
DataTypeDefinition.DATETIME,
|
||||
DataTypeDefinition.DOUBLE,
|
||||
DataTypeDefinition.FLOAT,
|
||||
DataTypeDefinition.INT,
|
||||
DataTypeDefinition.MLTEXT
|
||||
};
|
||||
|
||||
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
|
||||
|
||||
/** Node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Namespace service */
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
/** Dictionary service */
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
/** Records management admin service */
|
||||
private RecordsManagementAdminService recordsManagementAdminService;
|
||||
|
||||
/** List of definitions (aspects and types) to use for substitution suggestions */
|
||||
private List<QName> suggestionDefinitions = null;
|
||||
|
||||
/**
|
||||
* @param nodeService node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespaceService namespace service
|
||||
*/
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService dictionary service
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordsManagementAdminService Records management admin service
|
||||
*/
|
||||
public void setRecordsManagementAdminService(RecordsManagementAdminService recordsManagementAdminService)
|
||||
{
|
||||
this.recordsManagementAdminService = recordsManagementAdminService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public String process(String value, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
// the default position is to return the value un-changed
|
||||
String result = value;
|
||||
|
||||
// strip the processor name from the value
|
||||
value = stripName(value);
|
||||
if (!value.isEmpty())
|
||||
{
|
||||
QName qname = QName.createQName(value, namespaceService);
|
||||
|
||||
PropertyDefinition propertyDefinition = dictionaryService.getProperty(qname);
|
||||
if (propertyDefinition == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The property " + value + " does not have a property definition.");
|
||||
}
|
||||
|
||||
QName type = propertyDefinition.getDataType().getName();
|
||||
if (ArrayUtils.contains(supportedDataTypes, type))
|
||||
{
|
||||
Serializable propertyValue = nodeService.getProperty(actionedUponNodeRef, qname);
|
||||
if (propertyValue != null)
|
||||
{
|
||||
result = propertyValue.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the result to the empty string
|
||||
result = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The property " + value + " is of type " + type.toString() + " which is not supported by parameter substitution.");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maxmimum number of suggestions returned from the global property
|
||||
*
|
||||
* @param maximumNumberSuggestions
|
||||
*/
|
||||
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
|
||||
{
|
||||
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add suggestion definition to the list used to get properties suggestions from.
|
||||
*
|
||||
* @param definition Type or aspect
|
||||
*/
|
||||
public void addSuggestionDefinition(QName definition)
|
||||
{
|
||||
if(this.suggestionDefinitions == null)
|
||||
{
|
||||
this.suggestionDefinitions = Collections.synchronizedList(new ArrayList<QName>());
|
||||
}
|
||||
this.suggestionDefinitions.add(definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of node substitution suggestions for the specified fragment.
|
||||
*
|
||||
* @param substitutionFragment The fragment to search for
|
||||
* @returns A list of node substitution suggestions, for example 'node.cm:title'
|
||||
*
|
||||
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSubstitutionSuggestions(String substitutionFragment)
|
||||
{
|
||||
Set<String> suggestionSet = Collections.synchronizedSet(new HashSet<String>());
|
||||
if(this.suggestionDefinitions != null)
|
||||
{
|
||||
for(QName definition : this.suggestionDefinitions)
|
||||
{
|
||||
if(getSubstitutionSuggestions(definition, substitutionFragment.toLowerCase(), suggestionSet))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
suggestions.addAll(suggestionSet);
|
||||
Collections.sort(suggestions);
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of node substitution suggestions for the given definition and specified fragment.
|
||||
*
|
||||
* @param definitionName Definition (aspect or type) to get properties of and the call this method for associated aspects
|
||||
* @param substitutionFragment Substitution fragment to search for
|
||||
* @param suggestions The current list of suggestions to which we will add newly found suggestions
|
||||
*/
|
||||
private boolean getSubstitutionSuggestions(QName definitionName, String substitutionFragment, Set<String> suggestions)
|
||||
{
|
||||
boolean gotMaximumSuggestions = false;
|
||||
ClassDefinition definition = this.dictionaryService.getAspect(definitionName);
|
||||
if(definition == null)
|
||||
{
|
||||
definition = this.dictionaryService.getType(definitionName);
|
||||
}
|
||||
if(definition != null)
|
||||
{
|
||||
gotMaximumSuggestions = getSubstitutionSuggestionsForDefinition(definition, substitutionFragment, suggestions);
|
||||
}
|
||||
if(recordsManagementAdminService.isCustomisable(definitionName) && !gotMaximumSuggestions)
|
||||
{
|
||||
gotMaximumSuggestions = processPropertyDefinitions(recordsManagementAdminService.getCustomPropertyDefinitions(definitionName), substitutionFragment, suggestions);
|
||||
}
|
||||
return gotMaximumSuggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of node substitution suggestions for the given definition and specified fragment. Calls itself recursively for
|
||||
* associated aspects.
|
||||
*
|
||||
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
|
||||
* @param substitutionFragment Substitution fragment to search for
|
||||
* @param suggestions The current list of suggestions to which we will add newly found suggestions
|
||||
*/
|
||||
private boolean getSubstitutionSuggestionsForDefinition(ClassDefinition definition, String substitutionFragment, Set<String> suggestions)
|
||||
{
|
||||
boolean gotMaximumSuggestions = processPropertyDefinitions(definition.getProperties(), substitutionFragment, suggestions);
|
||||
if(!gotMaximumSuggestions)
|
||||
{
|
||||
for(QName defaultAspect : definition.getDefaultAspectNames())
|
||||
{
|
||||
gotMaximumSuggestions = getSubstitutionSuggestions(defaultAspect, substitutionFragment, suggestions);
|
||||
if(gotMaximumSuggestions)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return gotMaximumSuggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the supplied map of property definitions and add the ones that match the supplied fragment to the list of suggestions.
|
||||
*
|
||||
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
|
||||
* @param substitutionFragment Substitution fragment to search for
|
||||
* @param suggestions The current list of suggestions to which we will add newly found suggestions
|
||||
*/
|
||||
private boolean processPropertyDefinitions(Map<QName, PropertyDefinition> properties, String substitutionFragment, Set<String> suggestions)
|
||||
{
|
||||
boolean gotMaximumSuggestions = false;
|
||||
if (properties != null)
|
||||
{
|
||||
for (Map.Entry<QName, PropertyDefinition> entry : properties.entrySet())
|
||||
{
|
||||
PropertyDefinition propertyDefinition = entry.getValue();
|
||||
QName type = propertyDefinition.getDataType().getName();
|
||||
if(ArrayUtils.contains(supportedDataTypes, type))
|
||||
{
|
||||
String suggestion = getName() + "." + entry.getKey().getPrefixString();
|
||||
if(suggestion.toLowerCase().contains(substitutionFragment))
|
||||
{
|
||||
if(suggestions.size() < this.maximumNumberSuggestions)
|
||||
{
|
||||
suggestions.add(suggestion);
|
||||
}
|
||||
else
|
||||
{
|
||||
gotMaximumSuggestions = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return gotMaximumSuggestions;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
/**
|
||||
* Node parameter processor.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class NodeParameterProcessor extends ParameterProcessor implements ParameterSubstitutionSuggester
|
||||
{
|
||||
/** Supported data types */
|
||||
private QName[] supportedDataTypes =
|
||||
{
|
||||
DataTypeDefinition.TEXT,
|
||||
DataTypeDefinition.BOOLEAN,
|
||||
DataTypeDefinition.DATE,
|
||||
DataTypeDefinition.DATETIME,
|
||||
DataTypeDefinition.DOUBLE,
|
||||
DataTypeDefinition.FLOAT,
|
||||
DataTypeDefinition.INT,
|
||||
DataTypeDefinition.MLTEXT
|
||||
};
|
||||
|
||||
private int maximumNumberSuggestions = DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS;
|
||||
|
||||
/** Node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Namespace service */
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
/** Dictionary service */
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
/** Records management admin service */
|
||||
private RecordsManagementAdminService recordsManagementAdminService;
|
||||
|
||||
/** List of definitions (aspects and types) to use for substitution suggestions */
|
||||
private List<QName> suggestionDefinitions = null;
|
||||
|
||||
/**
|
||||
* @param nodeService node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespaceService namespace service
|
||||
*/
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService dictionary service
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordsManagementAdminService Records management admin service
|
||||
*/
|
||||
public void setRecordsManagementAdminService(RecordsManagementAdminService recordsManagementAdminService)
|
||||
{
|
||||
this.recordsManagementAdminService = recordsManagementAdminService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public String process(String value, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
// the default position is to return the value un-changed
|
||||
String result = value;
|
||||
|
||||
// strip the processor name from the value
|
||||
value = stripName(value);
|
||||
if (!value.isEmpty())
|
||||
{
|
||||
QName qname = QName.createQName(value, namespaceService);
|
||||
|
||||
PropertyDefinition propertyDefinition = dictionaryService.getProperty(qname);
|
||||
if (propertyDefinition == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The property " + value + " does not have a property definition.");
|
||||
}
|
||||
|
||||
QName type = propertyDefinition.getDataType().getName();
|
||||
if (ArrayUtils.contains(supportedDataTypes, type))
|
||||
{
|
||||
Serializable propertyValue = nodeService.getProperty(actionedUponNodeRef, qname);
|
||||
if (propertyValue != null)
|
||||
{
|
||||
result = propertyValue.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the result to the empty string
|
||||
result = "";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("The property " + value + " is of type " + type.toString() + " which is not supported by parameter substitution.");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maxmimum number of suggestions returned from the global property
|
||||
*
|
||||
* @param maximumNumberSuggestions
|
||||
*/
|
||||
public void setMaximumNumberSuggestions(int maximumNumberSuggestions)
|
||||
{
|
||||
this.maximumNumberSuggestions = (maximumNumberSuggestions <= 0 ? DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS: maximumNumberSuggestions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add suggestion definition to the list used to get properties suggestions from.
|
||||
*
|
||||
* @param definition Type or aspect
|
||||
*/
|
||||
public void addSuggestionDefinition(QName definition)
|
||||
{
|
||||
if(this.suggestionDefinitions == null)
|
||||
{
|
||||
this.suggestionDefinitions = Collections.synchronizedList(new ArrayList<QName>());
|
||||
}
|
||||
this.suggestionDefinitions.add(definition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of node substitution suggestions for the specified fragment.
|
||||
*
|
||||
* @param substitutionFragment The fragment to search for
|
||||
* @returns A list of node substitution suggestions, for example 'node.cm:title'
|
||||
*
|
||||
* @see org.alfresco.repo.action.parameter.ParameterSubstitutionSuggester#getSubstitutionSuggestions(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSubstitutionSuggestions(String substitutionFragment)
|
||||
{
|
||||
Set<String> suggestionSet = Collections.synchronizedSet(new HashSet<String>());
|
||||
if(this.suggestionDefinitions != null)
|
||||
{
|
||||
for(QName definition : this.suggestionDefinitions)
|
||||
{
|
||||
if(getSubstitutionSuggestions(definition, substitutionFragment.toLowerCase(), suggestionSet))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
suggestions.addAll(suggestionSet);
|
||||
Collections.sort(suggestions);
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of node substitution suggestions for the given definition and specified fragment.
|
||||
*
|
||||
* @param definitionName Definition (aspect or type) to get properties of and the call this method for associated aspects
|
||||
* @param substitutionFragment Substitution fragment to search for
|
||||
* @param suggestions The current list of suggestions to which we will add newly found suggestions
|
||||
*/
|
||||
private boolean getSubstitutionSuggestions(QName definitionName, String substitutionFragment, Set<String> suggestions)
|
||||
{
|
||||
boolean gotMaximumSuggestions = false;
|
||||
ClassDefinition definition = this.dictionaryService.getAspect(definitionName);
|
||||
if(definition == null)
|
||||
{
|
||||
definition = this.dictionaryService.getType(definitionName);
|
||||
}
|
||||
if(definition != null)
|
||||
{
|
||||
gotMaximumSuggestions = getSubstitutionSuggestionsForDefinition(definition, substitutionFragment, suggestions);
|
||||
}
|
||||
if(recordsManagementAdminService.isCustomisable(definitionName) && !gotMaximumSuggestions)
|
||||
{
|
||||
gotMaximumSuggestions = processPropertyDefinitions(recordsManagementAdminService.getCustomPropertyDefinitions(definitionName), substitutionFragment, suggestions);
|
||||
}
|
||||
return gotMaximumSuggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of node substitution suggestions for the given definition and specified fragment. Calls itself recursively for
|
||||
* associated aspects.
|
||||
*
|
||||
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
|
||||
* @param substitutionFragment Substitution fragment to search for
|
||||
* @param suggestions The current list of suggestions to which we will add newly found suggestions
|
||||
*/
|
||||
private boolean getSubstitutionSuggestionsForDefinition(ClassDefinition definition, String substitutionFragment, Set<String> suggestions)
|
||||
{
|
||||
boolean gotMaximumSuggestions = processPropertyDefinitions(definition.getProperties(), substitutionFragment, suggestions);
|
||||
if(!gotMaximumSuggestions)
|
||||
{
|
||||
for(QName defaultAspect : definition.getDefaultAspectNames())
|
||||
{
|
||||
gotMaximumSuggestions = getSubstitutionSuggestions(defaultAspect, substitutionFragment, suggestions);
|
||||
if(gotMaximumSuggestions)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return gotMaximumSuggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the supplied map of property definitions and add the ones that match the supplied fragment to the list of suggestions.
|
||||
*
|
||||
* @param definition Definition (aspect or type) to get properties of and the call this method for associated aspects
|
||||
* @param substitutionFragment Substitution fragment to search for
|
||||
* @param suggestions The current list of suggestions to which we will add newly found suggestions
|
||||
*/
|
||||
private boolean processPropertyDefinitions(Map<QName, PropertyDefinition> properties, String substitutionFragment, Set<String> suggestions)
|
||||
{
|
||||
boolean gotMaximumSuggestions = false;
|
||||
if (properties != null)
|
||||
{
|
||||
for (Map.Entry<QName, PropertyDefinition> entry : properties.entrySet())
|
||||
{
|
||||
PropertyDefinition propertyDefinition = entry.getValue();
|
||||
QName type = propertyDefinition.getDataType().getName();
|
||||
if(ArrayUtils.contains(supportedDataTypes, type))
|
||||
{
|
||||
String suggestion = getName() + "." + entry.getKey().getPrefixString();
|
||||
if(suggestion.toLowerCase().contains(substitutionFragment))
|
||||
{
|
||||
if(suggestions.size() < this.maximumNumberSuggestions)
|
||||
{
|
||||
suggestions.add(suggestion);
|
||||
}
|
||||
else
|
||||
{
|
||||
gotMaximumSuggestions = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return gotMaximumSuggestions;
|
||||
}
|
||||
}
|
||||
|
@@ -1,92 +1,92 @@
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* Record metadata bootstrap bean.
|
||||
* <p>
|
||||
* This method of bootstrapping record metadata aspects into the RecordService deprecates the
|
||||
* previous practice of extending rma:recordMetaData.
|
||||
*
|
||||
* @author Mark Hibbins
|
||||
* @since 2.2
|
||||
*/
|
||||
public class NodeParameterSuggesterBootstrap
|
||||
{
|
||||
/** namespace service */
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
/** configured node parameter processor aspect and type names, comma separated */
|
||||
private String nodeParameterProcessorAspectsNames;
|
||||
|
||||
/** node parameter processor */
|
||||
private NodeParameterProcessor nodeParameterProcessor;
|
||||
|
||||
/**
|
||||
* @param recordMetadataAspects map of record metadata aspects against file plan types
|
||||
*/
|
||||
public void setNodeParameterProcessorAspects(String nodeParameterProcessorAspectsNames)
|
||||
{
|
||||
this.nodeParameterProcessorAspectsNames = nodeParameterProcessorAspectsNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespaceService namespace service
|
||||
*/
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeParameterProcessor Node parameter processor
|
||||
*/
|
||||
public void setNodeParameterProcessor(NodeParameterProcessor nodeParameterProcessor)
|
||||
{
|
||||
this.nodeParameterProcessor = nodeParameterProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
ParameterCheck.mandatory("namespaceService", namespaceService);
|
||||
|
||||
if (nodeParameterProcessorAspectsNames != null)
|
||||
{
|
||||
String[] aspectsNames = this.nodeParameterProcessorAspectsNames.split(",");
|
||||
for (String name : aspectsNames)
|
||||
{
|
||||
if((name != null) && !"".equals(name.trim()))
|
||||
{
|
||||
// convert to qname and save it
|
||||
QName aspect = QName.createQName(name.trim(), namespaceService);
|
||||
|
||||
// register with node parameter processor
|
||||
this.nodeParameterProcessor.addSuggestionDefinition(aspect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* Record metadata bootstrap bean.
|
||||
* <p>
|
||||
* This method of bootstrapping record metadata aspects into the RecordService deprecates the
|
||||
* previous practice of extending rma:recordMetaData.
|
||||
*
|
||||
* @author Mark Hibbins
|
||||
* @since 2.2
|
||||
*/
|
||||
public class NodeParameterSuggesterBootstrap
|
||||
{
|
||||
/** namespace service */
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
/** configured node parameter processor aspect and type names, comma separated */
|
||||
private String nodeParameterProcessorAspectsNames;
|
||||
|
||||
/** node parameter processor */
|
||||
private NodeParameterProcessor nodeParameterProcessor;
|
||||
|
||||
/**
|
||||
* @param recordMetadataAspects map of record metadata aspects against file plan types
|
||||
*/
|
||||
public void setNodeParameterProcessorAspects(String nodeParameterProcessorAspectsNames)
|
||||
{
|
||||
this.nodeParameterProcessorAspectsNames = nodeParameterProcessorAspectsNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespaceService namespace service
|
||||
*/
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeParameterProcessor Node parameter processor
|
||||
*/
|
||||
public void setNodeParameterProcessor(NodeParameterProcessor nodeParameterProcessor)
|
||||
{
|
||||
this.nodeParameterProcessor = nodeParameterProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
ParameterCheck.mandatory("namespaceService", namespaceService);
|
||||
|
||||
if (nodeParameterProcessorAspectsNames != null)
|
||||
{
|
||||
String[] aspectsNames = this.nodeParameterProcessorAspectsNames.split(",");
|
||||
for (String name : aspectsNames)
|
||||
{
|
||||
if((name != null) && !"".equals(name.trim()))
|
||||
{
|
||||
// convert to qname and save it
|
||||
QName aspect = QName.createQName(name.trim(), namespaceService);
|
||||
|
||||
// register with node parameter processor
|
||||
this.nodeParameterProcessor.addSuggestionDefinition(aspect);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,94 +1,94 @@
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Abstract parameter processor implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public abstract class ParameterProcessor
|
||||
{
|
||||
/** Processor name */
|
||||
private String name;
|
||||
|
||||
/** Parameter processor component */
|
||||
private ParameterProcessorComponent parameterProcessorComponent;
|
||||
|
||||
/**
|
||||
* @return parameter processor name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name parameter processor name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameterProcessorComponent parameter processor component
|
||||
*/
|
||||
public void setParameterProcessorComponent(ParameterProcessorComponent parameterProcessorComponent)
|
||||
{
|
||||
this.parameterProcessorComponent = parameterProcessorComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
parameterProcessorComponent.register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the parameter value.
|
||||
*
|
||||
* @param value substitution value
|
||||
* @param actionedUponNodeRef actioned upon node reference
|
||||
* @return String processed string, original string if subs string invalid
|
||||
*/
|
||||
public abstract String process(String value, NodeRef actionedUponNodeRef);
|
||||
|
||||
/**
|
||||
* Strips the name of the processor from the subs value.
|
||||
*
|
||||
* @param value subs value
|
||||
* @return String subs value with the name and '.' delimiter removed
|
||||
*/
|
||||
protected String stripName(String value)
|
||||
{
|
||||
String result = "";
|
||||
String[] values = value.split("\\.", 2);
|
||||
if (values.length == 2)
|
||||
{
|
||||
result = values[1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Abstract parameter processor implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public abstract class ParameterProcessor
|
||||
{
|
||||
/** Processor name */
|
||||
private String name;
|
||||
|
||||
/** Parameter processor component */
|
||||
private ParameterProcessorComponent parameterProcessorComponent;
|
||||
|
||||
/**
|
||||
* @return parameter processor name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name parameter processor name
|
||||
*/
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameterProcessorComponent parameter processor component
|
||||
*/
|
||||
public void setParameterProcessorComponent(ParameterProcessorComponent parameterProcessorComponent)
|
||||
{
|
||||
this.parameterProcessorComponent = parameterProcessorComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
parameterProcessorComponent.register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the parameter value.
|
||||
*
|
||||
* @param value substitution value
|
||||
* @param actionedUponNodeRef actioned upon node reference
|
||||
* @return String processed string, original string if subs string invalid
|
||||
*/
|
||||
public abstract String process(String value, NodeRef actionedUponNodeRef);
|
||||
|
||||
/**
|
||||
* Strips the name of the processor from the subs value.
|
||||
*
|
||||
* @param value subs value
|
||||
* @return String subs value with the name and '.' delimiter removed
|
||||
*/
|
||||
protected String stripName(String value)
|
||||
{
|
||||
String result = "";
|
||||
String[] values = value.split("\\.", 2);
|
||||
if (values.length == 2)
|
||||
{
|
||||
result = values[1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -1,166 +1,166 @@
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.action.ParameterizedItem;
|
||||
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Parameter processor component
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ParameterProcessorComponent implements ParameterSubstitutionSuggester
|
||||
{
|
||||
/** regex used to parse parameters */
|
||||
private static final String REG_EX_OLD = "\\$\\{([^\\$\\{]+)\\}";
|
||||
private static final String REG_EX = "\\{([^\\{]+)\\}";
|
||||
|
||||
/** registry of parameter processors */
|
||||
private Map<String, ParameterProcessor> processors = new HashMap<String, ParameterProcessor>(5);
|
||||
private List<ParameterSubstitutionSuggester> subtitutionSuggesterProcessors = new ArrayList<ParameterSubstitutionSuggester>(5);
|
||||
|
||||
/**
|
||||
* Register parameter processor
|
||||
*
|
||||
* @param processor
|
||||
*/
|
||||
public void register(ParameterProcessor processor)
|
||||
{
|
||||
this.processors.put(processor.getName(), processor);
|
||||
if(processor instanceof ParameterSubstitutionSuggester)
|
||||
{
|
||||
this.subtitutionSuggesterProcessors.add((ParameterSubstitutionSuggester)processor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ruleItem
|
||||
* @param ruleItemDefinition
|
||||
* @param actionedUponNodeRef
|
||||
*/
|
||||
public void process(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
for (Map.Entry<String, Serializable> entry : ruleItem.getParameterValues().entrySet())
|
||||
{
|
||||
String parameterName = entry.getKey();
|
||||
Object parameterValue = entry.getValue();
|
||||
|
||||
// only sub string property values
|
||||
if (parameterValue instanceof String)
|
||||
{
|
||||
// set the updated parameter value
|
||||
ruleItem.setParameterValue(parameterName, process((String)parameterValue, actionedUponNodeRef));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the value for substitution within the context of the provided node.
|
||||
*
|
||||
* @param value value
|
||||
* @param nodeRef node reference
|
||||
* @return String resulting value
|
||||
*/
|
||||
public String process(String value, NodeRef nodeRef)
|
||||
{
|
||||
return process(process(value, nodeRef, REG_EX_OLD), nodeRef, REG_EX);
|
||||
}
|
||||
|
||||
public String process(String value, NodeRef nodeRef, String regExp)
|
||||
{
|
||||
// match the substitution pattern
|
||||
Pattern patt = Pattern.compile(regExp);
|
||||
Matcher m = patt.matcher(value);
|
||||
StringBuffer sb = new StringBuffer(value.length());
|
||||
|
||||
while (m.find())
|
||||
{
|
||||
String text = m.group(1);
|
||||
|
||||
// lookup parameter processor to use
|
||||
ParameterProcessor processor = lookupProcessor(text);
|
||||
if (processor == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("A parameter processor has not been found for the substitution string " + text);
|
||||
}
|
||||
else
|
||||
{
|
||||
// process each substitution value
|
||||
text = processor.process(text, nodeRef);
|
||||
}
|
||||
|
||||
// append new value
|
||||
m.appendReplacement(sb, Matcher.quoteReplacement(text));
|
||||
}
|
||||
m.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of substitution suggestions for the passed string fragment.
|
||||
*
|
||||
* @param subtitutionFragment Text fragment to search on.
|
||||
* @return A list of substitutions that match the substitution fragment.
|
||||
*/
|
||||
public List<String> getSubstitutionSuggestions(final String substitutionFragment)
|
||||
{
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
for (ParameterSubstitutionSuggester suggestor : this.subtitutionSuggesterProcessors)
|
||||
{
|
||||
suggestions.addAll(suggestor.getSubstitutionSuggestions(substitutionFragment.toLowerCase()));
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up parameter processor
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private ParameterProcessor lookupProcessor(String value)
|
||||
{
|
||||
ParameterProcessor result = null;
|
||||
|
||||
if (value != null && !value.isEmpty())
|
||||
{
|
||||
String[] values = value.split("\\.", 2);
|
||||
if (values.length != 0)
|
||||
{
|
||||
// get the processor from the registered map
|
||||
result = processors.get(values[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.service.cmr.action.ParameterizedItem;
|
||||
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Parameter processor component
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ParameterProcessorComponent implements ParameterSubstitutionSuggester
|
||||
{
|
||||
/** regex used to parse parameters */
|
||||
private static final String REG_EX_OLD = "\\$\\{([^\\$\\{]+)\\}";
|
||||
private static final String REG_EX = "\\{([^\\{]+)\\}";
|
||||
|
||||
/** registry of parameter processors */
|
||||
private Map<String, ParameterProcessor> processors = new HashMap<String, ParameterProcessor>(5);
|
||||
private List<ParameterSubstitutionSuggester> subtitutionSuggesterProcessors = new ArrayList<ParameterSubstitutionSuggester>(5);
|
||||
|
||||
/**
|
||||
* Register parameter processor
|
||||
*
|
||||
* @param processor
|
||||
*/
|
||||
public void register(ParameterProcessor processor)
|
||||
{
|
||||
this.processors.put(processor.getName(), processor);
|
||||
if(processor instanceof ParameterSubstitutionSuggester)
|
||||
{
|
||||
this.subtitutionSuggesterProcessors.add((ParameterSubstitutionSuggester)processor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ruleItem
|
||||
* @param ruleItemDefinition
|
||||
* @param actionedUponNodeRef
|
||||
*/
|
||||
public void process(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition, NodeRef actionedUponNodeRef)
|
||||
{
|
||||
for (Map.Entry<String, Serializable> entry : ruleItem.getParameterValues().entrySet())
|
||||
{
|
||||
String parameterName = entry.getKey();
|
||||
Object parameterValue = entry.getValue();
|
||||
|
||||
// only sub string property values
|
||||
if (parameterValue instanceof String)
|
||||
{
|
||||
// set the updated parameter value
|
||||
ruleItem.setParameterValue(parameterName, process((String)parameterValue, actionedUponNodeRef));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the value for substitution within the context of the provided node.
|
||||
*
|
||||
* @param value value
|
||||
* @param nodeRef node reference
|
||||
* @return String resulting value
|
||||
*/
|
||||
public String process(String value, NodeRef nodeRef)
|
||||
{
|
||||
return process(process(value, nodeRef, REG_EX_OLD), nodeRef, REG_EX);
|
||||
}
|
||||
|
||||
public String process(String value, NodeRef nodeRef, String regExp)
|
||||
{
|
||||
// match the substitution pattern
|
||||
Pattern patt = Pattern.compile(regExp);
|
||||
Matcher m = patt.matcher(value);
|
||||
StringBuffer sb = new StringBuffer(value.length());
|
||||
|
||||
while (m.find())
|
||||
{
|
||||
String text = m.group(1);
|
||||
|
||||
// lookup parameter processor to use
|
||||
ParameterProcessor processor = lookupProcessor(text);
|
||||
if (processor == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("A parameter processor has not been found for the substitution string " + text);
|
||||
}
|
||||
else
|
||||
{
|
||||
// process each substitution value
|
||||
text = processor.process(text, nodeRef);
|
||||
}
|
||||
|
||||
// append new value
|
||||
m.appendReplacement(sb, Matcher.quoteReplacement(text));
|
||||
}
|
||||
m.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of substitution suggestions for the passed string fragment.
|
||||
*
|
||||
* @param subtitutionFragment Text fragment to search on.
|
||||
* @return A list of substitutions that match the substitution fragment.
|
||||
*/
|
||||
public List<String> getSubstitutionSuggestions(final String substitutionFragment)
|
||||
{
|
||||
List<String> suggestions = new ArrayList<String>();
|
||||
for (ParameterSubstitutionSuggester suggestor : this.subtitutionSuggesterProcessors)
|
||||
{
|
||||
suggestions.addAll(suggestor.getSubstitutionSuggestions(substitutionFragment.toLowerCase()));
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up parameter processor
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
private ParameterProcessor lookupProcessor(String value)
|
||||
{
|
||||
ParameterProcessor result = null;
|
||||
|
||||
if (value != null && !value.isEmpty())
|
||||
{
|
||||
String[] values = value.split("\\.", 2);
|
||||
if (values.length != 0)
|
||||
{
|
||||
// get the processor from the registered map
|
||||
result = processors.get(values[0]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -1,28 +1,28 @@
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ParameterSubstitutionSuggester
|
||||
{
|
||||
int DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS = 10;
|
||||
|
||||
List<String> getSubstitutionSuggestions(final String substitutionFragment);
|
||||
}
|
||||
/*
|
||||
* 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.action.parameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ParameterSubstitutionSuggester
|
||||
{
|
||||
int DEFAULT_MAXIMUM_NUMBER_SUGGESTIONS = 10;
|
||||
|
||||
List<String> getSubstitutionSuggestions(final String substitutionFragment);
|
||||
}
|
||||
|
@@ -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.jscript;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* Extended jscript search implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedSearch extends Search
|
||||
{
|
||||
/**
|
||||
* Extended to take into account record read permission check.
|
||||
*
|
||||
* @see org.alfresco.repo.jscript.Search#findNode(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public ScriptNode findNode(NodeRef ref)
|
||||
{
|
||||
ParameterCheck.mandatory("ref", ref);
|
||||
if (this.services.getNodeService().exists(ref) &&
|
||||
(this.services.getPermissionService().hasPermission(ref, PermissionService.READ) == AccessStatus.ALLOWED ||
|
||||
this.services.getPermissionService().hasPermission(ref, RMPermissionModel.READ_RECORDS) == AccessStatus.ALLOWED))
|
||||
{
|
||||
return new ScriptNode(ref, this.services, getScope());
|
||||
}
|
||||
return 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.jscript;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* Extended jscript search implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedSearch extends Search
|
||||
{
|
||||
/**
|
||||
* Extended to take into account record read permission check.
|
||||
*
|
||||
* @see org.alfresco.repo.jscript.Search#findNode(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public ScriptNode findNode(NodeRef ref)
|
||||
{
|
||||
ParameterCheck.mandatory("ref", ref);
|
||||
if (this.services.getNodeService().exists(ref) &&
|
||||
(this.services.getPermissionService().hasPermission(ref, PermissionService.READ) == AccessStatus.ALLOWED ||
|
||||
this.services.getPermissionService().hasPermission(ref, RMPermissionModel.READ_RECORDS) == AccessStatus.ALLOWED))
|
||||
{
|
||||
return new ScriptNode(ref, this.services, getScope());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,50 +1,50 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.model.filefolder;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class ExtendedFileFolderServiceImpl extends FileFolderServiceImpl
|
||||
{
|
||||
protected RecordService recordService;
|
||||
|
||||
public void setRecordService(RecordService recordService)
|
||||
{
|
||||
this.recordService = recordService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo create(NodeRef parentNodeRef, String name, QName typeQName)
|
||||
{
|
||||
return create(parentNodeRef, name, typeQName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo create(NodeRef parentNodeRef, String name, QName typeQName, QName assocQName)
|
||||
{
|
||||
FileInfo result = null;
|
||||
|
||||
recordService.disablePropertyEditableCheck();
|
||||
try
|
||||
{
|
||||
result = super.create(parentNodeRef, name, typeQName, assocQName);
|
||||
}
|
||||
finally
|
||||
{
|
||||
recordService.enablePropertyEditableCheck();
|
||||
if (result != null)
|
||||
{
|
||||
recordService.disablePropertyEditableCheck(result.getNodeRef());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.model.filefolder;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class ExtendedFileFolderServiceImpl extends FileFolderServiceImpl
|
||||
{
|
||||
protected RecordService recordService;
|
||||
|
||||
public void setRecordService(RecordService recordService)
|
||||
{
|
||||
this.recordService = recordService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo create(NodeRef parentNodeRef, String name, QName typeQName)
|
||||
{
|
||||
return create(parentNodeRef, name, typeQName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo create(NodeRef parentNodeRef, String name, QName typeQName, QName assocQName)
|
||||
{
|
||||
FileInfo result = null;
|
||||
|
||||
recordService.disablePropertyEditableCheck();
|
||||
try
|
||||
{
|
||||
result = super.create(parentNodeRef, name, typeQName, assocQName);
|
||||
}
|
||||
finally
|
||||
{
|
||||
recordService.enablePropertyEditableCheck();
|
||||
if (result != null)
|
||||
{
|
||||
recordService.disablePropertyEditableCheck(result.getNodeRef());
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -1,257 +1,257 @@
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
|
||||
/**
|
||||
* Annotated behaviour bean post processor.
|
||||
* <p>
|
||||
* Registers the annotated methods on behaviour beans with the policy component.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class AnnotatedBehaviourPostProcessor implements BeanPostProcessor
|
||||
{
|
||||
/** logger */
|
||||
private static Log logger = LogFactory.getLog(AnnotatedBehaviourPostProcessor.class);
|
||||
|
||||
/** policy component */
|
||||
private PolicyComponent policyComponent;
|
||||
|
||||
/** namespace service */
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
/**
|
||||
* @param policyComponent policy component
|
||||
*/
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespaceService namespace service
|
||||
*/
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
{
|
||||
// register annotated behavior methods
|
||||
registerBehaviours(bean, beanName);
|
||||
|
||||
// return the bean
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
{
|
||||
// do nothing
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register behaviours.
|
||||
*
|
||||
* @param bean bean
|
||||
* @param beanName bean name
|
||||
*/
|
||||
private void registerBehaviours(Object bean, String beanName)
|
||||
{
|
||||
if (bean.getClass().isAnnotationPresent(BehaviourBean.class))
|
||||
{
|
||||
BehaviourBean behaviourBean = bean.getClass().getAnnotation(BehaviourBean.class);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Annotated behaviour post processing for " + beanName);
|
||||
}
|
||||
|
||||
Method[] methods = bean.getClass().getMethods();
|
||||
for (Method method : methods)
|
||||
{
|
||||
if (method.isAnnotationPresent(Behaviour.class))
|
||||
{
|
||||
registerBehaviour(behaviourBean, bean, beanName, method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register behaviour.
|
||||
*
|
||||
* @param behaviourBean behaviour bean annotation
|
||||
* @param bean bean
|
||||
* @param beanName bean name
|
||||
* @param method method
|
||||
*/
|
||||
private void registerBehaviour(BehaviourBean behaviourBean, Object bean, String beanName, Method method)
|
||||
{
|
||||
Behaviour behaviour = method.getAnnotation(Behaviour.class);
|
||||
QName policy = resolvePolicy(behaviour.policy(), method);
|
||||
QName type = resolveType(behaviourBean, behaviour);
|
||||
|
||||
// assert that the policy and type have been set!!
|
||||
ParameterCheck.mandatory("policy", policy);
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
ParameterCheck.mandatory("type", type);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
logger.debug(" ... binding " + behaviour.kind() + " behaviour for " + beanName + "." + method.getName() +
|
||||
" for policy " + policy.toString() +
|
||||
" and type " + type.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug(" ... binding " + behaviour.kind() + " service behaviour for " + beanName + "." + method.getName() +
|
||||
" for policy " + policy.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// create java behaviour object
|
||||
JavaBehaviour javaBehaviour = new JavaBehaviour(bean, method.getName(), behaviour.notificationFrequency());
|
||||
|
||||
// determine whether we should register the behaviour
|
||||
if (bean instanceof BehaviourRegistry && !behaviour.name().isEmpty())
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(" ... adding behaviour to registry with name " + behaviour.name());
|
||||
}
|
||||
|
||||
((BehaviourRegistry)bean).registerBehaviour(behaviour.name(), javaBehaviour);
|
||||
}
|
||||
|
||||
// deal with class behaviours
|
||||
if (BehaviourKind.CLASS.equals(behaviour.kind()))
|
||||
{
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
// bind class behaviour for given type
|
||||
policyComponent.bindClassBehaviour(policy, type, javaBehaviour);
|
||||
}
|
||||
else
|
||||
{
|
||||
// bind class service behaviour
|
||||
policyComponent.bindClassBehaviour(policy, bean, javaBehaviour);
|
||||
}
|
||||
}
|
||||
// deal with association behaviours
|
||||
else if (BehaviourKind.ASSOCIATION.equals(behaviour.kind()))
|
||||
{
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
// bind association behaviour for given type and assoc type
|
||||
policyComponent.bindAssociationBehaviour(policy,
|
||||
type,
|
||||
toQName(behaviour.assocType()),
|
||||
javaBehaviour);
|
||||
}
|
||||
else
|
||||
{
|
||||
// bind association service behaviour
|
||||
policyComponent.bindAssociationBehaviour(policy, bean, javaBehaviour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the policy qname, defaulting to the qualified name of the method if none specified.
|
||||
*
|
||||
* @param policyName policy name
|
||||
* @param method method
|
||||
* @return {@link QName} qualified name of the policy
|
||||
*/
|
||||
private QName resolvePolicy(String policyName, Method method)
|
||||
{
|
||||
QName policy = null;
|
||||
if (policyName.isEmpty())
|
||||
{
|
||||
policy = QName.createQName(NamespaceService.ALFRESCO_URI, method.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
policy = toQName(policyName);
|
||||
}
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param behaviourBean
|
||||
* @param typeName
|
||||
* @return
|
||||
*/
|
||||
private QName resolveType(BehaviourBean behaviourBean, Behaviour behaviour)
|
||||
{
|
||||
QName type = null;
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
if (behaviour.type().isEmpty())
|
||||
{
|
||||
// get default
|
||||
type = toQName(behaviourBean.defaultType());
|
||||
}
|
||||
else
|
||||
{
|
||||
// convert set
|
||||
type = toQName(behaviour.type());
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
private QName toQName(String name)
|
||||
{
|
||||
return QName.createQName(name, namespaceService);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
|
||||
/**
|
||||
* Annotated behaviour bean post processor.
|
||||
* <p>
|
||||
* Registers the annotated methods on behaviour beans with the policy component.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class AnnotatedBehaviourPostProcessor implements BeanPostProcessor
|
||||
{
|
||||
/** logger */
|
||||
private static Log logger = LogFactory.getLog(AnnotatedBehaviourPostProcessor.class);
|
||||
|
||||
/** policy component */
|
||||
private PolicyComponent policyComponent;
|
||||
|
||||
/** namespace service */
|
||||
private NamespaceService namespaceService;
|
||||
|
||||
/**
|
||||
* @param policyComponent policy component
|
||||
*/
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param namespaceService namespace service
|
||||
*/
|
||||
public void setNamespaceService(NamespaceService namespaceService)
|
||||
{
|
||||
this.namespaceService = namespaceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
{
|
||||
// register annotated behavior methods
|
||||
registerBehaviours(bean, beanName);
|
||||
|
||||
// return the bean
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName)
|
||||
{
|
||||
// do nothing
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register behaviours.
|
||||
*
|
||||
* @param bean bean
|
||||
* @param beanName bean name
|
||||
*/
|
||||
private void registerBehaviours(Object bean, String beanName)
|
||||
{
|
||||
if (bean.getClass().isAnnotationPresent(BehaviourBean.class))
|
||||
{
|
||||
BehaviourBean behaviourBean = bean.getClass().getAnnotation(BehaviourBean.class);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Annotated behaviour post processing for " + beanName);
|
||||
}
|
||||
|
||||
Method[] methods = bean.getClass().getMethods();
|
||||
for (Method method : methods)
|
||||
{
|
||||
if (method.isAnnotationPresent(Behaviour.class))
|
||||
{
|
||||
registerBehaviour(behaviourBean, bean, beanName, method);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register behaviour.
|
||||
*
|
||||
* @param behaviourBean behaviour bean annotation
|
||||
* @param bean bean
|
||||
* @param beanName bean name
|
||||
* @param method method
|
||||
*/
|
||||
private void registerBehaviour(BehaviourBean behaviourBean, Object bean, String beanName, Method method)
|
||||
{
|
||||
Behaviour behaviour = method.getAnnotation(Behaviour.class);
|
||||
QName policy = resolvePolicy(behaviour.policy(), method);
|
||||
QName type = resolveType(behaviourBean, behaviour);
|
||||
|
||||
// assert that the policy and type have been set!!
|
||||
ParameterCheck.mandatory("policy", policy);
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
ParameterCheck.mandatory("type", type);
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
logger.debug(" ... binding " + behaviour.kind() + " behaviour for " + beanName + "." + method.getName() +
|
||||
" for policy " + policy.toString() +
|
||||
" and type " + type.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug(" ... binding " + behaviour.kind() + " service behaviour for " + beanName + "." + method.getName() +
|
||||
" for policy " + policy.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// create java behaviour object
|
||||
JavaBehaviour javaBehaviour = new JavaBehaviour(bean, method.getName(), behaviour.notificationFrequency());
|
||||
|
||||
// determine whether we should register the behaviour
|
||||
if (bean instanceof BehaviourRegistry && !behaviour.name().isEmpty())
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug(" ... adding behaviour to registry with name " + behaviour.name());
|
||||
}
|
||||
|
||||
((BehaviourRegistry)bean).registerBehaviour(behaviour.name(), javaBehaviour);
|
||||
}
|
||||
|
||||
// deal with class behaviours
|
||||
if (BehaviourKind.CLASS.equals(behaviour.kind()))
|
||||
{
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
// bind class behaviour for given type
|
||||
policyComponent.bindClassBehaviour(policy, type, javaBehaviour);
|
||||
}
|
||||
else
|
||||
{
|
||||
// bind class service behaviour
|
||||
policyComponent.bindClassBehaviour(policy, bean, javaBehaviour);
|
||||
}
|
||||
}
|
||||
// deal with association behaviours
|
||||
else if (BehaviourKind.ASSOCIATION.equals(behaviour.kind()))
|
||||
{
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
// bind association behaviour for given type and assoc type
|
||||
policyComponent.bindAssociationBehaviour(policy,
|
||||
type,
|
||||
toQName(behaviour.assocType()),
|
||||
javaBehaviour);
|
||||
}
|
||||
else
|
||||
{
|
||||
// bind association service behaviour
|
||||
policyComponent.bindAssociationBehaviour(policy, bean, javaBehaviour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve the policy qname, defaulting to the qualified name of the method if none specified.
|
||||
*
|
||||
* @param policyName policy name
|
||||
* @param method method
|
||||
* @return {@link QName} qualified name of the policy
|
||||
*/
|
||||
private QName resolvePolicy(String policyName, Method method)
|
||||
{
|
||||
QName policy = null;
|
||||
if (policyName.isEmpty())
|
||||
{
|
||||
policy = QName.createQName(NamespaceService.ALFRESCO_URI, method.getName());
|
||||
}
|
||||
else
|
||||
{
|
||||
policy = toQName(policyName);
|
||||
}
|
||||
|
||||
return policy;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param behaviourBean
|
||||
* @param typeName
|
||||
* @return
|
||||
*/
|
||||
private QName resolveType(BehaviourBean behaviourBean, Behaviour behaviour)
|
||||
{
|
||||
QName type = null;
|
||||
if (!behaviour.isService())
|
||||
{
|
||||
if (behaviour.type().isEmpty())
|
||||
{
|
||||
// get default
|
||||
type = toQName(behaviourBean.defaultType());
|
||||
}
|
||||
else
|
||||
{
|
||||
// convert set
|
||||
type = toQName(behaviour.type());
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
private QName toQName(String name)
|
||||
{
|
||||
return QName.createQName(name, namespaceService);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,57 +1,57 @@
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
|
||||
|
||||
/**
|
||||
* Behaviour method annotation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
@Target(value = ElementType.METHOD)
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
public @interface Behaviour
|
||||
{
|
||||
/** lookup name of the behaviour, if none specified behaviour is not recorded in the registry */
|
||||
String name() default "";
|
||||
|
||||
/** kind of behaviour */
|
||||
BehaviourKind kind();
|
||||
|
||||
/** qualified name of policy */
|
||||
String policy() default "";
|
||||
|
||||
/** indicates whether this is a service behaviour or not */
|
||||
boolean isService() default false;
|
||||
|
||||
/** qualified name of type/aspect */
|
||||
String type() default "";
|
||||
|
||||
/** qualified name of association */
|
||||
String assocType() default "cm:contains";
|
||||
|
||||
/** notification frequency */
|
||||
NotificationFrequency notificationFrequency() default NotificationFrequency.EVERY_EVENT;
|
||||
}
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
|
||||
|
||||
/**
|
||||
* Behaviour method annotation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
@Target(value = ElementType.METHOD)
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
public @interface Behaviour
|
||||
{
|
||||
/** lookup name of the behaviour, if none specified behaviour is not recorded in the registry */
|
||||
String name() default "";
|
||||
|
||||
/** kind of behaviour */
|
||||
BehaviourKind kind();
|
||||
|
||||
/** qualified name of policy */
|
||||
String policy() default "";
|
||||
|
||||
/** indicates whether this is a service behaviour or not */
|
||||
boolean isService() default false;
|
||||
|
||||
/** qualified name of type/aspect */
|
||||
String type() default "";
|
||||
|
||||
/** qualified name of association */
|
||||
String assocType() default "cm:contains";
|
||||
|
||||
/** notification frequency */
|
||||
NotificationFrequency notificationFrequency() default NotificationFrequency.EVERY_EVENT;
|
||||
}
|
||||
|
@@ -1,36 +1,36 @@
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
@Target(value = ElementType.TYPE)
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
public @interface BehaviourBean
|
||||
{
|
||||
/** qualified name of type/aspect */
|
||||
String defaultType() default "";
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
@Target(value = ElementType.TYPE)
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
public @interface BehaviourBean
|
||||
{
|
||||
/** qualified name of type/aspect */
|
||||
String defaultType() default "";
|
||||
|
||||
}
|
||||
|
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
/**
|
||||
* Enumeration describing the different kinds of behaviour.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public enum BehaviourKind
|
||||
{
|
||||
CLASS,
|
||||
ASSOCIATION
|
||||
}
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
/**
|
||||
* Enumeration describing the different kinds of behaviour.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public enum BehaviourKind
|
||||
{
|
||||
CLASS,
|
||||
ASSOCIATION
|
||||
}
|
||||
|
@@ -1,45 +1,45 @@
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
import org.alfresco.repo.policy.Behaviour;
|
||||
|
||||
/**
|
||||
* Interface for a behaviour registry.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public interface BehaviourRegistry
|
||||
{
|
||||
/**
|
||||
* Register a behaviour against a given name.
|
||||
*
|
||||
* @param behaviour behaviour
|
||||
*/
|
||||
void registerBehaviour(String name, Behaviour behaviour);
|
||||
|
||||
/**
|
||||
* Gets the behaviour for a given name.
|
||||
*
|
||||
* @param name behaviour name
|
||||
* @return {@link Behaviour} behaviour, null otherwise
|
||||
*/
|
||||
Behaviour getBehaviour(String name);
|
||||
}
|
||||
/*
|
||||
* 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.policy.annotation;
|
||||
|
||||
import org.alfresco.repo.policy.Behaviour;
|
||||
|
||||
/**
|
||||
* Interface for a behaviour registry.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.2
|
||||
*/
|
||||
public interface BehaviourRegistry
|
||||
{
|
||||
/**
|
||||
* Register a behaviour against a given name.
|
||||
*
|
||||
* @param behaviour behaviour
|
||||
*/
|
||||
void registerBehaviour(String name, Behaviour behaviour);
|
||||
|
||||
/**
|
||||
* Gets the behaviour for a given name.
|
||||
*
|
||||
* @param name behaviour name
|
||||
* @return {@link Behaviour} behaviour, null otherwise
|
||||
*/
|
||||
Behaviour getBehaviour(String name);
|
||||
}
|
||||
|
@@ -1,251 +1,251 @@
|
||||
/*
|
||||
* 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.rule;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.rule.Rule;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Extended rule service implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedRuleServiceImpl extends RuleServiceImpl
|
||||
{
|
||||
/** indicates whether the rules should be run as admin or not */
|
||||
private boolean runAsAdmin = true;
|
||||
|
||||
/** ignore types */
|
||||
private Set<QName> ignoredTypes = new HashSet<QName>();
|
||||
|
||||
/** file plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
/** node service */
|
||||
protected NodeService nodeService;
|
||||
|
||||
/** Record service */
|
||||
protected RecordService recordService;
|
||||
|
||||
/**
|
||||
* @param nodeService node service
|
||||
*/
|
||||
public void setNodeService2(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filePlanService file plan service
|
||||
*/
|
||||
public void setFilePlanService(FilePlanService filePlanService)
|
||||
{
|
||||
this.filePlanService = filePlanService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordService record service
|
||||
*/
|
||||
public void setRecordService(RecordService recordService)
|
||||
{
|
||||
this.recordService = recordService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param runAsAdmin true if run rules as admin, false otherwise
|
||||
*/
|
||||
public void setRunAsAdmin(boolean runAsAdmin)
|
||||
{
|
||||
this.runAsAdmin = runAsAdmin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
// Specify a set of system types to be ignored by rule executions
|
||||
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_SCHEDULE);
|
||||
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_ACTION);
|
||||
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_ACTION_DEFINITION);
|
||||
ignoredTypes.add(RecordsManagementModel.TYPE_EVENT_EXECUTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.RuleServiceImpl#saveRule(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.rule.Rule)
|
||||
*/
|
||||
@Override
|
||||
public void saveRule(final NodeRef nodeRef, final Rule rule)
|
||||
{
|
||||
if (filePlanService.isFilePlanComponent(nodeRef))
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
{
|
||||
ExtendedRuleServiceImpl.super.saveRule(nodeRef, rule);
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
super.saveRule(nodeRef, rule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.RuleServiceImpl#removeRule(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.rule.Rule)
|
||||
*/
|
||||
@Override
|
||||
public void removeRule(final NodeRef nodeRef, final Rule rule)
|
||||
{
|
||||
if (filePlanService.isFilePlanComponent(nodeRef))
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
{
|
||||
ExtendedRuleServiceImpl.super.removeRule(nodeRef, rule);
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
super.removeRule(nodeRef, rule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.RuleServiceImpl#executeRule(org.alfresco.service.cmr.rule.Rule, org.alfresco.service.cmr.repository.NodeRef, java.util.Set)
|
||||
*/
|
||||
@Override
|
||||
public void executeRule(final Rule rule, final NodeRef nodeRef, final Set<ExecutedRuleData> executedRules)
|
||||
{
|
||||
if (nodeService.exists(nodeRef))
|
||||
{
|
||||
QName typeQName = nodeService.getType(nodeRef);
|
||||
if (shouldRuleBeAppliedToNode(rule, nodeRef, typeQName))
|
||||
{
|
||||
// check if this is a rm rule on a rm artifact
|
||||
if (filePlanService.isFilePlanComponent(nodeRef) &&
|
||||
isFilePlanComponentRule(rule))
|
||||
{
|
||||
// ignore and
|
||||
if (!isIgnoredType(typeQName))
|
||||
{
|
||||
if (runAsAdmin)
|
||||
{
|
||||
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
{
|
||||
ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules);
|
||||
return null;
|
||||
}
|
||||
}, AuthenticationUtil.getAdminUserName());
|
||||
}
|
||||
else
|
||||
{
|
||||
// run as current user
|
||||
ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// just execute the rule as the current user
|
||||
super.executeRule(rule, nodeRef, executedRules);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the rule is a file plan component
|
||||
*
|
||||
* @param rule rule
|
||||
* @return boolean true if rule is set on a file plan component, false otherwise
|
||||
*/
|
||||
private boolean isFilePlanComponentRule(Rule rule)
|
||||
{
|
||||
NodeRef nodeRef = getOwningNodeRef(rule);
|
||||
return filePlanService.isFilePlanComponent(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param typeQName type qname
|
||||
* @return boolean true if ignore type, false otherwise
|
||||
*/
|
||||
private boolean isIgnoredType(QName typeQName)
|
||||
{
|
||||
return ignoredTypes.contains(typeQName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the rule is associated with the file plan component that the node it is being
|
||||
* applied to isn't a hold container, a hold, a transfer container, a transfer, an unfiled
|
||||
* record container, an unfiled record folder or unfiled content
|
||||
*
|
||||
* @param rule
|
||||
* @param nodeRef
|
||||
* @param typeQName
|
||||
* @return
|
||||
*/
|
||||
private boolean shouldRuleBeAppliedToNode(Rule rule, NodeRef nodeRef, QName typeQName)
|
||||
{
|
||||
boolean result = true;
|
||||
NodeRef ruleNodeRef = getOwningNodeRef(rule);
|
||||
if(filePlanService.isFilePlan(ruleNodeRef))
|
||||
{
|
||||
// if this rule is defined at the root of the file plan then we do not want to apply
|
||||
// it to holds/transfers/unfiled content...
|
||||
result = !(RecordsManagementModel.TYPE_HOLD.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_HOLD_CONTAINER.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_TRANSFER.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_TRANSFER_CONTAINER.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(typeQName) ||
|
||||
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_TRANSFERRING) ||
|
||||
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FROZEN) ||
|
||||
!recordService.isFiled(nodeRef));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.rule;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.rule.Rule;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Extended rule service implementation.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ExtendedRuleServiceImpl extends RuleServiceImpl
|
||||
{
|
||||
/** indicates whether the rules should be run as admin or not */
|
||||
private boolean runAsAdmin = true;
|
||||
|
||||
/** ignore types */
|
||||
private Set<QName> ignoredTypes = new HashSet<QName>();
|
||||
|
||||
/** file plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
/** node service */
|
||||
protected NodeService nodeService;
|
||||
|
||||
/** Record service */
|
||||
protected RecordService recordService;
|
||||
|
||||
/**
|
||||
* @param nodeService node service
|
||||
*/
|
||||
public void setNodeService2(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param filePlanService file plan service
|
||||
*/
|
||||
public void setFilePlanService(FilePlanService filePlanService)
|
||||
{
|
||||
this.filePlanService = filePlanService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recordService record service
|
||||
*/
|
||||
public void setRecordService(RecordService recordService)
|
||||
{
|
||||
this.recordService = recordService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param runAsAdmin true if run rules as admin, false otherwise
|
||||
*/
|
||||
public void setRunAsAdmin(boolean runAsAdmin)
|
||||
{
|
||||
this.runAsAdmin = runAsAdmin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
@Override
|
||||
public void init()
|
||||
{
|
||||
super.init();
|
||||
|
||||
// Specify a set of system types to be ignored by rule executions
|
||||
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_SCHEDULE);
|
||||
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_ACTION);
|
||||
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_ACTION_DEFINITION);
|
||||
ignoredTypes.add(RecordsManagementModel.TYPE_EVENT_EXECUTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.RuleServiceImpl#saveRule(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.rule.Rule)
|
||||
*/
|
||||
@Override
|
||||
public void saveRule(final NodeRef nodeRef, final Rule rule)
|
||||
{
|
||||
if (filePlanService.isFilePlanComponent(nodeRef))
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
{
|
||||
ExtendedRuleServiceImpl.super.saveRule(nodeRef, rule);
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
super.saveRule(nodeRef, rule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.RuleServiceImpl#removeRule(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.rule.Rule)
|
||||
*/
|
||||
@Override
|
||||
public void removeRule(final NodeRef nodeRef, final Rule rule)
|
||||
{
|
||||
if (filePlanService.isFilePlanComponent(nodeRef))
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
{
|
||||
ExtendedRuleServiceImpl.super.removeRule(nodeRef, rule);
|
||||
return null;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
super.removeRule(nodeRef, rule);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.RuleServiceImpl#executeRule(org.alfresco.service.cmr.rule.Rule, org.alfresco.service.cmr.repository.NodeRef, java.util.Set)
|
||||
*/
|
||||
@Override
|
||||
public void executeRule(final Rule rule, final NodeRef nodeRef, final Set<ExecutedRuleData> executedRules)
|
||||
{
|
||||
if (nodeService.exists(nodeRef))
|
||||
{
|
||||
QName typeQName = nodeService.getType(nodeRef);
|
||||
if (shouldRuleBeAppliedToNode(rule, nodeRef, typeQName))
|
||||
{
|
||||
// check if this is a rm rule on a rm artifact
|
||||
if (filePlanService.isFilePlanComponent(nodeRef) &&
|
||||
isFilePlanComponentRule(rule))
|
||||
{
|
||||
// ignore and
|
||||
if (!isIgnoredType(typeQName))
|
||||
{
|
||||
if (runAsAdmin)
|
||||
{
|
||||
AuthenticationUtil.runAs(new RunAsWork<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void doWork()
|
||||
{
|
||||
ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules);
|
||||
return null;
|
||||
}
|
||||
}, AuthenticationUtil.getAdminUserName());
|
||||
}
|
||||
else
|
||||
{
|
||||
// run as current user
|
||||
ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// just execute the rule as the current user
|
||||
super.executeRule(rule, nodeRef, executedRules);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the rule is a file plan component
|
||||
*
|
||||
* @param rule rule
|
||||
* @return boolean true if rule is set on a file plan component, false otherwise
|
||||
*/
|
||||
private boolean isFilePlanComponentRule(Rule rule)
|
||||
{
|
||||
NodeRef nodeRef = getOwningNodeRef(rule);
|
||||
return filePlanService.isFilePlanComponent(nodeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param typeQName type qname
|
||||
* @return boolean true if ignore type, false otherwise
|
||||
*/
|
||||
private boolean isIgnoredType(QName typeQName)
|
||||
{
|
||||
return ignoredTypes.contains(typeQName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the rule is associated with the file plan component that the node it is being
|
||||
* applied to isn't a hold container, a hold, a transfer container, a transfer, an unfiled
|
||||
* record container, an unfiled record folder or unfiled content
|
||||
*
|
||||
* @param rule
|
||||
* @param nodeRef
|
||||
* @param typeQName
|
||||
* @return
|
||||
*/
|
||||
private boolean shouldRuleBeAppliedToNode(Rule rule, NodeRef nodeRef, QName typeQName)
|
||||
{
|
||||
boolean result = true;
|
||||
NodeRef ruleNodeRef = getOwningNodeRef(rule);
|
||||
if(filePlanService.isFilePlan(ruleNodeRef))
|
||||
{
|
||||
// if this rule is defined at the root of the file plan then we do not want to apply
|
||||
// it to holds/transfers/unfiled content...
|
||||
result = !(RecordsManagementModel.TYPE_HOLD.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_HOLD_CONTAINER.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_TRANSFER.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_TRANSFER_CONTAINER.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER.equals(typeQName) ||
|
||||
RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER.equals(typeQName) ||
|
||||
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_TRANSFERRING) ||
|
||||
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FROZEN) ||
|
||||
!recordService.isFiled(nodeRef));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -1,103 +1,103 @@
|
||||
/*
|
||||
* 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.rule.ruletrigger;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
|
||||
import org.alfresco.repo.transaction.TransactionalResourceHelper;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Prevent multiple triggering of outbound rules when moving records.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class ExtendedBeforeDeleteChildAssociationRuleTrigger
|
||||
extends RuleTriggerAbstractBase
|
||||
implements NodeServicePolicies.BeforeDeleteChildAssociationPolicy
|
||||
{
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static Log logger = LogFactory.getLog(BeforeDeleteChildAssociationRuleTrigger.class);
|
||||
|
||||
private static final String POLICY = "beforeDeleteChildAssociation";
|
||||
|
||||
private boolean isClassBehaviour = false;
|
||||
|
||||
public void setIsClassBehaviour(boolean isClassBehaviour)
|
||||
{
|
||||
this.isClassBehaviour = isClassBehaviour;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
|
||||
*/
|
||||
public void registerRuleTrigger()
|
||||
{
|
||||
if (isClassBehaviour)
|
||||
{
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, POLICY),
|
||||
this,
|
||||
new JavaBehaviour(this, POLICY, NotificationFrequency.FIRST_EVENT));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.policyComponent.bindAssociationBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, POLICY),
|
||||
this,
|
||||
new JavaBehaviour(this, POLICY, NotificationFrequency.FIRST_EVENT));
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeDeleteChildAssociation(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
// Break out early if rules are not enabled
|
||||
if (!areRulesEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NodeRef childNodeRef = childAssocRef.getChildRef();
|
||||
|
||||
// Avoid renamed nodes
|
||||
Set<NodeRef> renamedNodeRefSet = TransactionalResourceHelper.getSet(RULE_TRIGGER_RENAMED_NODES);
|
||||
if (renamedNodeRefSet.contains(childNodeRef))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Single child assoc trigger (policy = " + POLICY + ") fired for parent node " + childAssocRef.getParentRef() + " and child node " + childAssocRef.getChildRef());
|
||||
}
|
||||
|
||||
triggerRules(childAssocRef.getParentRef(), childNodeRef);
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.rule.ruletrigger;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
|
||||
import org.alfresco.repo.transaction.TransactionalResourceHelper;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Prevent multiple triggering of outbound rules when moving records.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class ExtendedBeforeDeleteChildAssociationRuleTrigger
|
||||
extends RuleTriggerAbstractBase
|
||||
implements NodeServicePolicies.BeforeDeleteChildAssociationPolicy
|
||||
{
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private static Log logger = LogFactory.getLog(BeforeDeleteChildAssociationRuleTrigger.class);
|
||||
|
||||
private static final String POLICY = "beforeDeleteChildAssociation";
|
||||
|
||||
private boolean isClassBehaviour = false;
|
||||
|
||||
public void setIsClassBehaviour(boolean isClassBehaviour)
|
||||
{
|
||||
this.isClassBehaviour = isClassBehaviour;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
|
||||
*/
|
||||
public void registerRuleTrigger()
|
||||
{
|
||||
if (isClassBehaviour)
|
||||
{
|
||||
this.policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, POLICY),
|
||||
this,
|
||||
new JavaBehaviour(this, POLICY, NotificationFrequency.FIRST_EVENT));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.policyComponent.bindAssociationBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, POLICY),
|
||||
this,
|
||||
new JavaBehaviour(this, POLICY, NotificationFrequency.FIRST_EVENT));
|
||||
}
|
||||
}
|
||||
|
||||
public void beforeDeleteChildAssociation(ChildAssociationRef childAssocRef)
|
||||
{
|
||||
// Break out early if rules are not enabled
|
||||
if (!areRulesEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NodeRef childNodeRef = childAssocRef.getChildRef();
|
||||
|
||||
// Avoid renamed nodes
|
||||
Set<NodeRef> renamedNodeRefSet = TransactionalResourceHelper.getSet(RULE_TRIGGER_RENAMED_NODES);
|
||||
if (renamedNodeRefSet.contains(childNodeRef))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Single child assoc trigger (policy = " + POLICY + ") fired for parent node " + childAssocRef.getParentRef() + " and child node " + childAssocRef.getChildRef());
|
||||
}
|
||||
|
||||
triggerRules(childAssocRef.getParentRef(), childNodeRef);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,43 +1,43 @@
|
||||
/*
|
||||
* 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.security.authority;
|
||||
|
||||
/**
|
||||
* Interface for defining constants
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface RMAuthority
|
||||
{
|
||||
/**
|
||||
* The default rm zone.
|
||||
*/
|
||||
String ZONE_APP_RM = "APP.RM";
|
||||
|
||||
/**
|
||||
* The constant for all roles display name
|
||||
*/
|
||||
String ALL_ROLES_DISPLAY_NAME = "All Roles";
|
||||
|
||||
/**
|
||||
* The constant for all roles prefix
|
||||
*/
|
||||
String ALL_ROLES_PREFIX = "AllRoles";
|
||||
}
|
||||
/*
|
||||
* 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.security.authority;
|
||||
|
||||
/**
|
||||
* Interface for defining constants
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface RMAuthority
|
||||
{
|
||||
/**
|
||||
* The default rm zone.
|
||||
*/
|
||||
String ZONE_APP_RM = "APP.RM";
|
||||
|
||||
/**
|
||||
* The constant for all roles display name
|
||||
*/
|
||||
String ALL_ROLES_DISPLAY_NAME = "All Roles";
|
||||
|
||||
/**
|
||||
* The constant for all roles prefix
|
||||
*/
|
||||
String ALL_ROLES_PREFIX = "AllRoles";
|
||||
}
|
||||
|
@@ -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.security.authority;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
|
||||
/**
|
||||
* This class extends {@link AuthorityDAOImpl}</br>
|
||||
* and overrides two methods from the original class</br>
|
||||
* </br>
|
||||
* addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type)</br>
|
||||
* </br>
|
||||
* and</br>
|
||||
* </br>
|
||||
* addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type, Pattern pattern)</br>
|
||||
*/
|
||||
public class RMAuthorityDAOImpl extends AuthorityDAOImpl
|
||||
{
|
||||
protected void addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type)
|
||||
{
|
||||
if (isAuthorityNameMatching(authorityName, type))
|
||||
{
|
||||
authorities.add(authorityName);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type, Pattern pattern)
|
||||
{
|
||||
if (isAuthorityNameMatching(authorityName, type))
|
||||
{
|
||||
if (pattern == null)
|
||||
{
|
||||
authorities.add(authorityName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pattern.matcher(getShortName(authorityName)).matches())
|
||||
{
|
||||
authorities.add(authorityName);
|
||||
}
|
||||
else
|
||||
{
|
||||
String displayName = getAuthorityDisplayName(authorityName);
|
||||
if (displayName != null && pattern.matcher(displayName).matches())
|
||||
{
|
||||
authorities.add(authorityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAuthorityNameMatching(String authorityName, AuthorityType type)
|
||||
{
|
||||
boolean isMatching = false;
|
||||
if (type == null || AuthorityType.getAuthorityType(authorityName).equals(type) && !getAuthorityZones(authorityName).contains("APP.RM"))
|
||||
{
|
||||
isMatching = true;
|
||||
}
|
||||
return isMatching;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.security.authority;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
|
||||
/**
|
||||
* This class extends {@link AuthorityDAOImpl}</br>
|
||||
* and overrides two methods from the original class</br>
|
||||
* </br>
|
||||
* addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type)</br>
|
||||
* </br>
|
||||
* and</br>
|
||||
* </br>
|
||||
* addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type, Pattern pattern)</br>
|
||||
*/
|
||||
public class RMAuthorityDAOImpl extends AuthorityDAOImpl
|
||||
{
|
||||
protected void addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type)
|
||||
{
|
||||
if (isAuthorityNameMatching(authorityName, type))
|
||||
{
|
||||
authorities.add(authorityName);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type, Pattern pattern)
|
||||
{
|
||||
if (isAuthorityNameMatching(authorityName, type))
|
||||
{
|
||||
if (pattern == null)
|
||||
{
|
||||
authorities.add(authorityName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pattern.matcher(getShortName(authorityName)).matches())
|
||||
{
|
||||
authorities.add(authorityName);
|
||||
}
|
||||
else
|
||||
{
|
||||
String displayName = getAuthorityDisplayName(authorityName);
|
||||
if (displayName != null && pattern.matcher(displayName).matches())
|
||||
{
|
||||
authorities.add(authorityName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isAuthorityNameMatching(String authorityName, AuthorityType type)
|
||||
{
|
||||
boolean isMatching = false;
|
||||
if (type == null || AuthorityType.getAuthorityType(authorityName).equals(type) && !getAuthorityZones(authorityName).contains("APP.RM"))
|
||||
{
|
||||
isMatching = true;
|
||||
}
|
||||
return isMatching;
|
||||
}
|
||||
}
|
||||
|
@@ -1,34 +1,34 @@
|
||||
/*
|
||||
* 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.security.permissions.impl;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
|
||||
/**
|
||||
* Extended Permission Service Interface used in RM.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface ExtendedPermissionService extends PermissionService
|
||||
{
|
||||
Set<String> getWriters(Long aclId);
|
||||
}
|
||||
/*
|
||||
* 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.security.permissions.impl;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
|
||||
/**
|
||||
* Extended Permission Service Interface used in RM.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 2.1
|
||||
*/
|
||||
public interface ExtendedPermissionService extends PermissionService
|
||||
{
|
||||
Set<String> getWriters(Long aclId);
|
||||
}
|
||||
|
@@ -1,343 +1,343 @@
|
||||
/*
|
||||
* 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.security.permissions.impl;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.isNotBlank;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedReaderDynamicAuthority;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedWriterDynamicAuthority;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.security.permissions.AccessControlEntry;
|
||||
import org.alfresco.repo.security.permissions.AccessControlList;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessPermission;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* Extends the core permission service implementation allowing the consideration of the read records
|
||||
* permission.
|
||||
* <p>
|
||||
* This is required for SOLR support.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class RMPermissionServiceImpl extends PermissionServiceImpl
|
||||
implements ExtendedPermissionService
|
||||
{
|
||||
/** Writers simple cache */
|
||||
protected SimpleCache<Serializable, Set<String>> writersCache;
|
||||
|
||||
/** File plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
/**
|
||||
* Gets the file plan service
|
||||
*
|
||||
* @return the filePlanService
|
||||
*/
|
||||
public FilePlanService getFilePlanService()
|
||||
{
|
||||
return this.filePlanService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file plan service
|
||||
*
|
||||
* @param filePlanService the filePlanService to set
|
||||
*/
|
||||
public void setFilePlanService(FilePlanService filePlanService)
|
||||
{
|
||||
this.filePlanService = filePlanService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#setAnyDenyDenies(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setAnyDenyDenies(boolean anyDenyDenies)
|
||||
{
|
||||
super.setAnyDenyDenies(anyDenyDenies);
|
||||
writersCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param writersCache the writersCache to set
|
||||
*/
|
||||
public void setWritersCache(SimpleCache<Serializable, Set<String>> writersCache)
|
||||
{
|
||||
this.writersCache = writersCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#onBootstrap(org.springframework.context.ApplicationEvent)
|
||||
*/
|
||||
@Override
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
super.onBootstrap(event);
|
||||
PropertyCheck.mandatory(this, "writersCache", writersCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to deal with the possibility of hard coded permission checks in core code.
|
||||
*
|
||||
* Note: Eventually we need to merge the RM permission model into the core to make this more rebust.
|
||||
*
|
||||
* @see org.alfresco.repo.security.permissions.impl.ExtendedPermissionService#hasPermission(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public AccessStatus hasPermission(NodeRef nodeRef, String perm)
|
||||
{
|
||||
AccessStatus acs = super.hasPermission(nodeRef, perm);
|
||||
if (AccessStatus.DENIED.equals(acs) == true &&
|
||||
PermissionService.READ.equals(perm) == true &&
|
||||
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) == true)
|
||||
{
|
||||
return super.hasPermission(nodeRef, RMPermissionModel.READ_RECORDS);
|
||||
}
|
||||
else if (AccessStatus.DENIED.equals(acs) == true &&
|
||||
PermissionService.WRITE.equals(perm) == true &&
|
||||
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) == true)
|
||||
{
|
||||
return super.hasPermission(nodeRef, RMPermissionModel.FILE_RECORDS);
|
||||
}
|
||||
|
||||
return acs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#canRead(java.lang.Long)
|
||||
*/
|
||||
@Override
|
||||
protected AccessStatus canRead(Long aclId)
|
||||
{
|
||||
Set<String> authorities = getAuthorisations();
|
||||
|
||||
// test denied
|
||||
|
||||
if(anyDenyDenies)
|
||||
{
|
||||
|
||||
Set<String> aclReadersDenied = getReadersDenied(aclId);
|
||||
|
||||
for(String auth : aclReadersDenied)
|
||||
{
|
||||
if(authorities.contains(auth))
|
||||
{
|
||||
return AccessStatus.DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// test acl readers
|
||||
Set<String> aclReaders = getReaders(aclId);
|
||||
|
||||
for(String auth : aclReaders)
|
||||
{
|
||||
if(authorities.contains(auth))
|
||||
{
|
||||
return AccessStatus.ALLOWED;
|
||||
}
|
||||
}
|
||||
|
||||
return AccessStatus.DENIED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#getReaders(java.lang.Long)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getReaders(Long aclId)
|
||||
{
|
||||
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
|
||||
if (acl == null)
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<String> aclReaders = readersCache.get((Serializable)acl.getProperties());
|
||||
if (aclReaders != null)
|
||||
{
|
||||
return aclReaders;
|
||||
}
|
||||
|
||||
HashSet<String> assigned = new HashSet<String>();
|
||||
HashSet<String> readers = new HashSet<String>();
|
||||
|
||||
for (AccessControlEntry ace : acl.getEntries())
|
||||
{
|
||||
assigned.add(ace.getAuthority());
|
||||
}
|
||||
|
||||
for (String authority : assigned)
|
||||
{
|
||||
UnconditionalAclTest test = new UnconditionalAclTest(getPermissionReference(PermissionService.READ));
|
||||
UnconditionalAclTest rmTest = new UnconditionalAclTest(getPermissionReference(RMPermissionModel.READ_RECORDS));
|
||||
if (test.evaluate(authority, aclId) || rmTest.evaluate(authority, aclId))
|
||||
{
|
||||
readers.add(authority);
|
||||
}
|
||||
}
|
||||
|
||||
aclReaders = Collections.unmodifiableSet(readers);
|
||||
readersCache.put((Serializable)acl.getProperties(), aclReaders);
|
||||
return aclReaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override with check for RM read
|
||||
*
|
||||
* @param aclId
|
||||
* @return
|
||||
*/
|
||||
private Set<String> getReadersDenied(Long aclId)
|
||||
{
|
||||
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
|
||||
|
||||
if (acl == null)
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<String> denied = readersDeniedCache.get(aclId);
|
||||
if (denied != null)
|
||||
{
|
||||
return denied;
|
||||
}
|
||||
denied = new HashSet<String>();
|
||||
Set<String> assigned = new HashSet<String>();
|
||||
|
||||
for (AccessControlEntry ace : acl.getEntries())
|
||||
{
|
||||
assigned.add(ace.getAuthority());
|
||||
}
|
||||
|
||||
for(String authority : assigned)
|
||||
{
|
||||
UnconditionalDeniedAclTest test = new UnconditionalDeniedAclTest(getPermissionReference(PermissionService.READ));
|
||||
UnconditionalDeniedAclTest rmTest = new UnconditionalDeniedAclTest(getPermissionReference(RMPermissionModel.READ_RECORDS));
|
||||
if(test.evaluate(authority, aclId) || rmTest.evaluate(authority, aclId))
|
||||
{
|
||||
denied.add(authority);
|
||||
}
|
||||
}
|
||||
|
||||
readersDeniedCache.put((Serializable)acl.getProperties(), denied);
|
||||
|
||||
return denied;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.ExtendedPermissionService#getWriters(java.lang.Long)
|
||||
*/
|
||||
public Set<String> getWriters(Long aclId)
|
||||
{
|
||||
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
|
||||
if (acl == null)
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<String> aclWriters = writersCache.get((Serializable)acl.getProperties());
|
||||
if (aclWriters != null)
|
||||
{
|
||||
return aclWriters;
|
||||
}
|
||||
|
||||
HashSet<String> assigned = new HashSet<String>();
|
||||
HashSet<String> readers = new HashSet<String>();
|
||||
|
||||
for (AccessControlEntry ace : acl.getEntries())
|
||||
{
|
||||
assigned.add(ace.getAuthority());
|
||||
}
|
||||
|
||||
for (String authority : assigned)
|
||||
{
|
||||
UnconditionalAclTest test = new UnconditionalAclTest(getPermissionReference(PermissionService.WRITE));
|
||||
if (test.evaluate(authority, aclId))
|
||||
{
|
||||
readers.add(authority);
|
||||
}
|
||||
}
|
||||
|
||||
aclWriters = Collections.unmodifiableSet(readers);
|
||||
writersCache.put((Serializable)acl.getProperties(), aclWriters);
|
||||
return aclWriters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#setInheritParentPermissions(org.alfresco.service.cmr.repository.NodeRef, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setInheritParentPermissions(final NodeRef nodeRef, boolean inheritParentPermissions)
|
||||
{
|
||||
final String adminRole = getAdminRole(nodeRef);
|
||||
if (nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) && isNotBlank(adminRole))
|
||||
{
|
||||
if (inheritParentPermissions)
|
||||
{
|
||||
Set<AccessPermission> accessPermissions = getAllSetPermissions(nodeRef);
|
||||
for (AccessPermission accessPermission : accessPermissions)
|
||||
{
|
||||
String authority = accessPermission.getAuthority();
|
||||
String permission = accessPermission.getPermission();
|
||||
if (accessPermission.isSetDirectly() &&
|
||||
(RMPermissionModel.FILING.equals(permission) || RMPermissionModel.READ_RECORDS.equals(permission)) &&
|
||||
(ExtendedReaderDynamicAuthority.EXTENDED_READER.equals(authority) || ExtendedWriterDynamicAuthority.EXTENDED_WRITER.equals(authority)) || adminRole.equals(authority))
|
||||
{
|
||||
// FIXME!!!
|
||||
//deletePermission(nodeRef, authority, permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setPermission(nodeRef, ExtendedReaderDynamicAuthority.EXTENDED_READER, RMPermissionModel.READ_RECORDS, true);
|
||||
setPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER, RMPermissionModel.FILING, true);
|
||||
setPermission(nodeRef, adminRole, RMPermissionModel.FILING, true);
|
||||
}
|
||||
}
|
||||
super.setInheritParentPermissions(nodeRef, inheritParentPermissions);
|
||||
}
|
||||
|
||||
private String getAdminRole(NodeRef nodeRef)
|
||||
{
|
||||
String adminRole = null;
|
||||
NodeRef filePlan = getFilePlanService().getFilePlan(nodeRef);
|
||||
if (filePlan != null)
|
||||
{
|
||||
adminRole = authorityService.getName(AuthorityType.GROUP, FilePlanRoleService.ROLE_ADMIN + filePlan.getId());
|
||||
}
|
||||
return adminRole;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.security.permissions.impl;
|
||||
|
||||
import static org.apache.commons.lang.StringUtils.isNotBlank;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedReaderDynamicAuthority;
|
||||
import org.alfresco.module.org_alfresco_module_rm.security.ExtendedWriterDynamicAuthority;
|
||||
import org.alfresco.repo.cache.SimpleCache;
|
||||
import org.alfresco.repo.security.permissions.AccessControlEntry;
|
||||
import org.alfresco.repo.security.permissions.AccessControlList;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AccessPermission;
|
||||
import org.alfresco.service.cmr.security.AccessStatus;
|
||||
import org.alfresco.service.cmr.security.AuthorityType;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* Extends the core permission service implementation allowing the consideration of the read records
|
||||
* permission.
|
||||
* <p>
|
||||
* This is required for SOLR support.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class RMPermissionServiceImpl extends PermissionServiceImpl
|
||||
implements ExtendedPermissionService
|
||||
{
|
||||
/** Writers simple cache */
|
||||
protected SimpleCache<Serializable, Set<String>> writersCache;
|
||||
|
||||
/** File plan service */
|
||||
private FilePlanService filePlanService;
|
||||
|
||||
/**
|
||||
* Gets the file plan service
|
||||
*
|
||||
* @return the filePlanService
|
||||
*/
|
||||
public FilePlanService getFilePlanService()
|
||||
{
|
||||
return this.filePlanService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the file plan service
|
||||
*
|
||||
* @param filePlanService the filePlanService to set
|
||||
*/
|
||||
public void setFilePlanService(FilePlanService filePlanService)
|
||||
{
|
||||
this.filePlanService = filePlanService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#setAnyDenyDenies(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setAnyDenyDenies(boolean anyDenyDenies)
|
||||
{
|
||||
super.setAnyDenyDenies(anyDenyDenies);
|
||||
writersCache.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param writersCache the writersCache to set
|
||||
*/
|
||||
public void setWritersCache(SimpleCache<Serializable, Set<String>> writersCache)
|
||||
{
|
||||
this.writersCache = writersCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#onBootstrap(org.springframework.context.ApplicationEvent)
|
||||
*/
|
||||
@Override
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
super.onBootstrap(event);
|
||||
PropertyCheck.mandatory(this, "writersCache", writersCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to deal with the possibility of hard coded permission checks in core code.
|
||||
*
|
||||
* Note: Eventually we need to merge the RM permission model into the core to make this more rebust.
|
||||
*
|
||||
* @see org.alfresco.repo.security.permissions.impl.ExtendedPermissionService#hasPermission(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public AccessStatus hasPermission(NodeRef nodeRef, String perm)
|
||||
{
|
||||
AccessStatus acs = super.hasPermission(nodeRef, perm);
|
||||
if (AccessStatus.DENIED.equals(acs) == true &&
|
||||
PermissionService.READ.equals(perm) == true &&
|
||||
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) == true)
|
||||
{
|
||||
return super.hasPermission(nodeRef, RMPermissionModel.READ_RECORDS);
|
||||
}
|
||||
else if (AccessStatus.DENIED.equals(acs) == true &&
|
||||
PermissionService.WRITE.equals(perm) == true &&
|
||||
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) == true)
|
||||
{
|
||||
return super.hasPermission(nodeRef, RMPermissionModel.FILE_RECORDS);
|
||||
}
|
||||
|
||||
return acs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#canRead(java.lang.Long)
|
||||
*/
|
||||
@Override
|
||||
protected AccessStatus canRead(Long aclId)
|
||||
{
|
||||
Set<String> authorities = getAuthorisations();
|
||||
|
||||
// test denied
|
||||
|
||||
if(anyDenyDenies)
|
||||
{
|
||||
|
||||
Set<String> aclReadersDenied = getReadersDenied(aclId);
|
||||
|
||||
for(String auth : aclReadersDenied)
|
||||
{
|
||||
if(authorities.contains(auth))
|
||||
{
|
||||
return AccessStatus.DENIED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// test acl readers
|
||||
Set<String> aclReaders = getReaders(aclId);
|
||||
|
||||
for(String auth : aclReaders)
|
||||
{
|
||||
if(authorities.contains(auth))
|
||||
{
|
||||
return AccessStatus.ALLOWED;
|
||||
}
|
||||
}
|
||||
|
||||
return AccessStatus.DENIED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#getReaders(java.lang.Long)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getReaders(Long aclId)
|
||||
{
|
||||
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
|
||||
if (acl == null)
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<String> aclReaders = readersCache.get((Serializable)acl.getProperties());
|
||||
if (aclReaders != null)
|
||||
{
|
||||
return aclReaders;
|
||||
}
|
||||
|
||||
HashSet<String> assigned = new HashSet<String>();
|
||||
HashSet<String> readers = new HashSet<String>();
|
||||
|
||||
for (AccessControlEntry ace : acl.getEntries())
|
||||
{
|
||||
assigned.add(ace.getAuthority());
|
||||
}
|
||||
|
||||
for (String authority : assigned)
|
||||
{
|
||||
UnconditionalAclTest test = new UnconditionalAclTest(getPermissionReference(PermissionService.READ));
|
||||
UnconditionalAclTest rmTest = new UnconditionalAclTest(getPermissionReference(RMPermissionModel.READ_RECORDS));
|
||||
if (test.evaluate(authority, aclId) || rmTest.evaluate(authority, aclId))
|
||||
{
|
||||
readers.add(authority);
|
||||
}
|
||||
}
|
||||
|
||||
aclReaders = Collections.unmodifiableSet(readers);
|
||||
readersCache.put((Serializable)acl.getProperties(), aclReaders);
|
||||
return aclReaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override with check for RM read
|
||||
*
|
||||
* @param aclId
|
||||
* @return
|
||||
*/
|
||||
private Set<String> getReadersDenied(Long aclId)
|
||||
{
|
||||
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
|
||||
|
||||
if (acl == null)
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
Set<String> denied = readersDeniedCache.get(aclId);
|
||||
if (denied != null)
|
||||
{
|
||||
return denied;
|
||||
}
|
||||
denied = new HashSet<String>();
|
||||
Set<String> assigned = new HashSet<String>();
|
||||
|
||||
for (AccessControlEntry ace : acl.getEntries())
|
||||
{
|
||||
assigned.add(ace.getAuthority());
|
||||
}
|
||||
|
||||
for(String authority : assigned)
|
||||
{
|
||||
UnconditionalDeniedAclTest test = new UnconditionalDeniedAclTest(getPermissionReference(PermissionService.READ));
|
||||
UnconditionalDeniedAclTest rmTest = new UnconditionalDeniedAclTest(getPermissionReference(RMPermissionModel.READ_RECORDS));
|
||||
if(test.evaluate(authority, aclId) || rmTest.evaluate(authority, aclId))
|
||||
{
|
||||
denied.add(authority);
|
||||
}
|
||||
}
|
||||
|
||||
readersDeniedCache.put((Serializable)acl.getProperties(), denied);
|
||||
|
||||
return denied;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.ExtendedPermissionService#getWriters(java.lang.Long)
|
||||
*/
|
||||
public Set<String> getWriters(Long aclId)
|
||||
{
|
||||
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
|
||||
if (acl == null)
|
||||
{
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
Set<String> aclWriters = writersCache.get((Serializable)acl.getProperties());
|
||||
if (aclWriters != null)
|
||||
{
|
||||
return aclWriters;
|
||||
}
|
||||
|
||||
HashSet<String> assigned = new HashSet<String>();
|
||||
HashSet<String> readers = new HashSet<String>();
|
||||
|
||||
for (AccessControlEntry ace : acl.getEntries())
|
||||
{
|
||||
assigned.add(ace.getAuthority());
|
||||
}
|
||||
|
||||
for (String authority : assigned)
|
||||
{
|
||||
UnconditionalAclTest test = new UnconditionalAclTest(getPermissionReference(PermissionService.WRITE));
|
||||
if (test.evaluate(authority, aclId))
|
||||
{
|
||||
readers.add(authority);
|
||||
}
|
||||
}
|
||||
|
||||
aclWriters = Collections.unmodifiableSet(readers);
|
||||
writersCache.put((Serializable)acl.getProperties(), aclWriters);
|
||||
return aclWriters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#setInheritParentPermissions(org.alfresco.service.cmr.repository.NodeRef, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setInheritParentPermissions(final NodeRef nodeRef, boolean inheritParentPermissions)
|
||||
{
|
||||
final String adminRole = getAdminRole(nodeRef);
|
||||
if (nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) && isNotBlank(adminRole))
|
||||
{
|
||||
if (inheritParentPermissions)
|
||||
{
|
||||
Set<AccessPermission> accessPermissions = getAllSetPermissions(nodeRef);
|
||||
for (AccessPermission accessPermission : accessPermissions)
|
||||
{
|
||||
String authority = accessPermission.getAuthority();
|
||||
String permission = accessPermission.getPermission();
|
||||
if (accessPermission.isSetDirectly() &&
|
||||
(RMPermissionModel.FILING.equals(permission) || RMPermissionModel.READ_RECORDS.equals(permission)) &&
|
||||
(ExtendedReaderDynamicAuthority.EXTENDED_READER.equals(authority) || ExtendedWriterDynamicAuthority.EXTENDED_WRITER.equals(authority)) || adminRole.equals(authority))
|
||||
{
|
||||
// FIXME!!!
|
||||
//deletePermission(nodeRef, authority, permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setPermission(nodeRef, ExtendedReaderDynamicAuthority.EXTENDED_READER, RMPermissionModel.READ_RECORDS, true);
|
||||
setPermission(nodeRef, ExtendedWriterDynamicAuthority.EXTENDED_WRITER, RMPermissionModel.FILING, true);
|
||||
setPermission(nodeRef, adminRole, RMPermissionModel.FILING, true);
|
||||
}
|
||||
}
|
||||
super.setInheritParentPermissions(nodeRef, inheritParentPermissions);
|
||||
}
|
||||
|
||||
private String getAdminRole(NodeRef nodeRef)
|
||||
{
|
||||
String adminRole = null;
|
||||
NodeRef filePlan = getFilePlanService().getFilePlan(nodeRef);
|
||||
if (filePlan != null)
|
||||
{
|
||||
adminRole = authorityService.getName(AuthorityType.GROUP, FilePlanRoleService.ROLE_ADMIN + filePlan.getId());
|
||||
}
|
||||
return adminRole;
|
||||
}
|
||||
}
|
||||
|
@@ -1,51 +1,51 @@
|
||||
/*
|
||||
* 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.security.permissions.impl.acegi;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.alfresco.service.cmr.security.OwnableService;
|
||||
|
||||
/**
|
||||
* This is a workaround to make RM 2.1 backwards compatible with the Community version 4.2.d.
|
||||
* This class will be removed after Community 4.2.e has been released.
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RMACLEntryVoter extends ACLEntryVoter
|
||||
{
|
||||
public void setOwnableService(OwnableService ownableService)
|
||||
{
|
||||
boolean exists = false;
|
||||
Method[] declaredMethods = ACLEntryVoter.class.getDeclaredMethods();
|
||||
for (Method method : declaredMethods)
|
||||
{
|
||||
if (method.getName().equals("setOwnableService"))
|
||||
{
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (exists)
|
||||
{
|
||||
super.setOwnableService(ownableService);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.security.permissions.impl.acegi;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.alfresco.service.cmr.security.OwnableService;
|
||||
|
||||
/**
|
||||
* This is a workaround to make RM 2.1 backwards compatible with the Community version 4.2.d.
|
||||
* This class will be removed after Community 4.2.e has been released.
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.1
|
||||
*/
|
||||
public class RMACLEntryVoter extends ACLEntryVoter
|
||||
{
|
||||
public void setOwnableService(OwnableService ownableService)
|
||||
{
|
||||
boolean exists = false;
|
||||
Method[] declaredMethods = ACLEntryVoter.class.getDeclaredMethods();
|
||||
for (Method method : declaredMethods)
|
||||
{
|
||||
if (method.getName().equals("setOwnableService"))
|
||||
{
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (exists)
|
||||
{
|
||||
super.setOwnableService(ownableService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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>();
|
||||
}
|
||||
}
|
||||
|
@@ -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>();
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user