001 /** 002 * Copyright 2004-2013 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.hr.lm.leaveblock.dao; 017 018 import java.util.ArrayList; 019 import java.util.Collection; 020 import java.util.Date; 021 import java.util.List; 022 023 import org.apache.log4j.Logger; 024 import org.apache.ojb.broker.query.Criteria; 025 import org.apache.ojb.broker.query.Query; 026 import org.apache.ojb.broker.query.QueryFactory; 027 import org.kuali.hr.lm.LMConstants; 028 import org.kuali.hr.lm.leaveblock.LeaveBlockHistory; 029 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb; 030 031 public class LeaveBlockHistoryDaoSpringOjbImpl extends PlatformAwareDaoBaseOjb implements LeaveBlockHistoryDao { 032 033 @SuppressWarnings("unused") 034 private static final Logger LOG = Logger 035 .getLogger(LeaveBlockHistoryDaoSpringOjbImpl.class); 036 037 @Override 038 public void saveOrUpdate(LeaveBlockHistory leaveBlockHistory) { 039 this.getPersistenceBrokerTemplate().store(leaveBlockHistory); 040 } 041 042 @Override 043 public void saveOrUpdate(List<LeaveBlockHistory> leaveBlockHistoryList) { 044 if (leaveBlockHistoryList != null) { 045 for (LeaveBlockHistory leaveBlockHistory : leaveBlockHistoryList) { 046 this.getPersistenceBrokerTemplate().store(leaveBlockHistory); 047 } 048 049 } 050 } 051 052 @Override 053 public List<LeaveBlockHistory> getLeaveBlockHistoryByLmLeaveBlockId( 054 String lmLeaveBlockId) { 055 Criteria recordCriteria = new Criteria(); 056 recordCriteria.addEqualTo("lmLeaveBlockId", lmLeaveBlockId); 057 Query query = QueryFactory.newQuery(LeaveBlockHistory.class, 058 recordCriteria); 059 return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate() 060 .getCollectionByQuery(query); 061 } 062 063 @Override 064 public List<LeaveBlockHistory> getLeaveBlockHistories(String principalId, 065 List<String> requestStatus) { 066 Criteria recordCriteria = new Criteria(); 067 recordCriteria.addEqualTo("principalId", principalId); 068 if (requestStatus != null) { 069 recordCriteria.addIn("requestStatus", requestStatus); 070 } 071 Query query = QueryFactory.newQuery(LeaveBlockHistory.class, 072 recordCriteria); 073 return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate() 074 .getCollectionByQuery(query); 075 } 076 077 @Override 078 public List<LeaveBlockHistory> getLeaveBlockHistories(String principalId,String requestStatus, String action, Date currentDate) { 079 Criteria recordCriteria = new Criteria(); 080 recordCriteria.addEqualTo("principalId", principalId); 081 if (requestStatus != null) { 082 recordCriteria.addEqualTo("requestStatus", requestStatus); 083 } 084 if(currentDate != null) { 085 recordCriteria.addGreaterThan("leaveDate", currentDate); 086 } 087 if(action != null) { 088 recordCriteria.addEqualTo("action", action); 089 } 090 Query query = QueryFactory.newQuery(LeaveBlockHistory.class, 091 recordCriteria); 092 return (List<LeaveBlockHistory>) this.getPersistenceBrokerTemplate() 093 .getCollectionByQuery(query); 094 } 095 096 @Override 097 public List<LeaveBlockHistory> getLeaveBlockHistoriesForLeaveDisplay(String principalId, 098 Date beginDate, Date endDate, boolean considerModifiedUser) { 099 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 }