Commit | Line | Data |
---|---|---|
6f43ba4a MS |
1 | package org.ufcspa.simdecs.session.crud.admin; |
2 | ||
69e26a06 MS |
3 | import java.io.ByteArrayInputStream; |
4 | import java.util.ArrayList; | |
5 | ||
6 | import javax.persistence.EntityManager; | |
7 | ||
8 | import org.jboss.seam.annotations.In; | |
9 | import org.jboss.seam.annotations.Logger; | |
6f43ba4a MS |
10 | import org.jboss.seam.annotations.Name; |
11 | import org.jboss.seam.annotations.Begin; | |
12 | import org.jboss.seam.annotations.web.RequestParameter; | |
69e26a06 | 13 | import org.jboss.seam.log.Log; |
6f43ba4a | 14 | |
d1c23fc5 | 15 | import org.ufcspa.simdecs.entities.ArquivoRedeBayesiana; |
69e26a06 MS |
16 | import org.ufcspa.simdecs.entities.BayesianNetworkParser; |
17 | import org.ufcspa.simdecs.entities.Nodo; | |
d1c23fc5 | 18 | import org.ufcspa.simdecs.entities.RedeBayesiana; |
69e26a06 | 19 | import org.ufcspa.simdecs.session.crud.defaults.SimDeCSEntityHome; |
6f43ba4a | 20 | |
d1c23fc5 MS |
21 | @Name("arquivoRedeBayesianaHome") |
22 | public class ArquivoRedeBayesianaHome extends SimDeCSEntityHome<ArquivoRedeBayesiana> | |
6f43ba4a | 23 | { |
69e26a06 | 24 | private static final long serialVersionUID = 1L; |
6f43ba4a | 25 | |
69e26a06 MS |
26 | @Logger private Log log; |
27 | @In | |
28 | private EntityManager entityManager; | |
29 | ||
30 | @RequestParameter Long arquivoRedeId; | |
31 | ||
6f43ba4a MS |
32 | @Override |
33 | public Object getId() | |
34 | { | |
35 | if (arquivoRedeId == null) | |
36 | { | |
37 | return super.getId(); | |
38 | } | |
39 | else | |
40 | { | |
41 | return arquivoRedeId; | |
42 | } | |
43 | } | |
44 | ||
79f1af86 | 45 | @Override @Begin(join=true) |
6f43ba4a MS |
46 | public void create() { |
47 | super.create(); | |
48 | } | |
69e26a06 MS |
49 | |
50 | public void saveNetwork() throws Exception { | |
51 | BayesianNetworkParser parser = new BayesianNetworkParser(); | |
52 | parser.parseBayesianNetwork(new ByteArrayInputStream(super.getInstance().getData())); | |
53 | String name = parser.getBayesianNetworkName(); | |
54 | ArrayList<String> nodes = parser.getBayesianNetworkNodes(); | |
55 | log.info(name + ": " + nodes); | |
56 | ||
d1c23fc5 | 57 | RedeBayesiana rede = new RedeBayesiana(); |
69e26a06 MS |
58 | rede.setNome(name); |
59 | rede.setArquivo(super.getInstance()); | |
79f1af86 MS |
60 | ArrayList<Nodo> nodos = new ArrayList<Nodo>(); |
61 | ||
69e26a06 MS |
62 | for (int i = 0; i < nodes.size(); i++){ |
63 | Nodo nodo = new Nodo(); | |
64 | nodo.setNome(nodes.get(i)); | |
d1c23fc5 | 65 | nodo.setRedeBayesiana(rede); |
69e26a06 | 66 | entityManager.persist(nodo); |
79f1af86 | 67 | nodos.add(nodo); |
69e26a06 MS |
68 | } |
69 | ||
79f1af86 MS |
70 | rede.setNodos(nodos); |
71 | entityManager.persist(rede); | |
69e26a06 MS |
72 | super.persist(); |
73 | } | |
6f43ba4a MS |
74 | |
75 | } |