1 | |
package br.mia.test.openoffice; |
2 | |
|
3 | |
import java.io.File; |
4 | |
import java.io.FileInputStream; |
5 | |
import java.io.IOException; |
6 | |
import java.sql.SQLException; |
7 | |
import java.util.ArrayList; |
8 | |
|
9 | |
import org.apache.poi.hwpf.HWPFDocument; |
10 | |
import org.apache.poi.hwpf.extractor.WordExtractor; |
11 | |
import org.openoffice.odf.doc.OdfDocument; |
12 | |
import org.openoffice.odf.doc.OdfFileDom; |
13 | |
import org.w3c.dom.Node; |
14 | |
import org.w3c.dom.NodeList; |
15 | |
|
16 | |
import br.mia.test.controler.ControladorErro; |
17 | |
import br.mia.test.model.CasoUso; |
18 | |
import br.mia.test.model.Fluxo; |
19 | |
import br.mia.test.model.Projeto; |
20 | |
import br.mia.test.model.Step; |
21 | |
import br.mia.test.model.dao.DAOFlow; |
22 | |
import br.mia.test.model.dao.DAOStep; |
23 | |
import br.mia.test.model.dao.DAOUseCase; |
24 | |
import br.mia.test.model.exception.CasoUsoJaInseridoException; |
25 | |
import br.mia.test.model.exception.DadoNuloException; |
26 | |
import br.mia.test.model.exception.FluxoNuloException; |
27 | |
import br.mia.test.model.exception.NomeTamanhoZeroException; |
28 | 0 | import br.mia.test.model.exception.PassoNuloException; |
29 | |
|
30 | 0 | public class OpenOffice |
31 | |
{ |
32 | |
|
33 | |
public ArrayList<CasoUso> insertUseCase(File[] file, Projeto projeto, |
34 | |
StringBuffer log, String tipoArquivo) |
35 | |
throws InstantiationException, IllegalAccessException, |
36 | |
ClassNotFoundException, SQLException, IOException, |
37 | 0 | CasoUsoJaInseridoException, NomeTamanhoZeroException, |
38 | |
PassoNuloException, DadoNuloException, FluxoNuloException { |
39 | 0 | |
40 | 0 | ArrayList<CasoUso> useCases = new ArrayList<CasoUso>(); |
41 | 0 | |
42 | 0 | for (int i = 0; i <= file.length - 1; i++) { |
43 | |
|
44 | 0 | CasoUso useCase = new CasoUso(); |
45 | 0 | useCase.setName(file[i].getName()); |
46 | 0 | |
47 | 0 | String fileName = file[i].getCanonicalPath(); |
48 | 0 | |
49 | 0 | OpenOffice openOffice = new OpenOffice(); |
50 | |
|
51 | 0 | DAOUseCase dao = new DAOUseCase(); |
52 | |
|
53 | 0 | dao.update(useCase, projeto); |
54 | |
|
55 | 0 | ArrayList<Fluxo> array = openOffice.getFlows(fileName, log, |
56 | 0 | tipoArquivo, useCase); |
57 | |
|
58 | 0 | for (Object object : array) { |
59 | 0 | |
60 | 0 | Fluxo normalFlow = (Fluxo) object; |
61 | 0 | |
62 | 0 | DAOFlow daoFlow = new DAOFlow(); |
63 | 0 | |
64 | 0 | if (normalFlow.getName().length()==0){ |
65 | 0 | normalFlow.setName("Nome n�o encontrado"); |
66 | 0 | } |
67 | |
|
68 | 0 | daoFlow.insert(normalFlow, useCase); |
69 | |
|
70 | 0 | useCase.flows.add(normalFlow); |
71 | |
|
72 | 0 | } |
73 | 0 | |
74 | 0 | useCases.add(useCase); |
75 | 0 | |
76 | |
} |
77 | 0 | return useCases; |
78 | |
|
79 | 0 | } |
80 | |
|
81 | 0 | public StringBuffer getTextDoc(String fileName) throws IOException { |
82 | 0 | |
83 | 0 | File file = new File(fileName); |
84 | 0 | FileInputStream fis = new FileInputStream(file.getAbsolutePath()); |
85 | |
|
86 | 0 | HWPFDocument doc = new HWPFDocument(fis); |
87 | 0 | |
88 | 0 | WordExtractor word = new WordExtractor(doc); |
89 | |
|
90 | 0 | String[] docArray = word.getParagraphText(); |
91 | |
|
92 | 0 | StringBuffer stringBuffer = new StringBuffer(); |
93 | 0 | for (String string : docArray) { |
94 | 0 | |
95 | 0 | stringBuffer.append(string); |
96 | 0 | } |
97 | 0 | |
98 | 0 | return stringBuffer; |
99 | 0 | |
100 | |
} |
101 | 0 | |
102 | 0 | public StringBuffer getText(String fileName) throws Exception { |
103 | |
|
104 | 0 | OdfDocument odfDoc = OdfDocument.loadDocument(fileName); |
105 | 0 | OdfFileDom dom = odfDoc.getContentDom(); |
106 | 0 | NodeList nodeLst = dom.getElementsByTagName("text:p"); |
107 | 0 | StringBuffer buffer = new StringBuffer(); |
108 | 0 | for (int s = 0; s < nodeLst.getLength(); s++) { |
109 | 0 | |
110 | 0 | Node fstNode = nodeLst.item(s); |
111 | |
|
112 | 0 | NodeList fstNm = fstNode.getChildNodes(); |
113 | 0 | int tamanho = fstNm.getLength(); |
114 | 0 | |
115 | 0 | for (int i = 0; i <= tamanho - 1; i++) { |
116 | 0 | if (fstNm.item(i) != null) { |
117 | 0 | |
118 | 0 | String valor = ((Node) fstNm.item(i)).getNodeValue(); |
119 | 0 | if ((valor != null)) { |
120 | 0 | buffer.append(valor); |
121 | |
|
122 | |
} |
123 | |
|
124 | 0 | if ((fstNm.item(i)).hasChildNodes()) { |
125 | 0 | NodeList fstNm1 = fstNm.item(i).getChildNodes(); |
126 | 0 | for (int j = 0; j <= fstNm1.getLength() - 1; j++) { |
127 | 0 | String valor1 = ((Node) fstNm1.item(j)) |
128 | 0 | .getNodeValue(); |
129 | |
|
130 | 0 | if ((valor1 != null)) { |
131 | 0 | buffer.append(valor1); |
132 | |
} |
133 | |
} |
134 | |
} |
135 | |
|
136 | 0 | } |
137 | |
|
138 | 0 | } |
139 | |
} |
140 | 0 | |
141 | 0 | return buffer; |
142 | |
} |
143 | |
|
144 | 0 | public int getFluxoPrincipalMetodo1(String casoUso, int contadorFP, |
145 | 0 | Fluxo flow) { |
146 | 0 | |
147 | 0 | String numeroPassoProcurado = "P" + contadorFP + "."; |
148 | 0 | int index = casoUso.indexOf(numeroPassoProcurado); |
149 | 0 | |
150 | 0 | while (contadorFP > 0) { |
151 | 0 | |
152 | 0 | if (index <= 0) { |
153 | 0 | return index; |
154 | |
} |
155 | 0 | |
156 | 0 | int indexFilho = casoUso.indexOf("P" + contadorFP + ".1"); |
157 | 0 | int contadorFilho = 2; |
158 | 0 | if (indexFilho > 0) { |
159 | 0 | |
160 | 0 | Step step = new Step(); |
161 | 0 | String descricao = casoUso.substring(index, indexFilho); |
162 | 0 | if (descricao.length() > 500) { |
163 | 0 | descricao = descricao.substring(0, 499); |
164 | 0 | } |
165 | 0 | step.setDescricao(descricao); |
166 | 0 | |
167 | 0 | flow.getSteps().add(step); |
168 | 0 | |
169 | 0 | while (contadorFilho > 0) { |
170 | |
|
171 | 0 | int indexFilhoProximo = casoUso.indexOf("P" + contadorFP |
172 | 0 | + "." + contadorFilho); |
173 | 0 | if (((indexFilhoProximo > 0) && (indexFilho > 0)) |
174 | 0 | && (indexFilhoProximo > indexFilho)) { |
175 | 0 | if ((indexFilho <= casoUso.length()) |
176 | 0 | && (indexFilhoProximo <= casoUso.length())) { |
177 | 0 | step = new Step(); |
178 | 0 | descricao = casoUso.substring(indexFilho, |
179 | 0 | indexFilhoProximo); |
180 | 0 | if (descricao.length() > 500) { |
181 | 0 | descricao = descricao.substring(0, 499); |
182 | 0 | } |
183 | 0 | step.setDescricao(descricao); |
184 | 0 | flow.getSteps().add(step); |
185 | 0 | contadorFilho++; |
186 | 0 | } |
187 | 0 | } else { |
188 | 0 | int contadorFPProximo = contadorFP + 1; |
189 | 0 | int indexProximo = casoUso.indexOf("P" |
190 | 0 | + contadorFPProximo + "."); |
191 | 0 | if (indexProximo > 0) { |
192 | 0 | step = new Step(); |
193 | 0 | descricao = casoUso.substring(indexFilho, |
194 | 0 | indexProximo); |
195 | 0 | if (descricao.length() > 500) { |
196 | 0 | descricao = descricao.substring(0, 499); |
197 | 0 | } |
198 | 0 | step.setDescricao(descricao); |
199 | 0 | flow.getSteps().add(step); |
200 | 0 | contadorFilho = -2; |
201 | 0 | contadorFP++; |
202 | 0 | |
203 | 0 | } else { |
204 | 0 | |
205 | 0 | indexFilhoProximo = casoUso |
206 | 0 | .indexOf("Fluxos Alternativos"); |
207 | 0 | step = new Step(); |
208 | 0 | if (descricao.length() > 500) { |
209 | 0 | descricao = descricao.substring(0, 499); |
210 | |
} |
211 | 0 | descricao = casoUso.substring(indexFilho, |
212 | 0 | indexFilhoProximo); |
213 | 0 | step.setDescricao(descricao); |
214 | 0 | flow.getSteps().add(step); |
215 | 0 | contadorFilho = -2; |
216 | 0 | contadorFP = -2; |
217 | 0 | } |
218 | 0 | |
219 | 0 | } |
220 | 0 | indexFilho = indexFilhoProximo; |
221 | |
} |
222 | 0 | |
223 | 0 | } else { |
224 | 0 | int contadorFPProximo = contadorFP + 1; |
225 | 0 | int indexProximo = casoUso.indexOf("P" + contadorFPProximo |
226 | 0 | + "."); |
227 | |
|
228 | 0 | if (indexProximo > 0) { |
229 | 0 | Step step = new Step(); |
230 | 0 | String descricao = casoUso.substring(index, indexProximo); |
231 | 0 | if (descricao.length() > 500) { |
232 | 0 | descricao = descricao.substring(0, 499); |
233 | 0 | } |
234 | 0 | step.setDescricao(descricao); |
235 | 0 | flow.getSteps().add(step); |
236 | 0 | contadorFP++; |
237 | 0 | index = indexProximo; |
238 | |
|
239 | |
} else { |
240 | |
|
241 | 0 | indexProximo = casoUso.indexOf("Fluxos Alternativos"); |
242 | 0 | Step step = new Step(); |
243 | 0 | String descricao = casoUso.substring(index, indexProximo); |
244 | 0 | if (descricao.length() > 500) { |
245 | 0 | descricao = descricao.substring(0, 499); |
246 | |
} |
247 | 0 | step.setDescricao(descricao); |
248 | 0 | flow.getSteps().add(step); |
249 | 0 | contadorFP = -2; |
250 | |
} |
251 | 0 | } |
252 | 0 | } |
253 | 0 | |
254 | 0 | return index; |
255 | 0 | |
256 | |
} |
257 | 0 | |
258 | |
public boolean getFluxoAlternativoMetodo1(ArrayList<Fluxo> flows, |
259 | 0 | String casoUso, int contadorFP, int index, boolean continuar, |
260 | 0 | StringBuffer log, CasoUso useCase) throws SQLException, |
261 | 0 | InstantiationException, IllegalAccessException, |
262 | 0 | ClassNotFoundException, IOException, PassoNuloException, |
263 | |
NomeTamanhoZeroException, FluxoNuloException { |
264 | 0 | DAOStep daoStep = new DAOStep(); |
265 | 0 | DAOFlow daoFlow = new DAOFlow(); |
266 | 0 | for (int alternativo = 1; alternativo <= 15; alternativo++) { |
267 | 0 | |
268 | 0 | Fluxo flow1 = new Fluxo(); |
269 | 0 | flow1.setName("Fluxo Alternativo " + alternativo); |
270 | |
|
271 | 0 | daoFlow.insert(flow1, useCase); |
272 | 0 | contadorFP = 1; |
273 | 0 | |
274 | 0 | int indexInicial = casoUso.indexOf("A" + alternativo + "."); |
275 | 0 | |
276 | 0 | int indexInicial1 = casoUso.indexOf("A" + alternativo + ".1"); |
277 | 0 | |
278 | 0 | if ((indexInicial >= 0) && (indexInicial1 >= 0)) { |
279 | 0 | String nomeFluxo = casoUso.substring(indexInicial, |
280 | 0 | indexInicial1); |
281 | 0 | flow1.setName(nomeFluxo); |
282 | 0 | |
283 | 0 | while (contadorFP > 0) { |
284 | 0 | |
285 | 0 | index = casoUso.indexOf("A" + alternativo + "." |
286 | 0 | + contadorFP); |
287 | |
|
288 | 0 | if (index > 0) { |
289 | 0 | |
290 | 0 | int contadorFPProximo = contadorFP + 1; |
291 | 0 | int indexProximo = casoUso.indexOf("A" + alternativo |
292 | 0 | + "." + contadorFPProximo); |
293 | 0 | |
294 | 0 | if (indexProximo > 0) { |
295 | 0 | Step step = new Step(); |
296 | 0 | String descricao = casoUso.substring(index, |
297 | 0 | indexProximo); |
298 | 0 | if (descricao.length() > 500) { |
299 | 0 | descricao = descricao.substring(0, 499); |
300 | 0 | } |
301 | 0 | step.setDescricao(descricao); |
302 | 0 | daoStep.insert(step, flow1); |
303 | 0 | flow1.getSteps().add(step); |
304 | 0 | contadorFP++; |
305 | 0 | |
306 | 0 | } else { |
307 | |
|
308 | 0 | int alternativoProximo = alternativo + 1; |
309 | 0 | indexProximo = casoUso.indexOf("A" |
310 | 0 | + alternativoProximo + ".1"); |
311 | |
|
312 | 0 | if (indexProximo > 0) { |
313 | 0 | Step step = new Step(); |
314 | 0 | if (indexProximo >= index) { |
315 | 0 | String descricao = casoUso.substring(index, |
316 | 0 | indexProximo); |
317 | 0 | if (descricao.length() > 500) { |
318 | 0 | descricao = descricao.substring(0, 499); |
319 | 0 | } |
320 | 0 | step.setDescricao(descricao); |
321 | 0 | daoStep.insert(step, flow1); |
322 | 0 | flow1.getSteps().add(step); |
323 | 0 | contadorFP = -2; |
324 | 0 | } else { |
325 | 0 | step.setDescricao("Passo Inv�lido"); |
326 | 0 | daoStep.insert(step, flow1); |
327 | 0 | flow1.getSteps().add(step); |
328 | 0 | contadorFP = -2; |
329 | 0 | |
330 | |
} |
331 | |
|
332 | |
} else { |
333 | |
|
334 | 0 | indexProximo = casoUso |
335 | 0 | .indexOf("Fluxos de Exce��o"); |
336 | 0 | Step step = new Step(); |
337 | 0 | if (indexProximo >= index) { |
338 | 0 | |
339 | 0 | String descricao = casoUso.substring(index, |
340 | 0 | indexProximo); |
341 | 0 | if (descricao.length() > 500) { |
342 | 0 | descricao = descricao.substring(0, 499); |
343 | |
} |
344 | 0 | step.setDescricao(descricao); |
345 | 0 | daoStep.insert(step, flow1); |
346 | 0 | flow1.getSteps().add(step); |
347 | 0 | contadorFP = -2; |
348 | 0 | continuar = false; |
349 | 0 | } else { |
350 | 0 | step.setDescricao("Passo Inv�lido"); |
351 | 0 | daoStep.insert(step, flow1); |
352 | 0 | flow1.getSteps().add(step); |
353 | 0 | contadorFP = -2; |
354 | 0 | } |
355 | 0 | |
356 | 0 | } |
357 | 0 | } |
358 | |
|
359 | 0 | } else { |
360 | 0 | contadorFP = -1; |
361 | 0 | continuar = false; |
362 | 0 | break; |
363 | |
|
364 | 0 | } |
365 | |
|
366 | |
} |
367 | |
|
368 | 0 | log.append(flow1.getSteps()); |
369 | 0 | flows.add(flow1); |
370 | 0 | if (!(continuar)) |
371 | 0 | break; |
372 | |
} else { |
373 | 0 | int proximoAlternativo = alternativo + 1; |
374 | 0 | indexInicial1 = casoUso.indexOf("A" + proximoAlternativo + "."); |
375 | |
|
376 | 0 | if ((indexInicial >= 0) && (indexInicial1 >= 0)) { |
377 | 0 | Step step = new Step(); |
378 | 0 | String descricao = casoUso.substring(indexInicial, |
379 | 0 | indexInicial1); |
380 | 0 | if (descricao.length() > 500) { |
381 | 0 | descricao = descricao.substring(0, 499); |
382 | 0 | } |
383 | 0 | step.setDescricao(descricao); |
384 | 0 | daoStep.insert(step, flow1); |
385 | 0 | flow1.getSteps().add(step); |
386 | 0 | flows.add(flow1); |
387 | 0 | contadorFP = -2; |
388 | 0 | } else { |
389 | 0 | return false; |
390 | 0 | } |
391 | 0 | } |
392 | 0 | } |
393 | 0 | return true; |
394 | 0 | } |
395 | |
|
396 | |
public ArrayList<Fluxo> getFlows(String fileName, StringBuffer log, |
397 | |
String tipoArquivo, CasoUso useCase) { |
398 | 0 | |
399 | 0 | ArrayList<Fluxo> flows = new ArrayList<Fluxo>(); |
400 | 0 | DAOFlow dao = new DAOFlow(); |
401 | 0 | DAOStep daoStep = new DAOStep(); |
402 | |
|
403 | 0 | try { |
404 | 0 | |
405 | 0 | String casoUso = ""; |
406 | 0 | if (tipoArquivo.equals("odt")) { |
407 | 0 | casoUso = getText(fileName).toString(); |
408 | 0 | } |
409 | 0 | if (tipoArquivo.equals("doc")) { |
410 | 0 | casoUso = getTextDoc(fileName).toString(); |
411 | 0 | } |
412 | 0 | |
413 | 0 | int contadorFP = 1; |
414 | 0 | Fluxo flow = new Fluxo(); |
415 | 0 | flow.setName("Fluxo Principal"); |
416 | 0 | |
417 | 0 | flow.setCasoUso(useCase); |
418 | |
|
419 | 0 | dao.insert(flow, useCase); |
420 | |
|
421 | 0 | flows.add(flow); |
422 | |
|
423 | 0 | int index = this |
424 | 0 | .getFluxoPrincipalMetodo1(casoUso, contadorFP, flow); |
425 | 0 | if (index <= 0) { |
426 | 0 | index = this |
427 | 0 | .getFluxoPrincipalMetodo2(casoUso, contadorFP, flow); |
428 | 0 | |
429 | 0 | } |
430 | 0 | |
431 | 0 | boolean continuar = true; |
432 | 0 | |
433 | 0 | contadorFP = 1; |
434 | |
|
435 | 0 | boolean alternativos = this.getFluxoAlternativoMetodo1(flows, |
436 | 0 | casoUso, 1, index, continuar, log, useCase); |
437 | 0 | |
438 | 0 | if (!(alternativos)) { |
439 | 0 | alternativos = this.getFluxoAlternativoMetodo2(flows, casoUso, |
440 | 0 | 1, index, continuar,useCase); |
441 | 0 | } |
442 | 0 | if (!(alternativos)) { |
443 | 0 | alternativos = this.getFluxoAlternativoMetodo3(flows, casoUso, |
444 | 0 | 1, index, continuar,useCase); |
445 | |
} |
446 | |
|
447 | 0 | while (contadorFP > 0) { |
448 | 0 | Fluxo flow2 = new Fluxo(); |
449 | 0 | flow2.setName("Fluxo Exce��o " + contadorFP); |
450 | |
|
451 | 0 | index = casoUso.indexOf("E" + contadorFP + "."); |
452 | 0 | |
453 | 0 | if (index > 0) { |
454 | 0 | |
455 | 0 | int alternativoProximo = contadorFP + 1; |
456 | 0 | int indexProximo = casoUso.indexOf("E" + alternativoProximo |
457 | 0 | + "."); |
458 | 0 | |
459 | 0 | if (indexProximo > 0) { |
460 | 0 | Step step = new Step(); |
461 | 0 | step.setFluxo(flow2); |
462 | 0 | if (indexProximo >= index) { |
463 | 0 | String descricao = casoUso.substring(index, |
464 | 0 | indexProximo); |
465 | 0 | if (descricao.length() > 500) { |
466 | 0 | descricao = descricao.substring(0, 499); |
467 | |
} |
468 | 0 | step.setDescricao(descricao); |
469 | 0 | daoStep.insert(step, flow2); |
470 | 0 | flow2.getSteps().add(step); |
471 | 0 | contadorFP++; |
472 | 0 | } else { |
473 | 0 | step.setDescricao("Passo Inv�lido"); |
474 | 0 | daoStep.insert(step, flow2); |
475 | 0 | flow2.getSteps().add(step); |
476 | 0 | contadorFP++; |
477 | |
|
478 | 0 | } |
479 | 0 | |
480 | |
} else { |
481 | |
|
482 | 0 | indexProximo = casoUso.indexOf("P�s-condi��es"); |
483 | 0 | Step step = new Step(); |
484 | 0 | step.setFluxo(flow2); |
485 | 0 | if (indexProximo >= index) { |
486 | |
|
487 | 0 | String descricao = casoUso.substring(index, |
488 | 0 | indexProximo); |
489 | |
|
490 | 0 | if (descricao.length() > 500) { |
491 | 0 | descricao = descricao.substring(0, 499); |
492 | 0 | } |
493 | 0 | step.setDescricao(descricao); |
494 | 0 | daoStep.insert(step, flow2); |
495 | 0 | flow2.getSteps().add(step); |
496 | 0 | contadorFP = -2; |
497 | 0 | continuar = false; |
498 | 0 | } else { |
499 | 0 | step.setDescricao("Passo Invalido"); |
500 | 0 | daoStep.insert(step, flow2); |
501 | 0 | flow2.getSteps().add(step); |
502 | 0 | contadorFP = -2; |
503 | 0 | continuar = false; |
504 | 0 | } |
505 | 0 | |
506 | |
} |
507 | 0 | } else { |
508 | 0 | continuar = false; |
509 | 0 | contadorFP = -2; |
510 | 0 | break; |
511 | 0 | } |
512 | 0 | flows.add(flow2); |
513 | |
} |
514 | 0 | |
515 | |
|
516 | 0 | } catch (Exception e) { |
517 | 0 | ControladorErro.trata(e, this); |
518 | |
} |
519 | 0 | |
520 | 0 | return flows; |
521 | |
} |
522 | |
|
523 | |
public int getFluxoPrincipalMetodo2(String casoUso, int contadorFP, |
524 | |
Fluxo flow) throws SQLException, InstantiationException, |
525 | |
IllegalAccessException, ClassNotFoundException, IOException, |
526 | 0 | PassoNuloException, NomeTamanhoZeroException { |
527 | 0 | DAOStep daoStep = new DAOStep(); |
528 | |
|
529 | 0 | int index = casoUso.indexOf("Fluxo Principal"); |
530 | |
|
531 | 0 | int index2 = casoUso.indexOf("Fluxos Alternativos"); |
532 | 0 | |
533 | 0 | int indexInicial = index; |
534 | 0 | |
535 | 0 | while (indexInicial <= index2) { |
536 | 0 | |
537 | 0 | int indexFinal = casoUso.indexOf(".", indexInicial + 1); |
538 | 0 | |
539 | 0 | if (indexFinal <= 0) { |
540 | 0 | break; |
541 | 0 | } |
542 | 0 | |
543 | 0 | Step step = new Step(); |
544 | 0 | step.setFluxo(flow); |
545 | 0 | String descricao = casoUso.substring(indexInicial, indexFinal); |
546 | 0 | if (descricao.length() > 500) { |
547 | 0 | descricao = descricao.substring(0, 499); |
548 | 0 | } |
549 | 0 | step.setDescricao(descricao); |
550 | 0 | |
551 | 0 | daoStep.insert(step, flow); |
552 | 0 | flow.getSteps().add(step); |
553 | 0 | |
554 | 0 | indexInicial = indexFinal; |
555 | 0 | |
556 | 0 | } |
557 | 0 | if (index <= 0) { |
558 | 0 | |
559 | 0 | contadorFP = -1; |
560 | |
} |
561 | |
|
562 | 0 | return index; |
563 | |
|
564 | |
} |
565 | |
|
566 | 0 | public boolean getFluxoAlternativoMetodo3(ArrayList<Fluxo> flows, |
567 | |
String casoUso, int contadorFP, int index, boolean continuar,CasoUso useCase) |
568 | |
throws SQLException, InstantiationException, |
569 | |
IllegalAccessException, ClassNotFoundException, IOException, |
570 | |
PassoNuloException, NomeTamanhoZeroException, FluxoNuloException { |
571 | 0 | DAOStep daoStep = new DAOStep(); |
572 | 0 | DAOFlow daoFlow=new DAOFlow(); |
573 | 0 | int indexInicial = casoUso.indexOf("Fluxos Alternativos"); |
574 | 0 | int index2 = casoUso.indexOf("Fluxos de Exce��o"); |
575 | 0 | |
576 | 0 | int alternativo = 1; |
577 | 0 | |
578 | 0 | if ((indexInicial > 0) && (index2 > 0)) { |
579 | 0 | while (indexInicial <= index2) { |
580 | 0 | int indexInicial1 = casoUso |
581 | 0 | .indexOf("MERGEFORMAT", indexInicial); |
582 | 0 | int indexFinal = casoUso.indexOf("MERGEFORMAT", |
583 | 0 | indexInicial1 + 1); |
584 | |
|
585 | 0 | if (indexFinal <= 0) { |
586 | 0 | break; |
587 | 0 | } |
588 | 0 | if (indexInicial1 <= 0) { |
589 | 0 | break; |
590 | |
} |
591 | 0 | |
592 | 0 | if (indexInicial1 > 0) { |
593 | 0 | |
594 | 0 | Fluxo flow1 = new Fluxo(); |
595 | 0 | flow1.setName("Fluxo Alternativo " + alternativo); |
596 | 0 | daoFlow.insert(flow1, useCase); |
597 | 0 | Step step = new Step(); |
598 | 0 | String descricao = casoUso.substring(indexInicial1, |
599 | 0 | indexFinal); |
600 | 0 | if (descricao.length() > 500) { |
601 | 0 | descricao = descricao.substring(0, 499); |
602 | 0 | } |
603 | 0 | step.setDescricao(descricao); |
604 | 0 | daoStep.insert(step, flow1); |
605 | 0 | flow1.getSteps().add(step); |
606 | 0 | alternativo++; |
607 | 0 | flows.add(flow1); |
608 | 0 | indexInicial = indexFinal; |
609 | |
|
610 | |
} |
611 | |
|
612 | 0 | } |
613 | |
} |
614 | |
|
615 | 0 | return true; |
616 | |
} |
617 | |
|
618 | |
public boolean getFluxoAlternativoMetodo2(ArrayList<Fluxo> flows, |
619 | |
String casoUso, int contadorFP, int index, boolean continuar, |
620 | |
CasoUso useCase) throws SQLException, InstantiationException, |
621 | |
IllegalAccessException, ClassNotFoundException, IOException, |
622 | |
PassoNuloException, NomeTamanhoZeroException, FluxoNuloException { |
623 | 0 | DAOStep daoStep = new DAOStep(); |
624 | 0 | DAOFlow daoFlow = new DAOFlow(); |
625 | |
|
626 | 0 | int indexInicial = casoUso.indexOf("Fluxos Alternativos"); |
627 | 0 | int index2 = casoUso.indexOf("Fluxos de Exce��o"); |
628 | |
|
629 | 0 | int alternativo = 1; |
630 | |
|
631 | 0 | if ((indexInicial > 0) && (index2 > 0)) { |
632 | 0 | while (indexInicial <= index2) { |
633 | 0 | int indexInicial1 = casoUso.indexOf("CDU2", indexInicial); |
634 | 0 | int indexFinal = casoUso.indexOf("CDU2", indexInicial1 + 1); |
635 | |
|
636 | 0 | if (indexFinal <= 0) { |
637 | 0 | return false; |
638 | |
|
639 | |
} |
640 | 0 | if (indexInicial1 <= 0) { |
641 | 0 | return false; |
642 | |
|
643 | |
} |
644 | |
|
645 | 0 | if (indexInicial1 > 0) { |
646 | |
|
647 | 0 | Fluxo flow1 = new Fluxo(); |
648 | 0 | flow1.setName("Fluxo Alternativo " + alternativo); |
649 | 0 | daoFlow.insert(flow1, useCase); |
650 | 0 | Step step = new Step(); |
651 | 0 | String descricao = casoUso.substring(indexInicial1, |
652 | 0 | indexFinal); |
653 | 0 | if (descricao.length() > 500) { |
654 | 0 | descricao = descricao.substring(0, 499); |
655 | |
} |
656 | 0 | step.setDescricao(descricao); |
657 | 0 | daoStep.insert(step, flow1); |
658 | 0 | flow1.getSteps().add(step); |
659 | 0 | alternativo++; |
660 | 0 | flows.add(flow1); |
661 | 0 | indexInicial = indexFinal; |
662 | |
|
663 | |
} |
664 | |
|
665 | |
} |
666 | |
} |
667 | |
|
668 | 0 | return true; |
669 | |
} |
670 | |
} |