001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-hibernate/src/java/org/sakaiproject/tool/assessment/data/dao/authz/AuthorizationData.java $
003: * $Id: AuthorizationData.java 16922 2006-10-09 21:56:09Z ktsao@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the"License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.assessment.data.dao.authz;
021:
022: import org.sakaiproject.tool.assessment.data.ifc.authz.AuthorizationIfc;
023: import java.util.Date;
024: import java.io.Serializable;
025:
026: public class AuthorizationData implements AuthorizationIfc,
027: Serializable {
028: /**
029: *
030: */
031: private static final long serialVersionUID = -1460106795359785530L;
032: private String agentId;
033: private String functionId;
034: private String qualifierId;
035: private Date effectiveDate;
036: private Date expirationDate;
037: private Date lastModifiedDate;
038: private String lastModifiedBy;
039: private Boolean isExplicit;
040:
041: private Long surrogateKey;
042: private Integer lockId;
043:
044: /**
045: * Creates a new AuthorizationBean object.
046: */
047: public AuthorizationData() {
048: }
049:
050: /**
051: * Creates a new AuthorizationBean object.
052: *
053: * @param pk DOCUMENTATION PENDING
054: * @param effectiveDate DOCUMENTATION PENDING
055: * @param expirationDate DOCUMENTATION PENDING
056: * @param modifierId DOCUMENTATION PENDING
057: * @param modifiedDate DOCUMENTATION PENDING
058: * @param isExplicit DOCUMENTATION PENDING
059: */
060: public AuthorizationData(String agentId, String functionId,
061: String qualifierId, Date effectiveDate,
062: Date expirationDate, String lastModifiedBy,
063: Date lastModifiedDate, Boolean isExplicit) {
064: this .agentId = agentId;
065: this .functionId = functionId;
066: this .qualifierId = qualifierId;
067: this .effectiveDate = effectiveDate;
068: this .expirationDate = expirationDate;
069: this .lastModifiedBy = lastModifiedBy;
070: this .lastModifiedDate = lastModifiedDate;
071: this .isExplicit = isExplicit;
072: }
073:
074: public String getAgentIdString() {
075: return this .agentId;
076: }
077:
078: public void setAgentIdString(String id) {
079: this .agentId = id;
080: }
081:
082: public String getFunctionId() {
083: return this .functionId;
084: }
085:
086: public void setFunctionId(String id) {
087: this .functionId = id;
088: }
089:
090: public String getQualifierId() {
091: return this .qualifierId;
092: }
093:
094: public void setQualifierId(String id) {
095: this .qualifierId = id;
096: }
097:
098: public Date getAuthorizationEffectiveDate() {
099: return this .effectiveDate;
100: }
101:
102: public void setAuthorizationEffectiveDate(Date cal) {
103: this .effectiveDate = cal;
104: }
105:
106: public Date getAuthorizationExpirationDate() {
107: return this .expirationDate;
108: }
109:
110: public void setAuthorizationExpirationDate(Date cal) {
111: this .expirationDate = cal;
112: }
113:
114: public String getLastModifiedBy() {
115: return this .lastModifiedBy;
116: }
117:
118: public void setLastModifiedBy(String id) {
119: this .lastModifiedBy = id;
120: }
121:
122: public Date getLastModifiedDate() {
123: return this .lastModifiedDate;
124: }
125:
126: public void setLastModifiedDate(Date cal) {
127: this .lastModifiedDate = cal;
128: }
129:
130: public Boolean getIsExplicitBoolean() {
131: return this .isExplicit;
132: }
133:
134: public void setIsExplicitBoolean(Boolean type) {
135: this .isExplicit = type;
136: }
137:
138: public Boolean getIsActiveNowBoolean() {
139: int effectiveVal = (getAuthorizationEffectiveDate() == null) ? 0
140: : 1;
141: int expirationVal = (getAuthorizationExpirationDate() == null) ? 0
142: : 2;
143:
144: long nowMillis = (new Date()).getTime();
145: boolean returnVal = false;
146:
147: switch (effectiveVal + expirationVal) {
148: case 0: // both are null
149: returnVal = true;
150: break;
151:
152: case 1: // effectiveDate is not null
153: if (nowMillis > getAuthorizationEffectiveDate().getTime())
154: returnVal = true;
155: else
156: returnVal = false;
157: break;
158:
159: case 2: // expirationDate is not null
160: if (nowMillis < getAuthorizationExpirationDate().getTime())
161: returnVal = true;
162: else
163: returnVal = false;
164: break;
165:
166: case 3: // both effectiveDate and expirationDate are not null
167: if ((nowMillis > getAuthorizationEffectiveDate().getTime())
168: && (nowMillis < getAuthorizationExpirationDate()
169: .getTime()))
170: returnVal = true;
171: else
172: returnVal = false;
173: break;
174: }
175: return Boolean.valueOf(returnVal);
176: }
177:
178: /**
179: * @return Returns the lockId.
180: */
181: public final Integer getLockId() {
182: return lockId;
183: }
184:
185: /**
186: * @param lockId The lockId to set.
187: */
188: public final void setLockId(Integer lockId) {
189: this .lockId = lockId;
190: }
191:
192: /**
193: * @return Returns the surrogateKey.
194: */
195: public final Long getSurrogateKey() {
196: return surrogateKey;
197: }
198:
199: /**
200: * @param surrogateKey The surrogateKey to set.
201: */
202: public final void setSurrogateKey(Long surrogateKey) {
203: this .surrogateKey = surrogateKey;
204: }
205:
206: public boolean equals(Object authorization) {
207: boolean returnValue = false;
208: if (this == authorization)
209: returnValue = true;
210: if (authorization != null
211: && authorization.getClass() == this .getClass()) {
212: AuthorizationData a = (AuthorizationData) authorization;
213: if ((this .getAgentIdString()).equals(a.getAgentIdString())
214: && (this .getFunctionId()).equals(a.getFunctionId())
215: && (this .getQualifierId()).equals(a
216: .getQualifierId()))
217: returnValue = true;
218: }
219: return returnValue;
220: }
221:
222: public int hashCode() {
223: return (this .getAgentIdString() + ":" + this .getFunctionId()
224: + ":" + this.getQualifierId()).hashCode();
225: }
226: }
|