View Javadoc

1   /**
2    * Copyright 2004-2013 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.positionappointment.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.OjbSubQueryUtil;
28  import org.kuali.kpme.core.util.ValidationUtils;
29  import org.kuali.kpme.pm.positionappointment.PositionAppointment;
30  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
31  
32  import com.google.common.collect.ImmutableList;
33  
34  public class PositionAppointmentDaoObjImpl extends PlatformAwareDaoBaseOjb implements PositionAppointmentDao {
35  
36  	private static final ImmutableList<String> PRG_EQUAL_TO_FIELDS = new ImmutableList.Builder<String>()
37  			.add("positionAppointment").add("institution").add("location")
38  			.build();
39  
40  	public PositionAppointment getPositionAppointmentById(String pmPositionAppointmentId) {
41  		
42  		Criteria crit = new Criteria();
43  		crit.addEqualTo("pmPositionAppointmentId", pmPositionAppointmentId);
44  
45  		Query query = QueryFactory.newQuery(PositionAppointment.class, crit);
46  		return (PositionAppointment) this.getPersistenceBrokerTemplate().getObjectByQuery(query);
47  	}
48  
49  	public List<PositionAppointment> getPositionAppointmentList(String positionAppointment, String description, String institution, String location, 
50  			LocalDate fromEffdt, LocalDate toEffdt, String active, String showHistory) {
51  		
52  		List<PositionAppointment> prgList = new ArrayList<PositionAppointment>();
53  		Criteria root = new Criteria();
54  
55  		if (StringUtils.isNotEmpty(positionAppointment) 
56  				&& !ValidationUtils.isWildCard(positionAppointment)) {
57  			root.addLike("UPPER(`pstn_appointment`)", positionAppointment.toUpperCase());
58  		}
59  		
60  		if (StringUtils.isNotEmpty(description) 
61  				&& !ValidationUtils.isWildCard(description)) {
62  			root.addLike("UPPER(`description`)", description.toUpperCase());
63  		}
64  		
65  		if (StringUtils.isNotEmpty(institution) 
66  				&& !ValidationUtils.isWildCard(institution)) {
67  			root.addLike("UPPER(`institution`)", institution.toUpperCase());
68  		}
69  		
70  		if (StringUtils.isNotEmpty(location) 
71  				&& !ValidationUtils.isWildCard(location)) {
72  			root.addLike("UPPER(`location`)", location.toUpperCase());
73  		}
74  
75  		Criteria effectiveDateFilter = new Criteria();
76          if (fromEffdt != null) {
77              effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate());
78          }
79          if (toEffdt != null) {
80              effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate());
81          }
82          if (fromEffdt == null && toEffdt == null) {
83              effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate());
84          }
85          root.addAndCriteria(effectiveDateFilter);
86          
87  		if (StringUtils.isNotBlank(active)) {
88          	Criteria activeFilter = new Criteria();
89              if (StringUtils.equals(active, "Y")) {
90                  activeFilter.addEqualTo("active", true);
91              } else if (StringUtils.equals(active, "N")) {
92                  activeFilter.addEqualTo("active", false);
93              }
94              root.addAndCriteria(activeFilter);
95          }
96  		
97  		//root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQuery(PositionAppointment.class, asOfDate, PRG_EQUAL_TO_FIELDS, false));
98  		//root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionAppointment.class, PRG_EQUAL_TO_FIELDS, false));
99  		if (StringUtils.equals(showHistory, "N")) {
100             root.addEqualTo("effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter(PositionAppointment.class, effectiveDateFilter, PRG_EQUAL_TO_FIELDS, false));
101             root.addEqualTo("timestamp", OjbSubQueryUtil.getTimestampSubQuery(PositionAppointment.class, PRG_EQUAL_TO_FIELDS, false));
102         }
103 		
104 
105 		Query query = QueryFactory.newQuery(PositionAppointment.class, root);
106 
107 		Collection c = this.getPersistenceBrokerTemplate().getCollectionByQuery(query);
108 		
109 		if (!c.isEmpty())
110 			prgList.addAll(c);
111 
112 		return prgList;
113 	}
114 
115 }