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.lead;
018:
019: import java.util.ArrayList;
020: import java.util.List;
021: import java.util.Map;
022:
023: import org.ofbiz.base.util.Debug;
024: import org.ofbiz.entity.GenericDelegator;
025: import org.ofbiz.entity.GenericEntityException;
026: import org.ofbiz.entity.GenericPK;
027: import org.ofbiz.entity.GenericValue;
028: import org.ofbiz.entity.condition.EntityExpr;
029: import org.ofbiz.entity.condition.EntityOperator;
030:
031: import com.sourcetap.sfa.security.SecurityLinkInfo;
032: import com.sourcetap.sfa.security.SecurityWrapper;
033: import com.sourcetap.sfa.ui.UIDropDown;
034: import com.sourcetap.sfa.util.UserInfo;
035:
036: /**
037: * DOCUMENT ME!
038: *
039: */
040: public class LeadQueueUserAvailableSelect extends UIDropDown {
041: public static final String module = LeadQueueUserAvailableSelect.class
042: .getName();
043:
044: public LeadQueueUserAvailableSelect() {
045: }
046:
047: /**
048: * DOCUMENT ME!
049: *
050: * @param delegator
051: * @param filterValues
052: * @param userInfo
053: *
054: * @return
055: */
056: public List getDropDownValues(GenericDelegator delegator,
057: Map filterValues, UserInfo userInfo) {
058: // See if the account ID was passed in the parameter map. If so, use that account ID. Otherwise, use the
059: // account ID from the leadQueue.
060: String accountId = "";
061:
062: if (filterValues.containsKey("accountId")) {
063: accountId = (String) filterValues.get("accountId");
064:
065: } else {
066: if (!filterValues.containsKey("leadQueueId")) {
067: Debug
068: .logError(
069: "[LeadQueueUserAvailableSelect.getDropDownValues] Neither account ID nor leadQueue ID are included in the query parameters. Can't get eligible users.",
070: module);
071:
072: return new ArrayList();
073: }
074:
075: // Get the account ID for this leadQueue.
076: String leadQueueId = (String) filterValues
077: .get("leadQueueId");
078: GenericPK leadQueuePK = new GenericPK(delegator
079: .getModelEntity("LeadQueue"));
080: leadQueuePK.set("leadQueueId", leadQueueId);
081:
082: GenericValue leadQueueGV = null;
083:
084: try {
085: leadQueueGV = delegator.findByPrimaryKey(leadQueuePK);
086: } catch (GenericEntityException e) {
087: Debug
088: .logError(
089: "[LeadQueueUserAvailableSelect.getDropDownValues] Error retrieving the leadQueue: ",
090: module);
091: Debug.logError(e.getLocalizedMessage(), module);
092:
093: return new ArrayList();
094: }
095:
096: accountId = (leadQueueGV.getString("accountId") == null) ? ""
097: : leadQueueGV.getString("accountId");
098:
099: }
100:
101: // Get a list of all eligible users.
102: ArrayList orderBy = new ArrayList();
103: orderBy.add("lastName");
104: orderBy.add("firstName");
105:
106: EntityExpr condition = null;
107:
108: if ((accountId != null) && (accountId.length() > 0)
109: && (!accountId.equals("null"))) {
110:
111: condition = new EntityExpr("accountId",
112: EntityOperator.EQUALS, accountId);
113:
114: }
115:
116: try {
117: return SecurityWrapper.findByCondition("Contact",
118: condition, orderBy, userInfo, new SecurityLinkInfo(
119: "Account", "accountId", true), delegator);
120: } catch (GenericEntityException e) {
121: Debug
122: .logError(
123: "[LeadQueueUserAvailableSelect.getDropDownValues] Error retrieving the users: ",
124: module);
125: Debug.logError(e.getLocalizedMessage(), module);
126:
127: return new ArrayList();
128: }
129: }
130: }
|