cancel
Showing results for 
Search instead for 
Did you mean: 

How to split Alfresco workflow files based on file type in Parallel Gateway to direct it into two diffrent path

rahiakela
Confirmed Champ
Confirmed Champ

I want to split Alfresco workflow files based on file type(like word and pdf) in Parallel Gateway to direct it into two diffrent path.That is shown in below image, like word file is going to other path and pdf is going to another path.

I am using parallel gateway, it is right way or need some other gateway for this type of problem ? and I also want to process both files at the same time parallelly.

I am new to Alfresco workflow implementation, so please help me.

5 REPLIES 5

gdharley
Elite Collaborator
Elite Collaborator

You need an exclusive gateway rather than a parallel gateway.

Parallel gateways execute all flow paths, exclusive gateways will only select the first that matches a specific condition (in your case the filetype).

Greg

Thanks Harley,

I have change parallel gateways to exclusive gateways as shown below:

And write code to get mimetype of file as shown below:

TaskListener Class:

package com.knovel.workflow.scripts;

import org.activiti.engine.ProcessEngine;
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.workflow.WorkflowNotificationUtils;
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.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;

public class FileTypeCheckTaskListener implements TaskListener{

private ProcessEngine activitiProcessEngine;

//private ServiceRegistry serviceRegistry;

@Override
public void notify(DelegateTask task) {
try {
//getting service registry and node service
ServiceRegistry serviceRegistry = getServiceRegistry();
System.out.println("serviceRegistry:"+serviceRegistry);

//ContentService contentService = serviceRegistry.getContentService();
NodeService nodeService = serviceRegistry.getNodeService();
System.out.println("nodeService:"+nodeService);

//getting bpm_package from task
//ActivitiScriptNode packageNode=(ActivitiScriptNode) task.getVariable("bpm_package");
ActivitiScriptNode packageNode=(ActivitiScriptNode)task.getVariable(WorkflowNotificationUtils.PROP_PACKAGE);
System.out.println("packageNode:"+packageNode);

//getting child node ref of bpm_package
NodeRef nodeRef = packageNode.getNodeRef();
System.out.println("nodeRef:"+nodeRef);
NodeRef docRef = serviceRegistry.getNodeService().getChildAssocs(nodeRef).get(0).getChildRef();
System.out.println("docRef:"+docRef);

//getting content data type from child node ref
ContentData contentData=(ContentData) nodeService.getProperty(docRef, ContentModel.PROP_CONTENT);
System.out.println("contentData:"+contentData);
String nodeMimeType=contentData.getMimetype();
System.out.println("MimeType found:"+nodeMimeType);

task.setVariable("wf_file_type_pdf", false);
task.setVariable("wf_file_type_word", false);
//checking the file type
if(nodeMimeType.contains("pdf")){
task.setVariable("wf_file_type_pdf", true);
} else if(nodeMimeType.contains("word")){
task.setVariable("wf_file_type_word", true);
} else{
System.out.println("There is no supported file type with task id "+task.getId());
}

task.setVariable("bpm_assignee", task.getVariable("bpm_assignee"));
task.setVariable("bpm_comment", task.getVariable("bpm_comment"));
task.setVariable("bpm_dueDate", task.getVariable("bpm_dueDate"));
task.setVariable("bpm_priority", task.getVariable("bpm_priority"));
} catch (Exception e) {
e.printStackTrace();
}

}

protected 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");
}

public void setActivitiProcessEngine(ProcessEngine activitiProcessEngine) {
this.activitiProcessEngine = activitiProcessEngine;
}

}

Bean-Context Mapping:

<bean id="fileTypeCheckTaskListener" class="com.knovel.workflow.scripts.FileTypeCheckTaskListener">
<property name="activitiProcessEngine" ref="activitiProcessEngine"/>
<!-- <property name="serviceRegistry" ref="ServiceRegistry"/> -->
</bean>

After this implementation, I am getting this error in runtime:

 And getting this error on console:

serviceRegistrySmiley Surprisedrg.alfresco.repo.service.ServiceDescriptorRegistry@91aa814
nodeServiceSmiley Surprisedrg.alfresco.repo.node.db.DbNodeServiceImpl@22c00d93
net.sf.acegisecurity.providers.ProviderNotFoundException: No authentication provider for net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken
at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:169)
at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:376)
at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:159)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.alfresco.repo.transaction.RetryingTransactionInterceptor$1.execute(RetryingTransactionInterceptor.java:79)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:457)
at org.alfresco.repo.transaction.RetryingTransactionInterceptor.invoke(RetryingTransactionInterceptor.java:69)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at com.sun.proxy.$Proxy42.exists(Unknown Source)
at org.alfresco.repo.jscript.ScriptNode.toString(ScriptNode.java:3335)
at java.lang.String.valueOf(String.java:2994)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at com.knovel.workflow.scripts.FileTypeCheckTaskListener.notify(FileTypeCheckTaskListener.java:37)
at org.activiti.engine.impl.delegate.TaskListenerInvocation.invoke(TaskListenerInvocation.java:34)
at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
at org.activiti.engine.impl.bpmn.helper.ClassDelegate.notify(ClassDelegate.java:119)
at org.activiti.engine.impl.delegate.TaskListenerInvocation.invoke(TaskListenerInvocation.java:34)
at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
at org.activiti.engine.impl.persistence.entity.TaskEntity.fireEvent(TaskEntity.java:738)
at org.activiti.engine.impl.persistence.entity.TaskEntity.complete(TaskEntity.java:184)
at org.activiti.engine.impl.cmd.CompleteTaskCmd.execute(CompleteTaskCmd.java:52)
at org.activiti.engine.impl.cmd.CompleteTaskCmd.execute(CompleteTaskCmd.java:24)
at org.activiti.engine.impl.cmd.NeedsActiveTaskCmd.execute(NeedsActiveTaskCmd.java:59)
at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:47)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)
at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:45)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:35)
at org.activiti.engine.impl.TaskServiceImpl.complete(TaskServiceImpl.java:175)
at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.endNormalTask(ActivitiWorkflowEngine.java:1403)
at org.alfresco.repo.workflow.activiti.ActivitiWorkflowEngine.endTask(ActivitiWorkflowEngine.java:1377)
at org.alfresco.repo.workflow.WorkflowServiceImpl.endTask(WorkflowServiceImpl.java:1028)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

gdharley
Elite Collaborator
Elite Collaborator

I believe this is somethign you will need to contact Alfresco ECM support about.

The key error in the stack is:

net.sf.acegisecurity.providers.ProviderNotFoundException: No authentication provider for net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken

Greg

rahiakela
Confirmed Champ
Confirmed Champ

I am not able to get file type from this code:

<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.listener.ScriptExecutionListener">
<activiti:field name="script">
<activiti:string><![CDATA[execution.setVariable('bpm_assignee', task.getVariable('bpm_assignee'));
execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));
execution.setVariable('wf_manager', person);
execution.setVariable('bpm_dueDate', task.dueDate);
execution.setVariable('bpm_priority', task.priority);

var fileExtention="";

for (var i = 0; i < bpm_package.children.length; i++) {
var child = bpm_package.children[i];

var fileArray = child.properties['cm:name'].split('.');
fileExtention = fileArray[fileArray.length-1];
}

if(fileExtention.indexOf('pdf') > 0){
execution.setVariable('wf_file_type_pdf', true);
} else{
execution.setVariable('wf_file_type_pdf', false);
}]]></activiti:string>
</activiti:field>
</activiti:taskListener>

The above code does not give the file extention, could you correct me, where I am doing wrong ?

Thanks

Rahi

I have done it with Alfresco jscripting as follows:

<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">       <activiti:field name="script">         <activiti:string><![CDATA[execution.setVariable('bpm_assignee', task.getVariable('bpm_assignee'));             execution.setVariable('bpm_comment', task.getVariable('bpm_comment'));             execution.setVariable('wf_manager', person);             execution.setVariable('bpm_dueDate', task.dueDate);             execution.setVariable('bpm_priority', task.priority);              var fileExtention="";              for (var i = 0; i < bpm_package.children.length; i++) {                 var child = bpm_package.children[i];                  var fileArray = child.properties['cm:name'].split('.');                  logger.log("#############FileArray >>"+fileArray);                 fileExtention = fileArray[fileArray.length-1];                    logger.log("###########FileExtention1  >>"+fileExtention );                 break;             }              logger.log("#############FileExtention2  >>"+fileExtention );             if(fileExtention.indexOf('pdf') != -1){                 execution.setVariable('wf_file_type_pdf', true);                 logger.log("##############PDF found##################");             } else{                 execution.setVariable('wf_file_type_pdf', false);                 logger.log("##############Word found##################");             }]]></activiti:string>       </activiti:field>     </activiti:taskListener>

Now I am able to get file type and it is working fine. Thanks for support!!!