001: /*
002: *
003: * Copyright (c) 2004 SourceTap - www.sourcetap.com
004: *
005: * The contents of this file are subject to the SourceTap Public License
006: * ("License"); You may not use this file except in compliance with the
007: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008: * Software distributed under the License is distributed on an "AS IS" basis,
009: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010: * the specific language governing rights and limitations under the License.
011: *
012: * The above copyright notice and this permission notice shall be included
013: * in all copies or substantial portions of the Software.
014: *
015: */
016:
017: package com.sourcetap.sfa.util;
018:
019: import java.util.List;
020:
021: import org.ofbiz.base.util.Debug;
022: import org.ofbiz.base.util.UtilFormatOut;
023: import org.ofbiz.base.util.UtilMisc;
024: import org.ofbiz.entity.GenericDelegator;
025: import org.ofbiz.entity.GenericEntityException;
026: import org.ofbiz.entity.GenericValue;
027:
028: /**
029: * DOCUMENT ME!
030: *
031: */
032: public class UserInfo {
033: public static final String module = UserInfo.class.getName();
034: String partyId;
035: String roleId;
036: String userName;
037: String userFullName;
038: String accountId;
039:
040: public UserInfo() {
041: partyId = null;
042: roleId = null;
043: userName = null;
044: accountId = null;
045: }
046:
047: public UserInfo(GenericDelegator delegator, String userId,
048: String accountId) {
049: try {
050: GenericValue contactGV = delegator.findByPrimaryKey(
051: "Contact", UtilMisc.toMap("contactId", userId));
052: if (contactGV == null)
053: throw new IllegalArgumentException("Invalid User ID");
054: if (!accountId.equals(contactGV.getString("accountId")))
055: throw new IllegalArgumentException(
056: "Account ID does not match User Info");
057:
058: List loginInfo = delegator.findByAnd("UserLogin", UtilMisc
059: .toMap("partyId", userId), null);
060: if ((loginInfo == null) || (loginInfo.size() < 1))
061: throw new IllegalArgumentException(
062: "Invalid User Login Info");
063:
064: GenericValue loginGV = (GenericValue) loginInfo.get(0);
065:
066: String userName = loginGV.getString("userLoginId");
067: String contactName = "";
068: String roleId = UtilFormatOut.checkNull(contactGV
069: .getString("roleId"));
070:
071: String firstName = (contactGV.getString("firstName") == null) ? ""
072: : contactGV.getString("firstName");
073: String lastName = (contactGV.getString("lastName") == null) ? ""
074: : contactGV.getString("lastName");
075:
076: if (((firstName != null) && !firstName.equals(""))
077: || ((lastName != null) && !lastName.equals(""))) {
078: contactName = firstName + " " + lastName;
079: } else {
080: contactName = userName;
081: }
082:
083: init(userId, roleId, userName, contactName, accountId);
084:
085: } catch (GenericEntityException e) {
086: Debug.logError("Error loading UserInfo information"
087: + e.getMessage(), module);
088: throw new IllegalArgumentException(
089: "Unable to load User Info");
090: }
091:
092: }
093:
094: public UserInfo(String partyId, String roleId, String userName,
095: String userFullName, String accountId) {
096: init(partyId, roleId, userName, userFullName, accountId);
097: }
098:
099: public void init(String partyId, String roleId, String userName,
100: String userFullName, String accountId) {
101: setPartyId(partyId);
102: setRoleId(roleId);
103: setUserName(userName);
104: setUserFullName(userFullName);
105: setAccountId(accountId);
106: }
107:
108: /**
109: * DOCUMENT ME!
110: *
111: * @return
112: */
113: public String getPartyId() {
114: return partyId;
115: }
116:
117: /**
118: * DOCUMENT ME!
119: *
120: * @return
121: */
122: public String getRoleId() {
123: return roleId;
124: }
125:
126: /**
127: * DOCUMENT ME!
128: *
129: * @return
130: */
131: public String getUserName() {
132: return userName;
133: }
134:
135: /**
136: * DOCUMENT ME!
137: *
138: * @return
139: */
140: public String getUserFullName() {
141: return userFullName;
142: }
143:
144: /**
145: * DOCUMENT ME!
146: *
147: * @return
148: */
149: public String getAccountId() {
150: return accountId;
151: }
152:
153: /**
154: * DOCUMENT ME!
155: *
156: * @param partyId_
157: */
158: public void setPartyId(String partyId_) {
159: partyId = partyId_;
160: }
161:
162: /**
163: * DOCUMENT ME!
164: *
165: * @param roleId_
166: */
167: public void setRoleId(String roleId_) {
168: roleId = roleId_;
169: }
170:
171: /**
172: * DOCUMENT ME!
173: *
174: * @param userName_
175: */
176: public void setUserName(String userName_) {
177: userName = userName_;
178: }
179:
180: /**
181: * DOCUMENT ME!
182: *
183: * @param userFullName_
184: */
185: public void setUserFullName(String userFullName_) {
186: userFullName = userFullName_;
187: }
188:
189: /**
190: * DOCUMENT ME!
191: *
192: * @param accountId_
193: */
194: public void setAccountId(String accountId_) {
195: accountId = accountId_;
196: }
197:
198: /**
199: * DOCUMENT ME!
200: *
201: * @return
202: */
203: public String toString() {
204: return "[partyId]" + partyId + "[roleId]" + roleId
205: + "[userName]" + userName + "[accountId]" + accountId;
206: }
207: }
|