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