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