Parent: [9e28b1] (diff)

Child: [19506b] (diff)

Download this file

EPCReader.java    69 lines (55 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package net.timbusproject.iermtoowl.utils;
import net.timbusproject.iermtoowl.Main;
import net.timbusproject.iermtoowl.epc.Connections;
import net.timbusproject.iermtoowl.epc.EPCModel;
import net.timbusproject.iermtoowl.epc.Elements;
import net.timbusproject.iermtoowl.risks.BusinessActivity;
import net.timbusproject.iermtoowl.risks.BusinessProcess;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.File;
import java.util.HashMap;
import java.util.List;
/**
* Created by miguel on 27-06-2014.
*/
public class EPCReader {
private EPCModel epc;
private HashMap<String, Elements> elementById;
public EPCReader() {
elementById = new HashMap<>();
}
public EPCModel readFromFile(String path, BusinessProcess bp) {
try {
File file = Main.fileHandler(path);
JAXBContext jaxbContext = JAXBContext.newInstance(EPCModel.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
epc = (EPCModel) jaxbUnmarshaller.unmarshal(file);
if (bp != null)
organizeBusinessActivitesByFunctionID(bp.getBusinessActivity());
organizeElementsById();
System.out.println("_______________________________________\n");
System.out.println("EPC XML - Elements found:\nElements: " + epc.getElements().size() + "\nConnections: " + epc.getConnections().size() + "\n");
} catch (JAXBException e) {
e.printStackTrace();
}
return epc;
}
private void organizeElementsById() {
for (Elements e : epc.getElements()) {
elementById.put(e.getUuid(), e);
}
}
private void organizeBusinessActivitesByFunctionID(List<BusinessActivity> activities) {
for (BusinessActivity ba : activities) {
String functionId = ba.getFunctionId();
for (Elements e : epc.getElements()) {
if (e.getUuid().equals(functionId)) {
e.setBusinessActivityInstance(ba);
break;
}
}
}
}
}