001: /*
002: * Copyright 2006-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: package org.kuali.core.bo.user;
017:
018: import java.util.LinkedHashMap;
019: import java.util.Map;
020:
021: import org.apache.commons.lang.StringUtils;
022: import org.kuali.RiceConstants;
023: import org.kuali.RicePropertyConstants;
024: import org.kuali.core.bo.TransientBusinessObjectBase;
025: import org.kuali.rice.KNSServiceLocator;
026:
027: public class KualiModuleUserBase extends TransientBusinessObjectBase
028: implements KualiModuleUser {
029:
030: private String personUniversalIdentifier;
031: private UniversalUser universalUser;
032: private String moduleId;
033:
034: public KualiModuleUserBase(String moduleId, UniversalUser user) {
035: this .moduleId = moduleId;
036: setUniversalUser(user);
037: }
038:
039: public boolean isModified(UniversalUser oldRecord,
040: UniversalUser newRecord) {
041: for (String propertyName : newRecord.getModuleProperties(
042: moduleId).keySet()) {
043: String newPropertyValue = newRecord.getModuleProperties(
044: moduleId).get(propertyName);
045: String oldPropertyValue = null;
046: if (oldRecord != null) {
047: if ((oldRecord.getModuleUser(moduleId) != null)
048: && (oldRecord.getModuleProperties(moduleId) != null)
049: && oldRecord.getModuleProperties(moduleId)
050: .containsKey(propertyName)) {
051: oldPropertyValue = oldRecord.getModuleProperties(
052: moduleId).get(propertyName);
053: }
054: }
055: if (((oldRecord == null) && !StringUtils
056: .isBlank(newPropertyValue))
057: || !StringUtils.equals(oldPropertyValue,
058: newPropertyValue)) {
059: return true;
060: }
061: }
062: return false;
063: }
064:
065: public boolean isActive() {
066: return getUserProperty(RicePropertyConstants.ACTIVE)
067: .equals("Y");
068: }
069:
070: protected boolean isActiveFacultyStaffAffiliate() {
071: return (getUniversalUser().isFaculty()
072: || getUniversalUser().isStaff() || getUniversalUser()
073: .isAffiliate())
074: && KNSServiceLocator
075: .getKualiConfigurationService()
076: .evaluateConstrainedValue(
077: RiceConstants.KNS_NAMESPACE,
078: RiceConstants.DetailTypes.UNIVERSAL_USER_DETAIL_TYPE,
079: RiceConstants.ALLOWED_EMPLOYEE_STATUS_RULE,
080: getUniversalUser()
081: .getEmployeeStatusCode());
082: }
083:
084: public void setActive(boolean active) {
085: if (KNSServiceLocator.getKualiModuleService().getModule(
086: moduleId).getModuleUserService().getPropertyList()
087: .contains(RicePropertyConstants.ACTIVE)) {
088: setUserProperty(RicePropertyConstants.ACTIVE, active ? "Y"
089: : "N");
090: }
091: }
092:
093: public String getPersonUniversalIdentifier() {
094: return personUniversalIdentifier;
095: }
096:
097: /**
098: * Gets the universalUser attribute.
099: *
100: * @return Returns the universalUser.
101: */
102: public UniversalUser getUniversalUser() {
103: universalUser = KNSServiceLocator.getUniversalUserService()
104: .updateUniversalUserIfNecessary(
105: personUniversalIdentifier, universalUser);
106: return universalUser;
107: }
108:
109: public void setUniversalUser(UniversalUser universalUser) {
110: this .universalUser = universalUser;
111: if (universalUser != null) {
112: personUniversalIdentifier = universalUser
113: .getPersonUniversalIdentifier();
114: } else {
115: personUniversalIdentifier = null;
116: }
117: }
118:
119: public String getUserProperty(String propKey) {
120: if (propKey == null || universalUser == null)
121: return "";
122: String value = universalUser.getModuleProperties(getModuleId())
123: .get(propKey);
124: return value == null ? "" : value;
125: }
126:
127: public void setUserProperty(String propKey, String value) {
128: if (propKey == null || universalUser == null)
129: return;
130: if (value == null)
131: value = "";
132: universalUser.getModuleProperties(getModuleId()).put(propKey,
133: value);
134: }
135:
136: public Map<String, String> getUserProperties() {
137: if (universalUser == null)
138: return null;
139: return universalUser.getModuleProperties(getModuleId());
140: }
141:
142: /**
143: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
144: */
145: protected LinkedHashMap toStringMapper() {
146: LinkedHashMap m = new LinkedHashMap();
147:
148: m.put(RicePropertyConstants.PERSON_UNIVERSAL_IDENTIFIER,
149: getPersonUniversalIdentifier());
150:
151: return m;
152: }
153:
154: public String getModuleId() {
155: return moduleId;
156: }
157:
158: protected void setModuleId(String moduleId) {
159: this.moduleId = moduleId;
160: }
161:
162: }
|