Skip to content

Commit 3b82f7a

Browse files
committed
another activiti example
1 parent da3ae99 commit 3b82f7a

23 files changed

+1058
-0
lines changed

activiti-example2/pom.xml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.activiti.examples</groupId>
5+
<artifactId>activiti-examples</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<name>BPMN 2.0 with Activiti - Examples</name>
9+
<properties>
10+
<activiti-version>5.9</activiti-version>
11+
</properties>
12+
<dependencies>
13+
14+
<dependency>
15+
<groupId>org.activiti</groupId>
16+
<artifactId>activiti-engine</artifactId>
17+
<version>${activiti-version}</version>
18+
</dependency>
19+
20+
<dependency>
21+
<groupId>org.activiti</groupId>
22+
<artifactId>activiti-spring</artifactId>
23+
<version>${activiti-version}</version>
24+
</dependency>
25+
26+
<dependency>
27+
<groupId>org.codehaus.groovy</groupId>
28+
<artifactId>groovy</artifactId>
29+
<version>1.7.5</version>
30+
</dependency>
31+
32+
<dependency>
33+
<groupId>com.h2database</groupId>
34+
<artifactId>h2</artifactId>
35+
<version>1.2.132</version>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>junit</groupId>
40+
<artifactId>junit</artifactId>
41+
<version>4.8.1</version>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>log4j</groupId>
46+
<artifactId>log4j</artifactId>
47+
<version>1.2.16</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>org.apache.commons</groupId>
52+
<artifactId>commons-lang3</artifactId>
53+
<version>3.0</version>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>commons-io</groupId>
58+
<artifactId>commons-io</artifactId>
59+
<version>2.4</version>
60+
</dependency>
61+
62+
63+
</dependencies>
64+
<repositories>
65+
<repository>
66+
<id>Activiti</id>
67+
<url>http://maven.alfresco.com/nexus/content/repositories/activiti</url>
68+
</repository>
69+
</repositories>
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-compiler-plugin</artifactId>
75+
<version>2.3.2</version>
76+
<configuration>
77+
<source>1.6</source>
78+
<target>1.6</target>
79+
</configuration>
80+
</plugin>
81+
<plugin>
82+
<groupId>org.apache.maven.plugins</groupId>
83+
<artifactId>maven-eclipse-plugin</artifactId>
84+
<inherited>true</inherited>
85+
<configuration>
86+
<classpathContainers>
87+
<classpathContainer>org.eclipse.jdt.USER_LIBRARY/Activiti Designer Extensions</classpathContainer>
88+
</classpathContainers>
89+
</configuration>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
http://sourceforge.net/projects/uengine/?source=recommended
2+
http://sourceforge.net/projects/cuteflow/?source=recommended
3+
http://sourceforge.net/projects/jogetworkflow/?source=recommended
4+
http://sourceforge.net/projects/bpmnpop/?source=recommended
5+
http://sourceforge.net/projects/itposter/files/latest/download
6+
7+
8+
9+
Information:
10+
http://www.bpmb.de/index.php/Bild:Poster_en.png
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.cherkashyn.vitaliy;
2+
3+
import java.util.logging.Logger;
4+
5+
import org.springframework.context.support.ClassPathXmlApplicationContext;
6+
7+
public class ExcelProcessorGui {
8+
public static void main(String[] args){
9+
Logger logger=Logger.getLogger(ExcelProcessorGui.class.getName());
10+
logger.info("begin");
11+
ClassPathXmlApplicationContext applicationContext =new ClassPathXmlApplicationContext("classpath*:application.xml");
12+
// RuntimeService runtimeService=applicationContext.getBean(RuntimeService.class);
13+
logger.info("Context load OK :"+applicationContext.getId());
14+
logger.info("-end-");
15+
}
16+
17+
18+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.cherkashyn.vitaliy.bpmn.diagram_scaner;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.io.UnsupportedEncodingException;
6+
import java.text.MessageFormat;
7+
import java.util.List;
8+
9+
import javax.xml.parsers.ParserConfigurationException;
10+
11+
import org.activiti.engine.RepositoryService;
12+
import org.activiti.engine.repository.DeploymentBuilder;
13+
import org.apache.commons.io.IOUtils;
14+
import org.apache.commons.lang3.StringUtils;
15+
import org.apache.commons.lang3.tuple.Pair;
16+
import org.apache.log4j.Logger;
17+
import org.springframework.beans.factory.annotation.Autowired;
18+
import org.w3c.dom.Document;
19+
import org.xml.sax.SAXException;
20+
21+
import com.cherkashyn.vitaliy.bpmn.utility.InputStreamIterator;
22+
import com.cherkashyn.vitaliy.bpmn.utility.XmlUtility;
23+
import com.cherkashyn.vitaliy.bpmn.xml_extender.XmlProcessor;
24+
25+
public class DiagramLoader {
26+
private static final Logger logger=Logger.getLogger(DiagramLoader.class);
27+
@Autowired(required=true)
28+
RepositoryService repositoryService;
29+
30+
@Autowired(required=true)
31+
InputStreamIterator inputStreamIterator;
32+
33+
private final static String magicStringForActiviti="bpmn20.xml";
34+
35+
public void init() throws Exception, IOException, SAXException, ParserConfigurationException {
36+
DeploymentBuilder builder= repositoryService.createDeployment();
37+
for(Pair<String, InputStream> eachFile:inputStreamIterator){
38+
logger.debug(MessageFormat.format("Load data from file: {0}", eachFile.getKey()));
39+
Document document=convertStringToXml(getStringFromInputStream(eachFile.getValue()));
40+
String key=StringUtils.removeEnd(getFileName(eachFile.getKey()),".");
41+
document=filterIntercepter(document, key);
42+
logger.debug(getStringFromXml(document));
43+
builder.addInputStream(key+magicStringForActiviti,
44+
IOUtils.toInputStream(getStringFromXml(document)));
45+
}
46+
builder.deploy();
47+
}
48+
49+
private String getStringFromXml(Document document) {
50+
return this.xmlUtility.getStringFromXml(document);
51+
}
52+
53+
private String getFileName(String fileName) {
54+
return StringUtils.substringBeforeLast(fileName, "bpmn20.xml");
55+
}
56+
57+
private XmlProcessor[] xmlProcessor;
58+
public void setXmlProcessors(XmlProcessor[] xmlProcessors){
59+
this.xmlProcessor=xmlProcessors;
60+
}
61+
62+
private Document filterIntercepter(Document document, String fileName) throws Exception{
63+
if(xmlProcessor!=null && xmlProcessor.length>0){
64+
for(XmlProcessor processor:xmlProcessor){
65+
document=processor.processDocument(document, fileName);
66+
}
67+
}
68+
return document;
69+
}
70+
71+
private XmlUtility xmlUtility=new XmlUtility();
72+
73+
private Document convertStringToXml(String xmlText) throws UnsupportedEncodingException, SAXException, IOException, ParserConfigurationException{
74+
return xmlUtility.getDocumentFromString(xmlText);
75+
}
76+
77+
private String getStringFromInputStream(InputStream inputStream) throws IOException{
78+
return linesToString(IOUtils.readLines(inputStream));
79+
}
80+
81+
private String linesToString(List<String> list){
82+
StringBuilder returnValue=new StringBuilder();
83+
if(list!=null && list.size()>0){
84+
for(String line:list){
85+
returnValue.append(line);
86+
}
87+
}
88+
return returnValue.toString();
89+
}
90+
91+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.cherkashyn.vitaliy.bpmn.utility;
2+
3+
import java.io.File;
4+
import java.io.FileFilter;
5+
import java.io.FileInputStream;
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.text.MessageFormat;
9+
import java.util.ArrayList;
10+
import java.util.Iterator;
11+
import java.util.List;
12+
13+
import org.apache.commons.lang3.StringUtils;
14+
import org.apache.commons.lang3.tuple.ImmutablePair;
15+
import org.apache.commons.lang3.tuple.Pair;
16+
import org.apache.log4j.Logger;
17+
18+
public class InputStreamIterator implements Iterable<Pair<String, InputStream>>{
19+
private final static Logger logger=Logger.getLogger(InputStreamIterator.class.getName());
20+
private String dir;
21+
private File[] files;
22+
23+
public InputStreamIterator(String pathToDirectory) throws IOException{
24+
this(pathToDirectory, BPMN_FILEFILTER);
25+
}
26+
27+
public InputStreamIterator(String pathToDirectory, FileFilter fileFilter) throws IOException{
28+
this.dir=pathToDirectory;
29+
this.init(fileFilter);
30+
}
31+
32+
protected void init(FileFilter fileFilter) throws IOException {
33+
File dirFile=new File(StringUtils.trim(this.dir));
34+
this.dir=dirFile.getAbsolutePath();
35+
if(dirFile.isDirectory()){
36+
files=dirFile.listFiles(fileFilter);
37+
}else{
38+
throw new IOException(MessageFormat.format("check Directory:{0} for existing",this.dir));
39+
}
40+
}
41+
42+
public String getPath(){
43+
return this.dir;
44+
}
45+
46+
@Override
47+
public Iterator<Pair<String,InputStream>> iterator() {
48+
List<Pair<String,InputStream>> returnValue=new ArrayList<Pair<String,InputStream>>();
49+
for(File file:this.files){
50+
try{
51+
returnValue.add(new ImmutablePair<String, InputStream>(file.getName(), new FileInputStream(file)));
52+
}catch(IOException ex){
53+
logger.error("Error, when try to open file ", ex);
54+
}
55+
}
56+
return returnValue.iterator();
57+
}
58+
59+
60+
public static FileFilter BPMN_FILEFILTER=new FileFilter(){
61+
private String suffix="bpmn20.xml";
62+
@Override
63+
public boolean accept(File file) {
64+
return (file.isFile() && StringUtils.endsWith(file.getName(), suffix));
65+
}
66+
};
67+
}

0 commit comments

Comments
 (0)