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 Jun 29, 2004
018: *
019: */
020: package org.kuali.module.pdp.bo;
021:
022: import java.io.Serializable;
023: import java.sql.Timestamp;
024: import java.util.Date;
025:
026: import org.apache.commons.lang.builder.EqualsBuilder;
027: import org.apache.commons.lang.builder.HashCodeBuilder;
028: import org.apache.commons.lang.builder.ToStringBuilder;
029: import org.apache.ojb.broker.PersistenceBroker;
030: import org.apache.ojb.broker.PersistenceBrokerAware;
031: import org.apache.ojb.broker.PersistenceBrokerException;
032: import org.kuali.core.bo.user.UniversalUser;
033: import org.kuali.core.exceptions.UserNotFoundException;
034: import org.kuali.core.service.UniversalUserService;
035:
036: /**
037: * @author jsissom
038: */
039: public abstract class CodeImpl implements Code, UserRequired,
040: Serializable, PersistenceBrokerAware {
041: private String code;
042: private String description;
043: private Timestamp lastUpdate;
044: private PdpUser lastUpdateUser;
045: private String lastUpdateUserId;
046: private Integer version;
047:
048: public PdpUser getLastUpdateUser() {
049: return lastUpdateUser;
050: }
051:
052: public void setLastUpdateUser(PdpUser s) {
053: if (s != null) {
054: this .lastUpdateUserId = s.getUniversalUser()
055: .getPersonUniversalIdentifier();
056: } else {
057: this .lastUpdateUserId = null;
058: }
059: this .lastUpdateUser = s;
060: }
061:
062: public String getLastUpdateUserId() {
063: return lastUpdateUserId;
064: }
065:
066: public void setLastUpdateUserId(String lastUpdateUserId) {
067: this .lastUpdateUserId = lastUpdateUserId;
068: }
069:
070: public void updateUser(UniversalUserService userService)
071: throws UserNotFoundException {
072: UniversalUser u = userService
073: .getUniversalUser(lastUpdateUserId);
074: if (u == null) {
075: setLastUpdateUser(null);
076: } else {
077: setLastUpdateUser(new PdpUser(u));
078: }
079: }
080:
081: public boolean equals(Object obj) {
082: if (!(obj instanceof Code)) {
083: return false;
084: }
085: Code tc = (Code) obj;
086: return new EqualsBuilder().append(code, tc.getCode())
087: .isEquals();
088: }
089:
090: /**
091: * @return Returns the code.
092: */
093: public String getCode() {
094: return code;
095: }
096:
097: public String getData() {
098: return code + "~" + description;
099: }
100:
101: /**
102: * @return Returns the description.
103: */
104: public String getDescription() {
105: return description;
106: }
107:
108: /**
109: * These need to be implemented in classes that extend this one. These are used to make sure the hash value is unique for each
110: * value.
111: *
112: * @return
113: */
114: protected abstract int getHashValue1();
115:
116: protected abstract int getHashValue2();
117:
118: /**
119: * @return Returns the lastUpdate.
120: */
121: public Timestamp getLastUpdate() {
122: return lastUpdate;
123: }
124:
125: /**
126: * @return Returns the version.
127: */
128: public Integer getVersion() {
129: return version;
130: }
131:
132: public int hashCode() {
133: return new HashCodeBuilder(getHashValue1(), getHashValue2())
134: .append(code).toHashCode();
135: }
136:
137: /**
138: * @param code The code to set.
139: */
140: public void setCode(String code) {
141: this .code = code;
142: }
143:
144: /**
145: * @param description The description to set.
146: */
147: public void setDescription(String description) {
148: this .description = description;
149: }
150:
151: /**
152: * @param lastUpdate The lastUpdate to set.
153: */
154: public void setLastUpdate(Timestamp lastUpdate) {
155: this .lastUpdate = lastUpdate;
156: }
157:
158: /**
159: * @param ojbVerNbr The ojbVerNbr to set.
160: */
161: public void setVersion(Integer ver) {
162: this .version = ver;
163: }
164:
165: public String toString() {
166: return new ToStringBuilder(this ).append("code", this .code)
167: .append("description", this .description).toString();
168: }
169:
170: public void beforeInsert(PersistenceBroker broker)
171: throws PersistenceBrokerException {
172: lastUpdate = new Timestamp((new Date()).getTime());
173: }
174:
175: public void afterInsert(PersistenceBroker broker)
176: throws PersistenceBrokerException {
177:
178: }
179:
180: public void beforeUpdate(PersistenceBroker broker)
181: throws PersistenceBrokerException {
182: lastUpdate = new Timestamp((new Date()).getTime());
183: }
184:
185: public void afterUpdate(PersistenceBroker broker)
186: throws PersistenceBrokerException {
187:
188: }
189:
190: public void beforeDelete(PersistenceBroker broker)
191: throws PersistenceBrokerException {
192:
193: }
194:
195: public void afterDelete(PersistenceBroker broker)
196: throws PersistenceBrokerException {
197:
198: }
199:
200: public void afterLookup(PersistenceBroker broker)
201: throws PersistenceBrokerException {
202:
203: }
204: }
|