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.dao.ojb;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.apache.commons.lang.StringUtils;
022: import org.apache.ojb.broker.query.Criteria;
023: import org.apache.ojb.broker.query.QueryByCriteria;
024: import org.apache.ojb.broker.query.QueryFactory;
025: import org.kuali.core.bo.user.UniversalUser;
026: import org.kuali.core.dao.UniversalUserDao;
027: import org.kuali.core.exceptions.UserNotFoundException;
028: import org.kuali.core.lookup.LookupUtils;
029:
030: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
031: import edu.iu.uis.eden.user.WorkflowUser;
032: import edu.iu.uis.eden.user.WorkflowUserId;
033:
034: /**
035: * This class is the OJB implementation of the UniversalUserDao interface.
036: *
037: *
038: */
039: public class UniversalUserDaoOjb extends PlatformAwareDaoBaseOjb
040: implements UniversalUserDao {
041: public UniversalUser getUser(org.kuali.core.bo.user.UserId userId)
042: throws UserNotFoundException {
043: UniversalUser user = null;
044:
045: Criteria criteria = new Criteria();
046: if (userId instanceof org.kuali.core.bo.user.AuthenticationUserId) {
047: criteria
048: .addEqualTo(
049: "personUserIdentifier",
050: StringUtils
051: .upperCase(((org.kuali.core.bo.user.AuthenticationUserId) userId)
052: .getAuthenticationId()));
053: }
054: if (userId instanceof org.kuali.core.bo.user.PersonPayrollId) {
055: criteria.addEqualTo("personPayrollIdentifier",
056: ((org.kuali.core.bo.user.PersonPayrollId) userId)
057: .getPayrollId());
058: }
059: if (userId instanceof org.kuali.core.bo.user.UuId) {
060: criteria.addEqualTo("personUniversalIdentifier",
061: ((org.kuali.core.bo.user.UuId) userId).getUuId());
062: }
063: if (userId instanceof org.kuali.core.bo.user.PersonTaxId) {
064: criteria.addEqualTo("personTaxIdentifier",
065: ((org.kuali.core.bo.user.PersonTaxId) userId)
066: .getTaxId());
067: }
068: return (UniversalUser) getPersistenceBrokerTemplate()
069: .getObjectByQuery(
070: QueryFactory.newQuery(UniversalUser.class,
071: criteria));
072: }
073:
074: public WorkflowUser getWorkflowUser(
075: edu.iu.uis.eden.user.UserId userId)
076: throws EdenUserNotFoundException {
077: if ((userId == null) || userId.isEmpty()) {
078: throw new EdenUserNotFoundException(
079: "Attempting to lookup user with null or empty id");
080: }
081: Criteria criteria = new Criteria();
082: if (userId instanceof edu.iu.uis.eden.user.AuthenticationUserId) {
083: criteria
084: .addEqualTo(
085: "authenticationUserId",
086: ((edu.iu.uis.eden.user.AuthenticationUserId) userId)
087: .getAuthenticationId().trim()
088: .toUpperCase());
089: }
090: if (userId instanceof edu.iu.uis.eden.user.EmplId) {
091: criteria.addEqualTo("emplId",
092: ((edu.iu.uis.eden.user.EmplId) userId).getEmplId()
093: .trim().toUpperCase());
094: }
095: if (userId instanceof WorkflowUserId) {
096: criteria.addEqualTo("uuId", ((WorkflowUserId) userId)
097: .getWorkflowId().trim().toUpperCase());
098: }
099: if (userId instanceof edu.iu.uis.eden.user.UuId) {
100: criteria.addEqualTo("uuId",
101: ((edu.iu.uis.eden.user.UuId) userId).getUuId()
102: .trim().toUpperCase());
103: }
104: WorkflowUser user = (WorkflowUser) getPersistenceBrokerTemplate()
105: .getObjectByQuery(
106: new QueryByCriteria(
107: org.kuali.core.workflow.bo.WorkflowUser.class,
108: criteria));
109: if (user == null) {
110: throw new EdenUserNotFoundException(new StringBuffer(
111: "Unable to locate user with ").append(
112: userId.getClass().getName()).append(": ").append(
113: userId.getId()).toString());
114: }
115: return user;
116: }
117:
118: public void save(WorkflowUser workflowUser) {
119: getPersistenceBrokerTemplate().store(workflowUser);
120: }
121:
122: public List search(WorkflowUser user, boolean useWildCards) {
123: Criteria criteria = new Criteria();
124: if (user != null) {
125: if ((user.getAuthenticationUserId() != null)
126: && StringUtils.isNotBlank(user
127: .getAuthenticationUserId()
128: .getAuthenticationId())) {
129: criteria.addLike("authenticationUserId", user
130: .getAuthenticationUserId()
131: .getAuthenticationId().trim().toUpperCase()
132: + "%");
133: }
134: if ((user.getEmplId() != null)
135: && StringUtils.isNotBlank(user.getEmplId()
136: .getEmplId())) {
137: criteria.addLike("emplId", user.getEmplId().getEmplId()
138: .trim().toUpperCase()
139: + "%");
140: }
141: if ((user.getUuId() != null)
142: && StringUtils.isNotBlank(user.getUuId().getUuId())) {
143: criteria.addLike("uuId", user.getUuId().getUuId()
144: .trim().toUpperCase()
145: + "%");
146: }
147: if ((user.getWorkflowUserId() != null)
148: && StringUtils.isNotBlank(user.getWorkflowUserId()
149: .getWorkflowId())) {
150: criteria.addLike("workflowUserId", user
151: .getWorkflowUserId().getWorkflowId().trim()
152: .toUpperCase()
153: + "%");
154: }
155: if (StringUtils.isNotBlank(user.getGivenName())) {
156: criteria.addLike("givenName", user.getGivenName()
157: .trim().toUpperCase()
158: + "%");
159: }
160: if (StringUtils.isNotBlank(user.getLastName())) {
161: criteria.addLike("lastName", user.getLastName().trim()
162: .toUpperCase()
163: + "%");
164: }
165: if (StringUtils.isNotBlank(user.getDisplayName())) {
166: criteria.addLike("displayName", user.getDisplayName()
167: .trim().toUpperCase().trim()
168: + "%");
169: }
170: if (StringUtils.isNotBlank(user.getEmailAddress())) {
171: criteria.addLike("emailAddress", user.getEmailAddress()
172: .trim()
173: + "%");
174: }
175: }
176: LookupUtils.applySearchResultsLimit(criteria, getDbPlatform());
177: return new ArrayList(
178: getPersistenceBrokerTemplate()
179: .getCollectionByQuery(
180: new QueryByCriteria(
181: org.kuali.core.workflow.bo.WorkflowUser.class,
182: criteria)));
183: }
184:
185: }
|