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.hr.lm.leaveblock.dao;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.Date;
21  import java.util.List;
22  
23  import org.apache.log4j.Logger;
24  import org.apache.ojb.broker.query.Criteria;
25  import org.apache.ojb.broker.query.Query;
26  import org.apache.ojb.broker.query.QueryFactory;
27  import org.kuali.hr.lm.LMConstants;
28  import org.kuali.hr.lm.leaveblock.LeaveBlockHistory;
29  import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
30  
31  public class LeaveBlockHistoryDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements LeaveBlockHistoryDao {
32  
33  	@SuppressWarnings("unused")
34  	private static final Logger LOG = Logger
35  			.getLogger(LeaveBlockHistoryDaoSpringOjbImpl.class);
36  
37  	@Override
38  	public void saveOrUpdate(LeaveBlockHistory leaveBlockHistory) {
39  		this.getPersistenceBrokerTemplate().store(leaveBlockHistory);
40  	}
41  
42  	@Override
43  	public void saveOrUpdate(List<LeaveBlockHistory> leaveBlockHistoryList) {
44  		if (leaveBlockHistoryList != null) {
45  			for (LeaveBlockHistory leaveBlockHistory : leaveBlockHistoryList) {
46  				this.getPersistenceBrokerTemplate().store(leaveBlockHistory);
47  			}
48  
49  		}
50  	}
51  
52  	@Override
53  	public List<LeaveBlockHistory> getLeaveBlockHistoryByLmLeaveBlockId(
54  			String lmLeaveBlockId) {
55  		Criteria recordCriteria = new Criteria();
56  		recordCriteria.addEqualTo("lmLeaveBlockId", lmLeaveBlockId);
57  		Query query = QueryFactory.newQuery(LeaveBlockHistory.class,
58  				recordCriteria);
59  		return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate()
60  				.getCollectionByQuery(query);
61  	}
62  
63  	@Override
64  	public List<LeaveBlockHistory> getLeaveBlockHistories(String principalId,
65  			List<String> requestStatus) {
66  		Criteria recordCriteria = new Criteria();
67  		recordCriteria.addEqualTo("principalId", principalId);
68  		if (requestStatus != null) {
69  			recordCriteria.addIn("requestStatus", requestStatus);
70  		}
71  		Query query = QueryFactory.newQuery(LeaveBlockHistory.class,
72  				recordCriteria);
73  		return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate()
74  				.getCollectionByQuery(query);
75  	}
76  	
77  	@Override
78  	public List<LeaveBlockHistory> getLeaveBlockHistories(String principalId,String requestStatus, String action, Date currentDate) {
79  		Criteria recordCriteria = new Criteria();
80  		recordCriteria.addEqualTo("principalId", principalId);
81  		if (requestStatus != null) {
82  			recordCriteria.addEqualTo("requestStatus", requestStatus);
83  		}
84  		if(currentDate != null) {
85  			recordCriteria.addGreaterThan("leaveDate", currentDate);
86  		}
87  		if(action != null) {
88  			recordCriteria.addEqualTo("action", action);
89  		}
90  		Query query = QueryFactory.newQuery(LeaveBlockHistory.class,
91  				recordCriteria);
92  		return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate()
93  				.getCollectionByQuery(query);
94  	}
95  
96  	@Override
97  	public List<LeaveBlockHistory> getLeaveBlockHistoriesForLeaveDisplay(String principalId,
98  			Date beginDate, Date endDate, boolean considerModifiedUser) {
99  		
100 		List<LeaveBlockHistory> leaveBlockHistories = new ArrayList<LeaveBlockHistory>();
101 		
102 		Criteria root = new Criteria();
103 		root.addEqualTo("principalId", principalId);
104 		root.addGreaterOrEqualThan("leaveDate", beginDate);
105 		root.addLessOrEqualThan("leaveDate", endDate);
106 		root.addEqualTo("action",LMConstants.ACTION.MODIFIED);
107 		if(considerModifiedUser) {
108 			root.addNotEqualTo("principalIdModified", principalId);
109 		} 
110 		
111 		Criteria root1 = new Criteria();
112 		root1.addEqualTo("principalId", principalId);
113 		root1.addGreaterOrEqualThan("leaveDate", beginDate);
114 		root1.addLessOrEqualThan("leaveDate", endDate);
115 		root1.addEqualTo("action",LMConstants.ACTION.DELETE);
116 		if(considerModifiedUser) {
117 			root1.addNotEqualTo("principalIdDeleted", principalId);
118 		} 
119 		
120 		root.addOrCriteria(root1);
121 		
122 		Query query = QueryFactory.newQuery(LeaveBlockHistory.class, root);
123 		Collection c = this.getPersistenceBrokerTemplate()
124 				.getCollectionByQuery(query);
125 
126 		if (c != null) {
127 			leaveBlockHistories.addAll(c);
128 		}
129 		return leaveBlockHistories;
130 	}
131 }