1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.document.dataaccess.impl;
17
18 import org.apache.ojb.broker.query.Criteria;
19 import org.apache.ojb.broker.query.ReportQueryByCriteria;
20 import org.kuali.ole.module.purap.PurapPropertyConstants;
21 import org.kuali.ole.module.purap.document.RequisitionDocument;
22 import org.kuali.ole.module.purap.document.dataaccess.RequisitionDao;
23 import org.kuali.ole.sys.OLEPropertyConstants;
24 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
25 import org.springframework.transaction.annotation.Transactional;
26
27 import java.util.List;
28
29
30
31
32 @Transactional
33 public class RequisitionDaoOjb extends PlatformAwareDaoBaseOjb implements RequisitionDao {
34 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(RequisitionDaoOjb.class);
35
36
37
38
39 public String getDocumentNumberForRequisitionId(Integer id) {
40 Criteria criteria = new Criteria();
41 criteria.addEqualTo(PurapPropertyConstants.PURAP_DOC_ID, id);
42
43 ReportQueryByCriteria rqbc = new ReportQueryByCriteria(RequisitionDocument.class, criteria);
44 rqbc.addOrderByAscending(OLEPropertyConstants.DOCUMENT_NUMBER);
45
46 List<RequisitionDocument> reqs = (List<RequisitionDocument>) getPersistenceBrokerTemplate().getCollectionByQuery(rqbc);
47
48 if (reqs.isEmpty()) {
49 return null;
50 }
51 if (reqs.size() > 1) {
52 String errorMsg = "Expected single document number for given criteria but multiple (at least 2) were returned";
53 LOG.error(errorMsg);
54 throw new RuntimeException();
55 } else {
56 RequisitionDocument req = reqs.get(0);
57 return req.getDocumentNumber();
58 }
59 }
60 }