View Javadoc

1   /**
2    * Copyright 2004-2014 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.kpme.pm.positionreportgroup.dao;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.List;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.apache.ojb.broker.query.Criteria;
24  import org.apache.ojb.broker.query.Query;
25  import org.apache.ojb.broker.query.QueryFactory;
26  import org.joda.time.LocalDate;
27  import org.kuali.kpme.core.util.HrConstants;
28  import org.kuali.kpme.core.util.OjbSubQueryUtil;
29  import org.kuali.kpme.core.util.ValidationUtils;
30  import org.kuali.kpme.pm.positionreportgroup.PositionReportGroup;
31  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
32  
33  public class PositionReportGroupDaoObjImpl extends PlatformAwareDaoBaseOjb implements PositionReportGroupDao {
34  
35  	@Override
36  	public PositionReportGroup getPositionReportGroupById(
37  			String pmPositionReportGroupId) {
38  		Criteria crit = new Criteria();
39          crit.addEqualTo("pmPositionReportGroupId", pmPositionReportGroupId);
40  
41          Query query = QueryFactory.newQuery(PositionReportGroup.class, crit);
42          return (PositionReportGroup) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
43  	}
44  
45  	@Override
46  	public List<PositionReportGroup> getPositionReportGroupList(String positionReportGroup, String institution, String location, LocalDate asOfDate) {
47  		List<PositionReportGroup> prgList = new ArrayList<PositionReportGroup>();
48  		Criteria root = new Criteria();
49  
50  		if(StringUtils.isNotEmpty(positionReportGroup) 
51  				&& !ValidationUtils.isWildCard(positionReportGroup)) {
52  			root.addEqualTo("positionReportGroup", positionReportGroup);  
53  		}
54  		if(StringUtils.isNotEmpty(institution) 
55  				&& !ValidationUtils.isWildCard(institution)) {
56  			root.addEqualTo("institution", institution); 
57  		}
58  		if(StringUtils.isNotEmpty(location) 
59  				&& !ValidationUtils.isWildCard(location)) {
60  			root.addEqualTo("location", location); 
61  		}
62          
63          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionReportGroup.class, asOfDate, PositionReportGroup.EQUAL_TO_FIELDS, false));
64          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionReportGroup.class, PositionReportGroup.EQUAL_TO_FIELDS, false));
65          
66          Criteria activeFilter = new Criteria();
67          activeFilter.addEqualTo("active", true);
68          root.addAndCriteria(activeFilter);
69  
70          Query query = QueryFactory.newQuery(PositionReportGroup.class, root);
71          
72          Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
73  		if(!c.isEmpty())
74  			prgList.addAll(c);
75  		
76  		return prgList;
77  	}
78  
79  	@Override
80  	public PositionReportGroup getPositionReportGroup(String positionReportGroup, LocalDate asOfDate) {
81  		Criteria root = new Criteria();
82          root.addEqualTo("positionReportGroup", positionReportGroup);
83          root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionReportGroup.class, asOfDate, PositionReportGroup.EQUAL_TO_FIELDS, false));
84          root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionReportGroup.class, PositionReportGroup.EQUAL_TO_FIELDS, false));
85          
86          Criteria activeFilter = new Criteria();
87          activeFilter.addEqualTo("active", true);
88          root.addAndCriteria(activeFilter);
89          
90          Query query = QueryFactory.newQuery(PositionReportGroup.class, root);
91          return (PositionReportGroup) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
92  	}
93  
94  }