001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: /*
017: * Created on Aug 19, 2004
018: *
019: */
020: package org.kuali.module.pdp.dao.ojb;
021:
022: import java.sql.Timestamp;
023: import java.util.Calendar;
024: import java.util.Date;
025: import java.util.GregorianCalendar;
026: import java.util.Iterator;
027: import java.util.List;
028:
029: import org.apache.ojb.broker.query.Criteria;
030: import org.apache.ojb.broker.query.QueryByCriteria;
031: import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
032: import org.kuali.core.exceptions.UserNotFoundException;
033: import org.kuali.core.service.UniversalUserService;
034: import org.kuali.module.pdp.bo.PaymentProcess;
035: import org.kuali.module.pdp.bo.PdpUser;
036: import org.kuali.module.pdp.bo.UserRequired;
037: import org.kuali.module.pdp.dao.ProcessDao;
038:
039: /**
040: * @author jsissom
041: */
042: public class ProcessDaoOjb extends PlatformAwareDaoBaseOjb implements
043: ProcessDao {
044: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
045: .getLogger(ProcessDaoOjb.class);
046:
047: private UniversalUserService userService;
048:
049: public void setUniversalUserService(UniversalUserService u) {
050: userService = u;
051: }
052:
053: public ProcessDaoOjb() {
054: super ();
055: }
056:
057: public PaymentProcess createProcess(String campusCd,
058: PdpUser processUser) {
059: LOG.debug("createProcess() started");
060:
061: Date d = new Date();
062: Timestamp now = new Timestamp(d.getTime());
063:
064: PaymentProcess p = new PaymentProcess();
065: p.setCampus(campusCd);
066: p.setProcessUser(processUser);
067: p.setProcessTimestamp(now);
068:
069: getPersistenceBrokerTemplate().store(p);
070:
071: return p;
072: }
073:
074: public PaymentProcess get(Integer procId) {
075: LOG.debug("get() started");
076:
077: Criteria c = new Criteria();
078: c.addEqualTo("id", procId);
079:
080: PaymentProcess p = (PaymentProcess) getPersistenceBrokerTemplate()
081: .getObjectByQuery(
082: new QueryByCriteria(PaymentProcess.class, c));
083: if (p != null) {
084: updateProcessUser(p);
085: return p;
086: } else {
087: return null;
088: }
089: }
090:
091: public List getMostCurrentProcesses(Integer number) {
092: LOG.debug("get() started");
093:
094: Criteria c = new Criteria();
095: GregorianCalendar gc = new GregorianCalendar();
096: gc.setTime(new Date());
097: gc.add(Calendar.MONTH, -4);
098: c.addGreaterOrEqualThan("processTimestamp", new Timestamp(gc
099: .getTimeInMillis()));
100: QueryByCriteria qbc = new QueryByCriteria(PaymentProcess.class,
101: c);
102: qbc.setEndAtIndex(number.intValue());
103: qbc.addOrderByDescending("processTimestamp");
104: List l = (List) getPersistenceBrokerTemplate()
105: .getCollectionByQuery(qbc);
106: updateProcessUser(l);
107:
108: return l;
109: }
110:
111: private void updateProcessUser(List l) {
112: for (Iterator iter = l.iterator(); iter.hasNext();) {
113: updateProcessUser((PaymentProcess) iter.next());
114: }
115: }
116:
117: private void updateProcessUser(PaymentProcess b) {
118: UserRequired ur = (UserRequired) b;
119: try {
120: ur.updateUser(userService);
121: } catch (UserNotFoundException e) {
122: b.setProcessUser(null);
123: }
124: }
125: }
|