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.opportunity;
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 OpportunityContactAvailableSelect extends UIDropDown {
042: public static final String module = OpportunityContactAvailableSelect.class
043: .getName();
044:
045: public OpportunityContactAvailableSelect() {
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 opportunity.
061: String accountId = "";
062:
063: if (filterValues.containsKey("accountId")) {
064: accountId = (String) filterValues.get("accountId");
065:
066: } else {
067: if (!filterValues.containsKey("dealId")) {
068: Debug
069: .logError(
070: "[OpportunityContactAvailableSelect.getDropDownValues] Neither account ID nor deal ID are included in the query parameters. Can't get eligible contacts.",
071: module);
072:
073: return new ArrayList();
074: }
075:
076: // Get the account ID for this opportunity.
077: String dealId = (String) filterValues.get("dealId");
078: GenericPK dealPK = new GenericPK(delegator
079: .getModelEntity("Deal"));
080: dealPK.set("dealId", dealId);
081:
082: GenericValue dealGV = null;
083:
084: try {
085: dealGV = delegator.findByPrimaryKey(dealPK);
086: } catch (GenericEntityException e) {
087: Debug
088: .logError(
089: "[OpportunityContactAvailableSelect.getDropDownValues] Error retrieving the opportunity: ",
090: module);
091: Debug.logError(e.getLocalizedMessage(), module);
092:
093: return new ArrayList();
094: }
095:
096: accountId = (dealGV.getString("accountId") == null) ? ""
097: : dealGV.getString("accountId");
098:
099: }
100:
101: // Get a list of all eligible contacts.
102: ArrayList orderBy = new ArrayList();
103: orderBy.add("lastName");
104: orderBy.add("firstName");
105:
106: EntityCondition condition = null;
107:
108: if ((accountId != null) && (accountId.length() > 0)
109: && (!accountId.equals("null"))) {
110: condition = new EntityExpr("accountId",
111: EntityOperator.EQUALS, accountId);
112: }
113:
114: try {
115: return SecurityWrapper.findByCondition("Contact",
116: condition, orderBy, userInfo, new SecurityLinkInfo(
117: "Account", "accountId", true), delegator);
118: } catch (GenericEntityException e) {
119: Debug
120: .logError(
121: "[OpportunityContactAvailableSelect.getDropDownValues] Error retrieving the contacts: ",
122: module);
123: Debug.logError(e.getLocalizedMessage(), module);
124:
125: return new ArrayList();
126: }
127: }
128: }
|