Browse Source

First Commit

ailton 8 years ago
commit
5598adb80c

+ 20 - 0
.classpath

@@ -0,0 +1,20 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<classpath>
3
+	<classpathentry kind="src" output="target/classes" path="src">
4
+		<attributes>
5
+			<attribute name="optional" value="true"/>
6
+			<attribute name="maven.pomderived" value="true"/>
7
+		</attributes>
8
+	</classpathentry>
9
+	<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
10
+		<attributes>
11
+			<attribute name="maven.pomderived" value="true"/>
12
+		</attributes>
13
+	</classpathentry>
14
+	<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
15
+		<attributes>
16
+			<attribute name="maven.pomderived" value="true"/>
17
+		</attributes>
18
+	</classpathentry>
19
+	<classpathentry kind="output" path="target/classes"/>
20
+</classpath>

+ 23 - 0
.project

@@ -0,0 +1,23 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>officialjournal-extractor</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.jdt.core.javabuilder</name>
10
+			<arguments>
11
+			</arguments>
12
+		</buildCommand>
13
+		<buildCommand>
14
+			<name>org.eclipse.m2e.core.maven2Builder</name>
15
+			<arguments>
16
+			</arguments>
17
+		</buildCommand>
18
+	</buildSpec>
19
+	<natures>
20
+		<nature>org.eclipse.m2e.core.maven2Nature</nature>
21
+		<nature>org.eclipse.jdt.core.javanature</nature>
22
+	</natures>
23
+</projectDescription>

+ 12 - 0
.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
1
+eclipse.preferences.version=1
2
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5
+org.eclipse.jdt.core.compiler.compliance=1.8
6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
8
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
12
+org.eclipse.jdt.core.compiler.source=1.8

+ 4 - 0
.settings/org.eclipse.m2e.core.prefs

@@ -0,0 +1,4 @@
1
+activeProfiles=
2
+eclipse.preferences.version=1
3
+resolveWorkspaceProjects=true
4
+version=1

+ 43 - 0
pom.xml

@@ -0,0 +1,43 @@
1
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2
+  <modelVersion>4.0.0</modelVersion>
3
+  <groupId>corg.develop.officialjournal</groupId>
4
+  <artifactId>extractor</artifactId>
5
+  <version>1.0</version>
6
+  <build>
7
+    <sourceDirectory>src</sourceDirectory>
8
+    <plugins>
9
+      <plugin>
10
+        <artifactId>maven-compiler-plugin</artifactId>
11
+        <version>3.3</version>
12
+        <configuration>
13
+          <source>1.8</source>
14
+          <target>1.8</target>
15
+        </configuration>
16
+      </plugin>
17
+      
18
+      
19
+    </plugins>
20
+  </build>
21
+  <dependencies>
22
+  <dependency>
23
+  	<groupId>com.develop</groupId>
24
+  	<artifactId>doDatabase</artifactId>
25
+  	<version>0.0.1-SNAPSHOT</version>
26
+  </dependency>
27
+  <dependency>
28
+  	<groupId>org.graphstream</groupId>
29
+  	<artifactId>gs-core</artifactId>
30
+  	<version>1.2</version>
31
+  </dependency>
32
+  <dependency>
33
+  	<groupId>org.jgrapht</groupId>
34
+  	<artifactId>jgrapht-core</artifactId>
35
+  	<version>0.9.2</version>
36
+  </dependency>
37
+  <dependency>
38
+  	<groupId>org.jgrapht</groupId>
39
+  	<artifactId>jgrapht-ext</artifactId>
40
+  	<version>0.9.1</version>
41
+  </dependency>
42
+  </dependencies>
43
+</project>

+ 47 - 0
src/graph/StartExtractorDO.java

@@ -0,0 +1,47 @@
1
+package graph;
2
+
3
+import java.util.Properties;
4
+
5
+import graph.extractor.ExtractorGraph;
6
+import graph.input.file.InputFolder;
7
+import graph.input.file.InputSTJ;
8
+import graph.output.database.DatabaseOutput;
9
+import graph.properties.ExtractorProperties;
10
+
11
+public class StartExtractorDO {
12
+
13
+	public static void main(String[] args) {
14
+		// TODO Auto-generated method stub
15
+				
16
+		/**Starts all properties*/
17
+		Properties exctractorProperites = new ExtractorProperties();
18
+		InputFolder folder = new InputFolder(exctractorProperites);
19
+		
20
+		/**Extractor**/
21
+		ExtractorGraph exctractorGraph = new ExtractorGraph();
22
+		
23
+		
24
+		/**Add the inputs*/
25
+			exctractorGraph.addInput(new InputSTJ(folder));
26
+		/***/
27
+		
28
+		
29
+			
30
+		/**Do the process on this part all the most CPU will be usage*/
31
+		exctractorGraph.process();
32
+		
33
+		/**add the Output*/
34
+			exctractorGraph.addOutPut(new DatabaseOutput());
35
+			//exctractorGraph.addOutPut(new ScreenOutput());
36
+		/******/
37
+			
38
+			
39
+			
40
+		/**Shows the result*/
41
+		exctractorGraph.outPut();
42
+		
43
+		
44
+		
45
+	}
46
+
47
+}

+ 78 - 0
src/graph/extractor/ExtractorGraph.java

@@ -0,0 +1,78 @@
1
+package graph.extractor;
2
+
3
+
4
+import java.util.ArrayList;
5
+import java.util.List;
6
+
7
+import graph.extractor.graph.builder.BuilderFactory;
8
+import graph.input.file.InputFactory;
9
+import graph.output.OutPutFactory;
10
+
11
+public class ExtractorGraph {
12
+	
13
+	
14
+	List<InputFactory> inputs = new ArrayList<InputFactory>();
15
+//	List<DOProcess> allProcess = new ArrayList<DOProcess>();
16
+	List<OutPutFactory> outputs = new ArrayList<OutPutFactory>();
17
+	BuilderFactory builder;
18
+	
19
+	
20
+	
21
+	public void addInput(InputFactory input) {
22
+		// TODO Auto-generated method stub
23
+		this.inputs.add(input);
24
+		
25
+		
26
+	}
27
+
28
+	public void process() {
29
+		
30
+		
31
+		for(InputFactory input: this.inputs  )
32
+		{
33
+			builder= input.getBuilder();
34
+			builder.cacheFilesToMemory(input);
35
+			 
36
+		}
37
+		
38
+		// TODO Auto-generated method stub
39
+		
40
+	}
41
+
42
+	public void addOutPut(OutPutFactory output) {
43
+		
44
+		this.outputs.add(output);
45
+		
46
+	}
47
+
48
+	
49
+	public void outPut() {
50
+		
51
+		
52
+		for(OutPutFactory output: this.outputs)
53
+		{
54
+			builder.extractAllProcesses(output);
55
+			output.print();
56
+			
57
+		}
58
+		
59
+
60
+	}
61
+
62
+}
63
+//File file = new File("/home/ailton/Monografia/file.txt");
64
+//try{
65
+//
66
+//	
67
+//FileWriter fw = new FileWriter(file);
68
+//for( DOProcess process : this.allProcess )
69
+//{
70
+//	fw.write(process.toString());
71
+//}
72
+//}catch
73
+//(Exception e)
74
+//{
75
+//	e.printStackTrace();
76
+//}
77
+
78
+//

+ 128 - 0
src/graph/extractor/graph/builder/BuilderFactory.java

@@ -0,0 +1,128 @@
1
+package graph.extractor.graph.builder;
2
+
3
+import java.io.File;
4
+import java.nio.file.Files;
5
+import java.util.ArrayList;
6
+import java.util.List;
7
+import java.util.Random;
8
+
9
+import entity.DOProcess;
10
+import graph.input.file.InputFactory;
11
+import graph.output.OutPutFactory;
12
+
13
+public abstract class BuilderFactory {
14
+
15
+	protected List<DOProcess> processes;
16
+	protected InputFactory input;
17
+
18
+	public BuilderFactory(){
19
+		this.processes = new ArrayList<DOProcess>();
20
+
21
+	}
22
+
23
+	public void cacheFilesToMemory(InputFactory input){
24
+		this.input = input;
25
+	}
26
+
27
+
28
+	public void extractAllProcesses(OutPutFactory output){
29
+
30
+		File DoFolder = input.getDOFolder();
31
+		List<File> allDateFiles = new ArrayList<File>( input.getFilesFromDate(DoFolder));
32
+		long originalSize = allDateFiles.size();
33
+		
34
+		
35
+		while(allDateFiles.size() > 0)
36
+		{
37
+			try{
38
+				Random rand = new Random();
39
+				
40
+				int randNumber = Math.abs(rand.nextInt(allDateFiles.size()));
41
+				File oneDayOfDO = allDateFiles.get(randNumber);
42
+				
43
+				List<String> allProcess  = input.getAllProcess(oneDayOfDO);
44
+				
45
+				System.out.println("Processando dia "+oneDayOfDO.getName() + "---> " + allProcess.size() +" processos");
46
+				System.out.println("Processados " +(originalSize - allDateFiles.size())+" de " + originalSize+" diarios");
47
+				for(String oneProcess: allProcess)
48
+				{
49
+					DOProcess process = this.extractProcess(oneProcess);
50
+					if(process != null)
51
+					{
52
+						process.setProcessDate(oneDayOfDO.getName());
53
+						this.processes.add(process);
54
+					}
55
+				}
56
+				output.buildOutput(this.processes);
57
+				
58
+				this.moveDoneFiles(oneDayOfDO);
59
+				this.processes.clear();
60
+				allProcess.clear();
61
+				allDateFiles.remove(oneDayOfDO);
62
+				
63
+			}catch(Exception e)
64
+			{
65
+				e.printStackTrace();
66
+			}
67
+			
68
+			System.out.println( "Completado " +(originalSize - allDateFiles.size())+" de " + originalSize +". Faltam "+ allDateFiles.size() +" Processos");
69
+			System.out.println("\n\n\n\n");
70
+			
71
+
72
+		}
73
+
74
+	/*	for(File oneDayOfDO : allDateFiles )
75
+		{
76
+			List<String> allProcess  = input.getAllProcess(oneDayOfDO);
77
+
78
+			for(String oneProcess: allProcess)
79
+			{
80
+				DOProcess process = this.extractProcess(oneProcess);
81
+				if(process != null)
82
+				{
83
+					process.setProcessDate(oneDayOfDO.getName());
84
+					this.processes.add(process);	
85
+				}
86
+			}
87
+
88
+			output.buildOutput(this.processes);
89
+			this.processes.clear();
90
+			allProcess.clear();
91
+		}*/
92
+
93
+
94
+
95
+	}
96
+
97
+	private void moveDoneFiles(File oneDayOfDO) {
98
+		
99
+		try{
100
+			
101
+		
102
+		List<File> files = input.getFilesFromDate(oneDayOfDO);
103
+		
104
+		
105
+		
106
+		for(File file: files)
107
+		{
108
+			File doneFolder = new File("/home/ailton/Monografia/done/"+file.getName());
109
+			Files.move(file.toPath(), doneFolder.toPath());
110
+			
111
+		}}catch(Exception e)
112
+		{
113
+			e.printStackTrace();
114
+		}
115
+		
116
+		
117
+	}
118
+
119
+	public List<DOProcess> getAllProcess()
120
+	{
121
+		return this.processes;
122
+	}
123
+
124
+	protected abstract DOProcess extractProcess(String process);
125
+
126
+
127
+
128
+}

+ 229 - 0
src/graph/extractor/graph/builder/STJBuilder.java

@@ -0,0 +1,229 @@
1
+package graph.extractor.graph.builder;
2
+
3
+import entity.DOProcess;
4
+import entity.Entity;
5
+import entity.Judge;
6
+import entity.Lawyer;
7
+import entity.ProcessTypes;
8
+import entity.TYPES;
9
+
10
+public class STJBuilder extends BuilderFactory{
11
+
12
+
13
+
14
+	private Entity getEntity(String canditate)
15
+	{
16
+		Entity entity = new Entity();
17
+
18
+		try{
19
+
20
+
21
+			if(canditate.contains(":") && !canditate.contains("Distribuição automática"))
22
+			{
23
+				String type = canditate.split(":")[0].trim();
24
+				entity.setType(type);
25
+
26
+
27
+				if(type.equals("RELATORA") || type.equals("RELATOR"))		
28
+				{
29
+					entity.setType(TYPES.JUDGE);
30
+				}
31
+				if(type.contains("ADVOGAD") )
32
+				{
33
+					entity.setType(TYPES.LAWYER);
34
+				}
35
+
36
+				entity.setName(canditate.split(":")[1].trim());
37
+
38
+			}
39
+			else
40
+			{
41
+				entity.setName(canditate);
42
+				entity.setType(TYPES.OTHERINFO);
43
+
44
+
45
+			}
46
+		}catch(Exception e)
47
+		{
48
+			//			System.out.println(canditate);
49
+		}
50
+
51
+		return entity;
52
+
53
+	}
54
+
55
+
56
+
57
+	@Override
58
+	protected DOProcess extractProcess(String process) {
59
+
60
+		
61
+		DOProcess proc = new DOProcess();
62
+		
63
+		proc.setOrign("DJ_STJ");
64
+		
65
+		String vecProcesses[] = process.split("\n");
66
+		int index = 0;
67
+		String firstLine = vecProcesses[index];
68
+
69
+		/**Extract information from the first line**/
70
+		try{
71
+			if(firstLine.equals(""))
72
+			{
73
+				index++;
74
+				firstLine = vecProcesses[index];
75
+			}
76
+
77
+			if(!firstLine.contains("class='np'"))
78
+			{
79
+				index++;
80
+				firstLine = firstLine +vecProcesses[index];
81
+				
82
+			}
83
+			
84
+			if(!firstLine.contains("class='np'"))
85
+			{
86
+				return null;
87
+				
88
+			}
89
+			
90
+			
91
+
92
+			String processType = firstLine.toLowerCase().split("nº")[0].toLowerCase();
93
+			firstLine = firstLine.substring(processType.length());
94
+			ProcessTypes procType = new ProcessTypes(processType);
95
+			proc.setProcessType(procType);
96
+			
97
+			
98
+			
99
+			String processIndex = firstLine.split("<NP1><B class='np'>")[0].trim();
100
+			firstLine = firstLine.split("<NP1><B class='np'>")[1].trim();
101
+			proc.setProcessIndex(processIndex);
102
+
103
+			String state =  firstLine.split("\\(")[0].trim();
104
+			firstLine = firstLine.split("\\(")[1].trim();
105
+			proc.setState(state);
106
+
107
+			String processNumber =  firstLine.split("\\)")[0].trim();
108
+			firstLine = firstLine.split("\\)")[1].trim();
109
+			proc.setProcessNumber(processNumber);
110
+
111
+
112
+			if(!firstLine.trim().equals("</B></NP1>"))
113
+			{
114
+
115
+				firstLine = firstLine.split("</B></NP1>")[1].trim();
116
+				Entity entity= this.getEntity(firstLine);
117
+
118
+				switch (entity.getType()) {
119
+				case TYPES.JUDGE:
120
+					proc.addJudge(new Judge(entity.getName()));
121
+					break;
122
+				case TYPES.OTHERINFO:
123
+					proc.addOtherInfo(entity.getName());
124
+					break;
125
+				case TYPES.LAWYER:
126
+					proc.addLawyer(new Lawyer(entity.getName()));
127
+					break;
128
+
129
+				default:
130
+					proc.addEntity(entity);
131
+					break;
132
+				}
133
+
134
+
135
+			}
136
+
137
+
138
+
139
+
140
+		}catch(Exception e)
141
+		{
142
+			System.out.println("Error on this process");
143
+			System.out.println(vecProcesses[0]);
144
+			System.out.println(proc);
145
+			System.out.println();
146
+			return null;
147
+		}
148
+
149
+
150
+		
151
+		/***next lines*/
152
+		try{
153
+			index++;
154
+			
155
+			String line = vecProcesses[index];
156
+
157
+			while( index < vecProcesses.length-1 && !this.isVerdict(line)  )
158
+			{
159
+
160
+				Entity entity= this.getEntity(line);
161
+				switch (entity.getType()) {
162
+				case TYPES.JUDGE:
163
+					proc.addJudge(new Judge(entity.getName()));
164
+					break;
165
+				case TYPES.OTHERINFO:
166
+					proc.addOtherInfo(entity.getName());
167
+					break;
168
+				case TYPES.LAWYER:
169
+					proc.addLawyer(new Lawyer(entity.getName()));
170
+					break;
171
+
172
+
173
+				default:
174
+					proc.addEntity(entity);
175
+					break;
176
+				}
177
+
178
+				index++;
179
+				line = vecProcesses[index];
180
+			}
181
+
182
+			StringBuilder sb = new StringBuilder();
183
+
184
+			for(int i=index; i< vecProcesses.length; i++ )
185
+			{
186
+				sb.append(vecProcesses[i] +"\n");
187
+
188
+			}
189
+
190
+			proc.setVerdict(sb.toString());
191
+
192
+
193
+
194
+
195
+		}catch(Exception e)
196
+		{
197
+
198
+			e.printStackTrace();
199
+		}
200
+
201
+		return proc;
202
+
203
+	}
204
+
205
+
206
+
207
+	private boolean isVerdict(String line) {
208
+		line = line.trim().toLowerCase();
209
+
210
+		if(line.equals("despacho"))
211
+		{
212
+
213
+			return true;
214
+		}
215
+		if(line.equals("decisão"))
216
+		{
217
+
218
+			return true;
219
+		}
220
+		
221
+		if(line.contains("A Turma, por unanimidade"))
222
+		{
223
+			return true;
224
+		}
225
+
226
+		return false;
227
+	}
228
+
229
+}

+ 4 - 0
src/graph/graph.properties

@@ -0,0 +1,4 @@
1
+
2
+
3
+mainFolder = /home/ailton/Monografia/data
4
+

+ 53 - 0
src/graph/input/file/InputFactory.java

@@ -0,0 +1,53 @@
1
+package graph.input.file;
2
+
3
+import java.io.File;
4
+import java.util.ArrayList;
5
+import java.util.Arrays;
6
+import java.util.List;
7
+
8
+import graph.extractor.graph.builder.BuilderFactory;
9
+
10
+public abstract class InputFactory {
11
+	
12
+	protected InputFolder folder;
13
+	
14
+	
15
+	
16
+	public InputFactory(InputFolder folder)
17
+	{
18
+		this.folder = folder;
19
+		
20
+	}
21
+	
22
+	/**Date will be in day month year without separator*/
23
+	
24
+	public List<File> getFilesFromDate(File date)
25
+	{
26
+		List<File> DOs = new ArrayList<File>();
27
+		if(date.isDirectory())
28
+		{
29
+			DOs = Arrays.asList( date.listFiles());
30
+		}
31
+		return DOs;
32
+		
33
+	}
34
+	
35
+	
36
+	
37
+	public List<String> getAllProcess(File oneDayOfDO)
38
+	{
39
+		
40
+		List<File>  AllFilesOfthatDay = this.getFilesFromDate(oneDayOfDO);
41
+		List<String> allProcess  =  this.readProcess(AllFilesOfthatDay);
42
+		return allProcess;
43
+		
44
+	}
45
+	
46
+	
47
+	public abstract List<String> readProcess(List<File> filesOfProcess);
48
+	public abstract File getDOFolder();
49
+	public abstract BuilderFactory getBuilder();
50
+	
51
+	
52
+
53
+}

+ 47 - 0
src/graph/input/file/InputFolder.java

@@ -0,0 +1,47 @@
1
+package graph.input.file;
2
+
3
+import java.io.File;
4
+import java.util.Arrays;
5
+import java.util.List;
6
+import java.util.Properties;
7
+
8
+public class InputFolder {
9
+	
10
+	private String mainFolder;
11
+	private List<String> typesOfDO;
12
+	private File folder;
13
+
14
+	public InputFolder(Properties properties){
15
+		
16
+		this.mainFolder = properties.getProperty("mainFolder");
17
+		
18
+		this.setTypesOfDO();
19
+	}
20
+	
21
+	public List<String> readTypesOfDO()
22
+	{
23
+		this.folder= new File(mainFolder);
24
+		List<String> typesOfDO = Arrays.asList(this.folder.list());
25
+		return typesOfDO;
26
+		
27
+	}
28
+
29
+	public void setTypesOfDO() {
30
+		this.typesOfDO = this.readTypesOfDO();
31
+	}
32
+	
33
+	public List<String> getTypesOfDO()
34
+	{
35
+		return this.typesOfDO;
36
+	}
37
+	
38
+	public File getFolder()
39
+	{
40
+		return this.folder;
41
+	}
42
+	
43
+	
44
+	
45
+	
46
+	
47
+}

+ 105 - 0
src/graph/input/file/InputSTJ.java

@@ -0,0 +1,105 @@
1
+package graph.input.file;
2
+
3
+
4
+import java.io.BufferedReader;
5
+import java.io.File;
6
+import java.io.FileInputStream;
7
+import java.io.IOException;
8
+import java.io.InputStreamReader;
9
+import java.util.ArrayList;
10
+import java.util.List;
11
+
12
+import graph.extractor.graph.builder.BuilderFactory;
13
+import graph.extractor.graph.builder.STJBuilder;
14
+
15
+public class InputSTJ extends InputFactory{
16
+
17
+	public InputSTJ(InputFolder folders) {
18
+		super(folders);
19
+		// TODO Auto-generated constructor stub
20
+	}
21
+
22
+	@Override
23
+	public List<String> readProcess(List<File> filesOfProcess) {
24
+		// TODO Auto-generated method stub
25
+
26
+		int index = 1;
27
+		List <String> process = new ArrayList<String>();
28
+		boolean isProcess = false;
29
+		StringBuilder temporaryProcess = new StringBuilder();
30
+		filesOfProcess.sort(null);
31
+		for(File file: filesOfProcess )
32
+		{
33
+
34
+
35
+			try {
36
+				InputStreamReader stream = new InputStreamReader(new FileInputStream(file), "ISO-8859-1");
37
+				@SuppressWarnings("resource")
38
+				BufferedReader bf = new BufferedReader(stream);
39
+				String line= bf.readLine();
40
+
41
+				while(line != null){
42
+
43
+					if(isProcess)
44
+					{
45
+						temporaryProcess.append(line+"\n");
46
+
47
+					}
48
+
49
+					String marker = "("+index+")";
50
+					if( line.equals(marker))
51
+					{	
52
+						isProcess = true;
53
+						index++;
54
+						if(temporaryProcess.length() > 10)
55
+						{
56
+							temporaryProcess.setLength(temporaryProcess.length()-marker.length()-2);
57
+							process.add(temporaryProcess.toString());
58
+							temporaryProcess.setLength(0);
59
+
60
+						}
61
+					}
62
+					line = bf.readLine();
63
+					if(line != null && line.equals(""))
64
+					{
65
+						line = bf.readLine();
66
+					}
67
+
68
+
69
+				}
70
+
71
+
72
+			} catch ( IOException e) {
73
+				// TODO Auto-generated catch block
74
+				e.printStackTrace();
75
+			}
76
+
77
+
78
+		}
79
+
80
+		return process;
81
+	}
82
+
83
+
84
+	@Override
85
+	public File getDOFolder() {
86
+		// TODO Auto-generated method stub
87
+
88
+		File folder = new File(this.folder.getFolder() +"/stj");
89
+		return folder;
90
+
91
+
92
+
93
+	}
94
+
95
+	@Override
96
+	public BuilderFactory getBuilder() {
97
+		// TODO Auto-generated method stub
98
+		return new STJBuilder();
99
+	}
100
+
101
+
102
+
103
+
104
+
105
+}

+ 20 - 0
src/graph/output/OutPutFactory.java

@@ -0,0 +1,20 @@
1
+package graph.output;
2
+
3
+import java.util.List;
4
+
5
+import entity.DOProcess;
6
+
7
+
8
+public abstract class OutPutFactory {
9
+	
10
+	
11
+	
12
+	public abstract void insertToOutPut(DOProcess process );
13
+	
14
+	
15
+	public abstract void buildOutput(List<DOProcess> allProcess);
16
+	
17
+	public abstract void print();
18
+	
19
+
20
+}

+ 90 - 0
src/graph/output/database/DatabaseOutput.java

@@ -0,0 +1,90 @@
1
+package graph.output.database;
2
+
3
+import java.util.List;
4
+import java.util.Random;
5
+
6
+import dao.DAOGeneralProcess;
7
+import entity.DOProcess;
8
+import graph.output.OutPutFactory;
9
+
10
+public class DatabaseOutput extends OutPutFactory {
11
+
12
+	
13
+	DAOGeneralProcess dao = new DAOGeneralProcess();
14
+	public int runned;
15
+	
16
+	public DatabaseOutput() {
17
+		// TODO Auto-generated constructor stub
18
+		
19
+		
20
+		
21
+	}
22
+	
23
+	
24
+	
25
+	@Override
26
+	public void insertToOutPut(DOProcess process) {
27
+		// TODO Auto-generated method stu
28
+		int run = dao.insertDOProcess(process);
29
+		runned = runned + run;
30
+		
31
+		
32
+	}
33
+
34
+	@Override
35
+	public void buildOutput(List<DOProcess> allProcess) {
36
+		
37
+		long processSize = allProcess.size();
38
+		
39
+		int counter  = 0;
40
+		this.runned = 0;
41
+		
42
+		
43
+		while(allProcess.size() > 0)
44
+		{
45
+			try{
46
+				Random rand = new Random();
47
+				int randNumber = Math.abs(rand.nextInt(allProcess.size()));
48
+				DOProcess process= allProcess.get(randNumber);
49
+				this.insertToOutPut(process);
50
+				counter++;
51
+				try{
52
+					if(counter% (processSize/100) ==0 || counter >= processSize -10)
53
+						System.out.println("Concluido "+ counter+ " de "+ processSize);
54
+					
55
+					if((runned) % (processSize/100) ==1) 
56
+						System.out.println("Atualizou " + runned );
57
+					
58
+				}catch(Exception e)
59
+				{
60
+					
61
+				}
62
+				
63
+				allProcess.remove(process);
64
+				
65
+			}catch(Exception e)
66
+			{
67
+				e.printStackTrace();
68
+			}
69
+			
70
+			
71
+			
72
+
73
+		}
74
+		System.out.println("Foram atualizados " +runned+". Skip: " + (processSize-runned));
75
+
76
+		System.gc();
77
+		
78
+		
79
+		
80
+	}
81
+
82
+	
83
+	
84
+	@Override
85
+	public void print() {
86
+		// TODO Auto-generated method stub
87
+		
88
+	}
89
+
90
+}

+ 117 - 0
src/graph/output/graph/JGraphOutput.java

@@ -0,0 +1,117 @@
1
+package graph.output.graph;
2
+
3
+
4
+
5
+import java.awt.*;
6
+
7
+
8
+import javax.swing.*;
9
+
10
+
11
+import org.jgraph.JGraph;
12
+import org.jgrapht.*;
13
+import org.jgrapht.ext.*;
14
+
15
+import org.jgrapht.graph.*;
16
+
17
+import entity.DOProcess;
18
+import entity.Entity;
19
+
20
+/**
21
+ * A demo applet that shows how to use JGraph to visualize JGraphT graphs.
22
+ *
23
+ * @author Barak Naveh
24
+ * @since Aug 3, 2003
25
+ */
26
+public class JGraphOutput    extends JApplet
27
+{
28
+    //~ Static fields/initializers ---------------------------------------------
29
+
30
+    private static final long serialVersionUID = 3256444702936019250L;
31
+    private static final Color DEFAULT_BG_COLOR = Color.decode("#FAFBFF");
32
+    private static final Dimension DEFAULT_SIZE = new Dimension(800, 800);
33
+
34
+    //~ Instance fields --------------------------------------------------------
35
+
36
+    //
37
+    private JGraphModelAdapter<Entity, DOProcess> jgAdapter;
38
+
39
+    //~ Methods ----------------------------------------------------------------
40
+
41
+    /**
42
+     * An alternative starting point for this demo, to also allow running this
43
+     * applet as an application.
44
+     *
45
+     * @param args ignored.
46
+     */
47
+    public JGraphOutput(UndirectedGraph<Entity, DOProcess> graph)
48
+    {
49
+    	
50
+        this.init(graph);
51
+
52
+        JFrame frame = new JFrame();
53
+        frame.getContentPane().add(this);
54
+        frame.setTitle("JGraphT Adapter to JGraph Demo");
55
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
56
+        frame.pack();
57
+        frame.setVisible(true);
58
+    }
59
+
60
+    /**
61
+     * {@inheritDoc}
62
+     */
63
+    public void init(UndirectedGraph<Entity, DOProcess> graph)
64
+    { 
65
+        // create a JGraphT graphq
66
+        ListenableGraph<Entity, DOProcess> g =new ListenableUndirectedGraph<Entity, DOProcess>(graph);
67
+
68
+        // create a visualization using JGraph, via an adapter
69
+        jgAdapter =  new JGraphModelAdapter<Entity,DOProcess>(g);
70
+        
71
+        JGraph jgraph = new JGraph(jgAdapter);
72
+
73
+        adjustDisplaySettings(jgraph);
74
+        getContentPane().add(jgraph);
75
+        resize(DEFAULT_SIZE);
76
+       
77
+     
78
+    }
79
+
80
+    private void adjustDisplaySettings(JGraph jg)
81
+    {
82
+        jg.setPreferredSize(DEFAULT_SIZE);
83
+
84
+        Color c = DEFAULT_BG_COLOR;
85
+        String colorStr = null;
86
+
87
+        try {
88
+            colorStr = getParameter("bgcolor");
89
+        } catch (Exception e) {
90
+        }
91
+
92
+        if (colorStr != null) {
93
+            c = Color.decode(colorStr);
94
+        }
95
+
96
+        jg.setBackground(c);
97
+    }
98
+
99
+//    @SuppressWarnings("unchecked") // FIXME hb 28-nov-05: See FIXME below
100
+//    private void positionVertexAt(Object vertex, int x, int y)
101
+//    {
102
+//        DefaultGraphCell cell = jgAdapter.getVertexCell(vertex);
103
+//        AttributeMap attr = cell.getAttributes();
104
+//        Rectangle2D bounds = GraphConstants.getBounds(attr);
105
+//
106
+//        Rectangle2D newBounds = new Rectangle2D.Double(x,y,bounds.getWidth(),bounds.getHeight());
107
+//
108
+//        GraphConstants.setBounds(attr, newBounds);
109
+//
110
+//        // TODO: Clean up generics once JGraph goes generic
111
+//        org.jgraph.graph.AttributeMap cellAttr = new AttributeMap();
112
+//        cellAttr.put(cell, attr);
113
+//        jgAdapter.edit(cellAttr, null, null, null);
114
+//    }
115
+
116
+
117
+}

+ 156 - 0
src/graph/output/screen/ScreenOutput.java

@@ -0,0 +1,156 @@
1
+package graph.output.screen;
2
+
3
+
4
+import java.util.List;
5
+
6
+import org.graphstream.graph.Graph;
7
+import org.graphstream.graph.Node;
8
+import org.graphstream.graph.implementations.SingleGraph;
9
+
10
+import entity.DOProcess;
11
+import entity.Judge;
12
+import entity.Lawyer;
13
+import entity.TYPES;
14
+import graph.output.OutPutFactory;
15
+
16
+public class ScreenOutput extends OutPutFactory{
17
+
18
+
19
+	protected String styleSheet =
20
+			"node {" +
21
+					"	fill-color: black;" +
22
+					"}" +
23
+					"node.marked {" +
24
+					"	fill-color: red;" +
25
+					"}";
26
+
27
+	protected Graph graph;
28
+
29
+	public ScreenOutput() {
30
+		graph = new SingleGraph("Processos X Juizes");
31
+
32
+		graph.addAttribute("ui.stylesheet", styleSheet);
33
+		graph.setAutoCreate(true);
34
+		graph.setStrict(false);
35
+		graph.display();
36
+
37
+
38
+	}
39
+
40
+
41
+
42
+	@Override
43
+	public void insertToOutPut(DOProcess process) {
44
+
45
+
46
+		if(process.getJudges().size() > 0)
47
+		{
48
+
49
+			Judge judge = process.getJudge();
50
+			if(!judge.getName().equals(TYPES.NAMEDEFAULT))
51
+			{
52
+				Node judgeNode;
53
+
54
+				if( graph.getNode(judge.getName()) == null )
55
+				{
56
+					judgeNode = graph.addNode(judge.getName());
57
+					judgeNode.setAttribute("ui.class", "marked");
58
+					judgeNode.addAttribute("ui.label", judge.getName());
59
+
60
+				}
61
+				else
62
+				{
63
+					judgeNode = graph.getNode(judge.getName());
64
+				}
65
+
66
+				Integer ID = new Integer(0);
67
+				for(Lawyer laywer: process.getLawyer())
68
+				{
69
+
70
+
71
+					if(!laywer.getName().equals(TYPES.NAMEDEFAULT))
72
+					{
73
+
74
+						Node lawyerNode;
75
+						if( graph.getNode(laywer.getName()) == null )
76
+						{
77
+							lawyerNode= graph.addNode(laywer.getName());
78
+							lawyerNode.addAttribute("ui.label", laywer.getName());
79
+
80
+						}
81
+						else
82
+						{
83
+							lawyerNode= graph.getNode(laywer.getName());
84
+
85
+						}
86
+
87
+						graph.addEdge(process.getProcessNumber()+ID.toString(), judgeNode, lawyerNode);
88
+						ID++;
89
+
90
+					}
91
+
92
+
93
+
94
+				}
95
+			}
96
+		}
97
+
98
+
99
+
100
+
101
+	}
102
+	
103
+	
104
+	
105
+
106
+	
107
+	
108
+	
109
+
110
+
111
+
112
+
113
+	@Override
114
+	public void buildOutput(List<DOProcess> allProcess) {
115
+
116
+		for( DOProcess process : allProcess )
117
+		{
118
+			try {
119
+				if(process.getVerdict().length() > 100)	
120
+				{
121
+					//System.out.println(process.getVerdict());
122
+					this.insertToOutPut(process);
123
+					Thread.sleep(300);
124
+					System.out.println(process.getVerdict());
125
+				}
126
+				else
127
+				{
128
+					//System.out.println(process.getVerdict());
129
+				}
130
+
131
+			} catch (InterruptedException e) {
132
+				// TODO Auto-generated catch block
133
+				e.printStackTrace();
134
+			}
135
+
136
+
137
+		}
138
+
139
+
140
+	}
141
+
142
+
143
+
144
+
145
+
146
+
147
+
148
+	@Override
149
+	public void print() {
150
+		// TODO Auto-generated method stub
151
+
152
+	}
153
+
154
+
155
+
156
+}

+ 33 - 0
src/graph/properties/ExtractorProperties.java

@@ -0,0 +1,33 @@
1
+package graph.properties;
2
+
3
+import java.io.FileReader;
4
+import java.io.IOException;
5
+import java.util.Properties;
6
+
7
+public class ExtractorProperties extends Properties{
8
+	
9
+	 
10
+	
11
+	/**
12
+	 * 
13
+	 */
14
+	private static final long serialVersionUID = 1L;
15
+
16
+	public ExtractorProperties()
17
+	{
18
+		
19
+			FileReader propertiesFile;
20
+			try {
21
+				propertiesFile = new FileReader("graph.properties");
22
+				this.load(propertiesFile);
23
+			} catch (IOException e) {
24
+				// TODO Auto-generated catch block
25
+				System.out.println("File graph.properties not found set on hardcode");
26
+				this.setProperty("mainFolder","/home/ailton/Monografia/data");
27
+				
28
+			}
29
+		
30
+	}
31
+	
32
+
33
+}