01: /*
02: * Copyright 2006-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
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.module.cg.bo;
17:
18: import org.kuali.core.bo.user.KualiModuleUserBase;
19: import org.kuali.core.bo.user.UniversalUser;
20: import org.kuali.kfs.KFSPropertyConstants;
21: import org.kuali.module.chart.bo.ChartUser;
22:
23: /**
24: * This class allows behaviors to be defined for users within the CG module specifically.
25: */
26: public class CgUser extends KualiModuleUserBase {
27:
28: public static final String MODULE_ID = "cg";
29:
30: /**
31: * Constructs a CgUser object.
32: *
33: * @param user The universal user object to be assigned to this object.
34: */
35: public CgUser(UniversalUser user) {
36: super (MODULE_ID, user);
37: }
38:
39: /**
40: * Returns the active flag from the embedded ChartUser object.
41: *
42: * @see org.kuali.core.bo.user.KualiModuleUser#isActive()
43: */
44: @Override
45: public boolean isActive() {
46: if (getUniversalUser() == null)
47: return false;
48: String activeStatus = getUniversalUser().getModuleProperties(
49: ChartUser.MODULE_ID).get(KFSPropertyConstants.ACTIVE);
50: return activeStatus != null && activeStatus.equals("Y");
51: }
52:
53: /**
54: * Returns a flag identifying if the new user object is different from the old user object passed in. This determination is made
55: * using the following criteria:
56: * <ul>
57: * <li>Calling super.isModified()</li>
58: * <li>Checking that the old record is null and the new record is active</li>
59: * <li>Check that the old record is not null and the active indicator on the old record does not match the active indicator on
60: * the new record.</li>
61: * </ul>
62: *
63: * @param oldRecord Old universal user object
64: * @param newRecord New universal user object
65: * @see org.kuali.core.bo.user.KualiModuleUserBase#isModified(org.kuali.core.bo.user.UniversalUser,
66: * org.kuali.core.bo.user.UniversalUser)
67: */
68: @Override
69: public boolean isModified(UniversalUser oldRecord,
70: UniversalUser newRecord) {
71: boolean isThisModuleUserForNewRecordActive = "Y"
72: .equals(newRecord.getModuleProperties(
73: ChartUser.MODULE_ID).get(
74: KFSPropertyConstants.ACTIVE));
75: return super .isModified(oldRecord, newRecord)
76: || (oldRecord == null && isThisModuleUserForNewRecordActive)
77: || (oldRecord != null && oldRecord.getModuleUser(
78: MODULE_ID).isActive() != isThisModuleUserForNewRecordActive);
79: }
80:
81: /**
82: * This method throws an UnsupportedOperationException if called because setActive is not supported on this object type.
83: *
84: * @param active The active indicator value to be set.
85: * @exception UnsupportedOperationException Thrown if this method is ever called, because the defined functionality is not
86: * supported by this object.
87: * @see org.kuali.core.bo.user.KualiModuleUserBase#setActive(boolean)
88: */
89: @Override
90: public void setActive(boolean active) {
91: throw new UnsupportedOperationException(
92: "setActive is not supported on "
93: + this .getClass().getSimpleName() + " objects");
94: }
95: }
|