View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.module.purap.dataaccess.impl;
17  
18  import org.apache.ojb.broker.query.Criteria;
19  import org.apache.ojb.broker.query.QueryByCriteria;
20  import org.kuali.ole.module.purap.businessobject.PurchaseOrderSensitiveData;
21  import org.kuali.ole.module.purap.businessobject.SensitiveData;
22  import org.kuali.ole.module.purap.businessobject.SensitiveDataAssignment;
23  import org.kuali.ole.module.purap.dataaccess.SensitiveDataDao;
24  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
25  
26  import java.util.ArrayList;
27  import java.util.Collection;
28  import java.util.List;
29  
30  public class SensitiveDataDaoOjb extends PlatformAwareDaoBaseOjb implements SensitiveDataDao {
31  
32      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SensitiveDataDaoOjb.class);
33  
34      public SensitiveDataDaoOjb() {
35          super();
36      }
37  
38      /**
39       * @see org.kuali.ole.integration.service.SensitiveDataDaoe#getSensitiveDatasAssignedByPoId(java.lang.Integer)
40       */
41      public List<SensitiveData> getSensitiveDatasAssignedByPoId(Integer poId) {
42          LOG.debug("getSensitiveDatasAssignedByPoId(Integer) started");
43  
44          Criteria criteria = new Criteria();
45          criteria.addEqualTo("purapDocumentIdentifier", poId);
46          Collection<PurchaseOrderSensitiveData> posdColl = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(PurchaseOrderSensitiveData.class, criteria));
47          List<SensitiveData> sdList = new ArrayList<SensitiveData>();
48          for (PurchaseOrderSensitiveData posd : posdColl) {
49              sdList.add(posd.getSensitiveData());
50          }
51  
52          return sdList;
53      }
54  
55      /**
56       * @see org.kuali.ole.integration.service.SensitiveDataDaoe#getSensitiveDatasAssignedByReqId(java.lang.Integer)
57       */
58      public List<SensitiveData> getSensitiveDatasAssignedByReqId(Integer reqId) {
59          LOG.debug("getSensitiveDatasAssignedByReqId(Integer) started");
60  
61          Criteria criteria = new Criteria();
62          criteria.addEqualTo("requisitionIdentifier", reqId);
63          Collection<PurchaseOrderSensitiveData> posdColl = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(PurchaseOrderSensitiveData.class, criteria));
64          List<SensitiveData> sdList = new ArrayList<SensitiveData>();
65          for (PurchaseOrderSensitiveData posd : posdColl) {
66              sdList.add(posd.getSensitiveData());
67          }
68  
69          return sdList;
70      }
71  
72      /**
73       * @see org.kuali.ole.integration.service.SensitiveDataDaoe#deletePurchaseOrderSensitiveDatas(java.lang.Integer)
74       */
75      public void deletePurchaseOrderSensitiveDatas(Integer poId) {
76          LOG.debug("deletePurchaseOrderSensitiveDatas(Integer) started");
77          Criteria criteria = new Criteria();
78          criteria.addEqualTo("purapDocumentIdentifier", poId);
79          getPersistenceBrokerTemplate().deleteByQuery(new QueryByCriteria(PurchaseOrderSensitiveData.class, criteria));
80      }
81  
82      /**
83       * @see org.kuali.ole.integration.service.SensitiveDataDaoe#getLastSensitiveDataAssignment(java.lang.Integer)
84       */
85      public SensitiveDataAssignment getLastSensitiveDataAssignment(Integer poId) {
86          LOG.debug("getLastSensitiveDataAssignment(Integer) started");
87  
88          Criteria criteria = new Criteria();
89          criteria.addEqualTo("purapDocumentIdentifier", poId);
90          Collection<SensitiveDataAssignment> sdaColl = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(SensitiveDataAssignment.class, criteria));
91  
92          // look for the greatest assignment ID, which will be the latest one for this PO
93          int max = 0;
94          SensitiveDataAssignment lastsda = null;
95          for (SensitiveDataAssignment sda : sdaColl) {
96              if (sda.getSensitiveDataAssignmentIdentifier() >= max) {
97                  max = sda.getSensitiveDataAssignmentIdentifier();
98                  lastsda = sda;
99              }
100         }
101 
102         return lastsda;
103     }
104 
105     /*
106     public Integer getLastSensitiveDataAssignmentId(Integer poId) {
107         LOG.debug("getLastSensitiveDataAssignmentId(Integer) started");
108 
109         Criteria criteria = new Criteria();
110         criteria.addEqualTo("purapDocumentIdentifier", poId);
111         Collection sdaColl = getPersistenceBrokerTemplate().getCollectionByQuery(new QueryByCriteria(SensitiveDataAssignment.class, criteria));
112         if (sdaColl == null || sdaColl.isEmpty())
113             return null;
114         else {
115             SensitiveDataAssignment sda = (SensitiveDataAssignment)sdaColl.toArray()[0];        
116             return sda.getSensitiveDataAssignmentIdentifier();
117         }
118     }
119     */
120 
121 }