cancel
Showing results for 
Search instead for 
Did you mean: 

File Listener - Read file and create cases

atanus
Champ in-the-making
Champ in-the-making
I want read a file (.excel,.csv) from a network location and create cases in Activiti for each row in the file.
Do we have anything OOTB in Activiti?
Has someone done this before?
Some guidance on the approach and components to use etc. will be helpful.

Thanks
Atanu
6 REPLIES 6

jbarrez
Star Contributor
Star Contributor

- What do you mean with 'cases' in Activiti? Tasks? Process instances? They all can be created dynamically with Activiti.

- Reading an excel file is not OOTB possible, but we do have Aspose integrated in Activiti that can read and parse excel files. So you could have a simple service task that uses the Aspose API to read and process that excel file.

atanus
Champ in-the-making
Champ in-the-making
Thanks.
cases = process instances.
This task needs to run in the background and monitor a network drive for new file arrival. How can we achieve this in Activiti Enterprise?

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Atanus,

I would use spring integration for pooling directory.
e.g.:

<int-file:inbound-channel-adapter id="filePoller"
    channel="inboundFileChannel"
    directory="file:/tmp/myfiles/"
    filename-pattern="*.csv">
  <int:smileytongue:oller fixed-rate="1000"/>
</int-file:inbound-channel-adapter>

based on the new file arrival, process to parse csv file can be started….

Regards
Martin

Hi Martin ,  here I am providing the entire source code with Annotations and I was getting the Exception which I mentioned in the earlier comment.. Please suggest.




@Component("cSVFileProcessor")
@Configuration
@IntegrationComponentScan
@EnableIntegration
@MessageEndpoint
public class CSVFileProcessor {

public static FileReadingMessageSource getFileReadingMessageSource() {
try {
if (fileReadingMessageSource == null) {
fileReadingMessageSource = new FileReadingMessageSource();
fileReadingMessageSource.setDirectory(new File(folderPath));
SimplePatternFileListFilter simplePatternFileListFilter = new SimplePatternFileListFilter(
filePattern);
IgnoreHiddenFileListFilter ignoreHiddenFileListFilter = new IgnoreHiddenFileListFilter();
List> fileListFilter = new ArrayList>();
fileListFilter.add(simplePatternFileListFilter);
fileListFilter.add(ignoreHiddenFileListFilter);
compositeFileListFilter = new CompositeFileListFilter(
fileListFilter);
CustomScanner cs = new CustomScanner();
cs.setFilter(compositeFileListFilter);
fileReadingMessageSource.setScanner(cs);
logger.info("In static method after Initializing frms "
+ fileReadingMessageSource);
}
} catch (Exception e) {
logger.debug("Exception while creating FileReadingMessageSource");
logger.debug("Exception while creating FileReadingMessageSource", e);
return null;
}
return fileReadingMessageSource;
}

@InboundChannelAdapter(value = "inboundchannel", poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
public Message<File> processFiles() {
    fileReadingMessageSource = getFileReadingMessageSource();

    return fileReadingMessageSource.receive();
}

@ServiceActivator(inputChannel = "inboundchannel")
public void process(Message<File> payload) {
    logger.info("In process() … payload is" + payload.getClass());

        processFile(payload);


}
}

atanus
Champ in-the-making
Champ in-the-making
Thanks for the direction.

sudheerm
Champ in-the-making
Champ in-the-making
Hi Martin,

we developed File Listener based on Spring Annotations which are equivalent to the above approach you mentioned,but Spring is not able to auto create MessageChannel Bean with name "inboundchannel" and an exception is being thrown. will you be able to help here  please ?

Code Snippet :

public static FileReadingMessageSource getFileReadingMessageSource() {
  try {
   if (fileReadingMessageSource == null) {
    fileReadingMessageSource = new FileReadingMessageSource();
    fileReadingMessageSource.setDirectory(new File(folderPath));
    SimplePatternFileListFilter simplePatternFileListFilter = new SimplePatternFileListFilter(
      filePattern);
    IgnoreHiddenFileListFilter ignoreHiddenFileListFilter = new IgnoreHiddenFileListFilter();
    List<FileListFilter<File>> fileListFilter = new ArrayList<FileListFilter<File>>();
    fileListFilter.add(simplePatternFileListFilter);
    fileListFilter.add(ignoreHiddenFileListFilter);
    compositeFileListFilter = new CompositeFileListFilter<File>(
      fileListFilter);
    CustomScanner cs = new CustomScanner();
    cs.setFilter(compositeFileListFilter);
    fileReadingMessageSource.setScanner(cs);
   
   }
  } catch (Exception e) {
   logger.debug("Exception while creating FileReadingMessageSource");
     }
  return fileReadingMessageSource;
}


@InboundChannelAdapter(value = "inboundchannel", poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
public MessageSource<File> processFiles() {
  fileReadingMessageSource = getFileReadingMessageSource();
  logger.info("In processFiles() after getting FileReadingMessageSource from static method  "
    + fileReadingMessageSource);
  return fileReadingMessageSource;
}
@ServiceActivator(inputChannel = "inboundchannel")
public void process(Message<File> payload) {
  logger.info("In process() … payload is" + payload.getClass());
 
   processFile(payload);
 
}


Exception details :


Dec 21, 2015 3:22:11 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class com.activiti.servlet.WebConfigurer
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cSVFileProcessor' defined in URL [jar:file:/xjp/appserver_1/tomcat/apache-tomcat-7.0.42/webapps/activiti-app/WEB-INF/lib/nexen-workflow-ext-0.0.3.jar!/com/activiti/extension/bean/CSVFileProcessor.class]: Initialization of bean failed; nested exception is org.springframework.messaging.core.DestinationResolutionException: failed to look up MessageChannel with name 'inboundchannel' in the BeanFactory.; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'inboundchannel' is defined
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at com.activiti.servlet.WebConfigurer.contextInitialized(WebConfigurer.java:67)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
        at com.activiti.servlet.WebConfigurer.contextInitialized(WebConfigurer.java:67)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
        at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)
Caused by: org.springframework.messaging.core.DestinationResolutionException: failed to look up MessageChannel with name 'inboundchannel' in the BeanFactory.; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'inboundchannel' is defined
        at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:112)
        at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:45)
        at org.springframework.integration.config.annotation.InboundChannelAdapterAnnotationPostProcessor.postProcess(InboundChannelAdapterAnnotationPostProcessor.java:64)
        at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor$1.doWith(MessagingAnnotationPostProcessor.java:177)
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:494)
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:501)
        at org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor.postProcessAfterInitialization(MessagingAnnotationPostProcessor.java:145)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
        … 23 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'inboundchannel' is defined
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at org.springframework.integration.support.channel.BeanFactoryChannelResolver.resolveDestination(BeanFactoryChannelResolver.java:88)
        … 32 more

Dec 21, 2015 3:22:11 PM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class com.activiti.servlet.WebConfigurer
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
        at org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:83)
        at com.activiti.servlet.WebConfigurer.contextDestroyed(WebConfigurer.java:230)
        at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980)
        at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626)
        at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
        at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:722)