RM-631 (The records management team can create a rule to request information about an undeclared record)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@48973 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-04-08 20:55:50 +00:00
parent 900ac2fb54
commit 90a9bd99c0
8 changed files with 255 additions and 114 deletions

View File

@@ -24,17 +24,12 @@ import java.util.Map;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
import org.alfresco.repo.workflow.activiti.ActivitiScriptNode;
import org.alfresco.repo.workflow.activiti.ActivitiScriptNodeList;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.util.ParameterCheck;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* An assignment handler for the request info workflow.
@@ -56,7 +51,7 @@ public class RequestInfoAssignmentHandler implements TaskListener
ParameterCheck.mandatory("delegateTask", delegateTask);
// Set the workflow description for the task
delegateTask.setVariable("bpm_workflowDescription", getWorkflowDescription(delegateTask));
delegateTask.setVariable("bpm_workflowDescription", getWorkflowDescription(RequestInfoUtils.getRecordName(delegateTask)));
// Get the list of user(s) and/or group(s)
ActivitiScriptNodeList usersAndGroups = (ActivitiScriptNodeList) delegateTask.getVariable("rmwf_mixedAssignees");
@@ -115,42 +110,20 @@ public class RequestInfoAssignmentHandler implements TaskListener
}
}
private String getWorkflowDescription(DelegateTask delegateTask)
{
// FIXME: I18N!!!
return "Information requested for record '" + getRecordName(delegateTask) + "'";
}
private String getRecordName(DelegateTask delegateTask)
{
ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package");
NodeService nodeService = getServiceRegistry().getNodeService();
NodeRef docRef= nodeService.getChildAssocs(scriptNode.getNodeRef()).get(0).getChildRef();
return (String) nodeService.getProperty(docRef, ContentModel.PROP_NAME);
}
//FIXME: Is there a better way to call services?
/**
* Helper method for getting the service registry in order to call services
* Helper method for building the workflow description
*
* @return Returns the service registry
* @param recordName The name of the record
* @return Returns the workflow description
*/
private ServiceRegistry getServiceRegistry()
private String getWorkflowDescription(String recordName)
{
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null)
{
// Fetch the registry that is injected in the activiti spring-configuration
ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
if (registry == null)
{
throw new RuntimeException(
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
}
return registry;
}
throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");
StringBuilder sb = new StringBuilder();
sb.append(I18NUtil.getMessage("activitiReviewPooled.workflow.info.requested"));
sb.append(" '");
sb.append(recordName);
sb.append("'");
return sb.toString();
}
}

View File

@@ -20,18 +20,11 @@ package org.alfresco.workflow.requestInfo;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.notification.EMailNotificationProvider;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
import org.alfresco.repo.workflow.activiti.ActivitiScriptNode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.notification.NotificationContext;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.util.ParameterCheck;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Request info workflow notifier.
@@ -51,11 +44,14 @@ public class RequestInfoNotifier implements TaskListener
{
ParameterCheck.mandatory("delegateTask", delegateTask);
// Get the record name
String recordName = RequestInfoUtils.getRecordName(delegateTask);
// Set the workflow description for the task
delegateTask.setVariable("bpm_workflowDescription", getWorkflowDescription(delegateTask));
delegateTask.setVariable("bpm_workflowDescription", getWorkflowDescription(recordName));
// Assign the task to the initiator
String initiator = getInitiator(delegateTask);
String initiator = RequestInfoUtils.getInitiator(delegateTask);
delegateTask.setAssignee(initiator);
// Create the context and send an email to the initiator
@@ -63,71 +59,62 @@ public class RequestInfoNotifier implements TaskListener
notificationContext.setAsyncNotification(true);
notificationContext.setIgnoreNotificationFailure(true);
notificationContext.addTo(initiator);
// FIXME: I18N!!! and get the record name and the user name who provided the information
notificationContext.setSubject("Information provided for the record '" + "" + "'.");
notificationContext.setBody("The user '" + "' has provided the needed information for the record '" + "" + "'.");
notificationContext.setSubject(getEmailSubject(recordName));
notificationContext.setBody(getEmailBody(recordName));
// Send the email
getServiceRegistry().getNotificationService().sendNotification(EMailNotificationProvider.NAME, notificationContext);
RequestInfoUtils.getServiceRegistry().getNotificationService().sendNotification(EMailNotificationProvider.NAME, notificationContext);
}
/**
* Helper method to extract the initiator from the task
* Helper method for building the workflow description
*
* @param delegateTask The delegate task
* @return Returns the initiator of the workflow. If the initiator does not exist the admin user will be returned.
* @param recordName The name of the record
* @return Returns the workflow description
*/
private String getInitiator(DelegateTask delegateTask)
private String getWorkflowDescription(String recordName)
{
String userName = null;
ActivitiScriptNode initiator = (ActivitiScriptNode) delegateTask.getVariable("initiator");
if (initiator.exists())
{
userName = (String) initiator.getProperties().get(ContentModel.PROP_USERNAME.toString());
}
else
{
userName = AuthenticationUtil.getAdminUserName();
}
return userName;
StringBuilder sb = new StringBuilder();
sb.append(I18NUtil.getMessage("activitiReviewPooled.workflow.info.provided"));
sb.append(" '");
sb.append(recordName);
sb.append("'");
return sb.toString();
}
private String getWorkflowDescription(DelegateTask delegateTask)
{
// FIXME: I18N!!!
return "Information provided for record '" + getRecordName(delegateTask) + "'";
}
private String getRecordName(DelegateTask delegateTask)
{
ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package");
NodeService nodeService = getServiceRegistry().getNodeService();
NodeRef docRef= nodeService.getChildAssocs(scriptNode.getNodeRef()).get(0).getChildRef();
return (String) nodeService.getProperty(docRef, ContentModel.PROP_NAME);
}
//FIXME: Is there a better way to call services?
/**
* Helper method for getting the service registry in order to call services
* Helper method for building the email subject
*
* @return Returns the service registry
* @param recordName The name of the record
* @return Returns the email subject
*/
private ServiceRegistry getServiceRegistry()
private String getEmailSubject(String recordName)
{
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null)
{
// Fetch the registry that is injected in the activiti spring-configuration
ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
if (registry == null)
{
throw new RuntimeException(
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
}
return registry;
}
throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");
StringBuilder sb = new StringBuilder();
sb.append(I18NUtil.getMessage("activitiReviewPooled.workflow.email.subject"));
sb.append(" '");
sb.append(recordName);
sb.append("'");
return sb.toString();
}
/**
* Helper method for building the email body
*
* @param recordName The name of the record
* @return Returns the email body
*/
private String getEmailBody(String recordName)
{
StringBuilder sb = new StringBuilder();
sb.append(I18NUtil.getMessage("activitiReviewPooled.workflow.email.body1"));
sb.append(" '");
sb.append(AuthenticationUtil.getFullyAuthenticatedUser());
sb.append("' ");
sb.append(I18NUtil.getMessage("activitiReviewPooled.workflow.email.body2"));
sb.append(" '");
sb.append(recordName);
sb.append("'.");
return sb.toString();
}
}

View File

@@ -0,0 +1,119 @@
/*
* Copyright (C) 2005-2013 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.workflow.requestInfo;
import java.util.List;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.context.Context;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.workflow.activiti.ActivitiConstants;
import org.alfresco.repo.workflow.activiti.ActivitiScriptNode;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.util.ParameterCheck;
import org.apache.commons.lang.StringUtils;
/**
* Util class for the request info workflow
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RequestInfoUtils
{
//FIXME: Is there a better way to call services?
/**
* Helper method to get the service registry in order to call services
*
* @return Returns the service registry
*/
public static ServiceRegistry getServiceRegistry()
{
ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
if (config != null)
{
// Fetch the registry that is injected in the activiti spring-configuration
ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
if (registry == null)
{
throw new RuntimeException(
"Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
}
return registry;
}
throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");
}
/**
* Helper method to extract the record name from the task
*
* @param delegateTask The delegate task
* @return Returns the name of the record or an empty string if the record name could not be found
(may be because the record has been deleted in the mean time)
*/
public static String getRecordName(DelegateTask delegateTask)
{
ParameterCheck.mandatory("delegateTask", delegateTask);
String recordName = StringUtils.EMPTY;
NodeService nodeService = getServiceRegistry().getNodeService();
ActivitiScriptNode scriptNode = (ActivitiScriptNode) delegateTask.getVariable("bpm_package");
List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(scriptNode.getNodeRef());
if (childAssocs.size() > 0)
{
NodeRef docRef= childAssocs.get(0).getChildRef();
recordName = (String) nodeService.getProperty(docRef, ContentModel.PROP_NAME);
}
return recordName;
}
/**
* Helper method to extract the initiator from the task
*
* @param delegateTask The delegate task
* @return Returns the initiator of the workflow. If the initiator does not exist the admin user name will be returned.
*/
public static String getInitiator(DelegateTask delegateTask)
{
ParameterCheck.mandatory("delegateTask", delegateTask);
String userName = null;
ActivitiScriptNode initiator = (ActivitiScriptNode) delegateTask.getVariable("initiator");
if (initiator.exists())
{
userName = (String) initiator.getProperties().get(ContentModel.PROP_USERNAME.toString());
}
else
{
userName = AuthenticationUtil.getAdminUserName();
}
return userName;
}
}