1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.kuali.rice.edl.impl.extract.dao.impl; |
19 | |
|
20 | |
import java.util.List; |
21 | |
|
22 | |
import javax.persistence.EntityManager; |
23 | |
import javax.persistence.PersistenceContext; |
24 | |
|
25 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
26 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.Criteria; |
27 | |
import org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria; |
28 | |
import org.kuali.rice.edl.impl.extract.Dump; |
29 | |
import org.kuali.rice.edl.impl.extract.Fields; |
30 | |
import org.kuali.rice.edl.impl.extract.dao.ExtractDAO; |
31 | |
import org.kuali.rice.kew.notes.Note; |
32 | |
|
33 | 0 | public class ExtractDAOJpaImpl implements ExtractDAO { |
34 | |
|
35 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ExtractDAOJpaImpl.class); |
36 | |
|
37 | |
@PersistenceContext(unitName = "kew-unit") |
38 | |
private EntityManager entityManager; |
39 | |
|
40 | |
public Dump getDumpByDocumentId(String docId) { |
41 | 0 | LOG.debug("finding Document Extract by documentId " + docId); |
42 | 0 | Criteria crit = new Criteria(Dump.class.getName()); |
43 | 0 | crit.eq("docId", docId); |
44 | 0 | return (Dump) new QueryByCriteria(entityManager, crit).toQuery().getSingleResult(); |
45 | |
} |
46 | |
|
47 | |
public List<Fields> getFieldsByDocumentId(String docId) { |
48 | 0 | LOG.debug("finding Extract Fileds by documentId " + docId); |
49 | 0 | Criteria crit = new Criteria(Fields.class.getName()); |
50 | 0 | crit.eq("documentId", docId); |
51 | 0 | crit.orderBy("docId", true); |
52 | |
|
53 | 0 | return (List<Fields>) new QueryByCriteria(entityManager, crit).toQuery().getResultList(); |
54 | |
} |
55 | |
|
56 | |
public void saveDump(Dump dump) { |
57 | 0 | LOG.debug("check for null values in Extract document"); |
58 | 0 | checkNull(dump.getDocId(), "Document ID"); |
59 | 0 | checkNull(dump.getDocCreationDate(), "Creation Date"); |
60 | 0 | checkNull(dump.getDocCurrentNodeName(), "Current Node Name"); |
61 | 0 | checkNull(dump.getDocModificationDate(), "Modification Date"); |
62 | 0 | checkNull(dump.getDocRouteStatusCode(), "Route Status Code"); |
63 | 0 | checkNull(dump.getDocInitiatorId(), "Initiator ID"); |
64 | 0 | checkNull(dump.getDocTypeName(), "Doc Type Name"); |
65 | 0 | LOG.debug("saving EDocLite document: routeHeader " + dump.getDocId()); |
66 | 0 | if (dump.getDocId() == null) { |
67 | 0 | entityManager.persist(dump); |
68 | |
} else { |
69 | 0 | OrmUtils.merge(entityManager, dump); |
70 | |
} |
71 | 0 | } |
72 | |
|
73 | |
public void saveField(Fields field) { |
74 | 0 | LOG.debug("saving EDocLite Extract fields"); |
75 | 0 | checkNull(field.getDocId(), "Document ID"); |
76 | 0 | checkNull(field.getFieldValue(), "Field Value"); |
77 | 0 | checkNull(field.getFiledName(), "Field Name"); |
78 | 0 | LOG.debug("saving Fields: routeHeader " + field.getFieldId()); |
79 | |
|
80 | 0 | if (field.getFieldId() == null) { |
81 | 0 | entityManager.persist(field); |
82 | |
} else { |
83 | 0 | OrmUtils.merge(entityManager, field); |
84 | |
} |
85 | 0 | } |
86 | |
|
87 | |
private void checkNull(Object value, String valueName) throws RuntimeException { |
88 | 0 | if (value == null) { |
89 | 0 | throw new RuntimeException("Null value for " + valueName); |
90 | |
} |
91 | 0 | } |
92 | |
|
93 | |
public void deleteDump(String documentId) { |
94 | 0 | LOG.debug("deleting record form Extract Dump table"); |
95 | 0 | entityManager.remove(entityManager.find(Note.class, documentId)); |
96 | 0 | } |
97 | |
|
98 | |
public EntityManager getEntityManager() { |
99 | 0 | return this.entityManager; |
100 | |
} |
101 | |
|
102 | |
public void setEntityManager(EntityManager entityManager) { |
103 | 0 | this.entityManager = entityManager; |
104 | 0 | } |
105 | |
} |