/*
*
* Copyright (c) 2004 SourceTap - www.sourcetap.com
*
* The contents of this file are subject to the SourceTap Public License
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*/
package com.sourcetap.sfa.lead;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.ofbiz.base.util.Debug;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.GenericPK;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.condition.EntityExpr;
import org.ofbiz.entity.condition.EntityOperator;
import com.sourcetap.sfa.security.SecurityLinkInfo;
import com.sourcetap.sfa.security.SecurityWrapper;
import com.sourcetap.sfa.ui.UIDropDown;
import com.sourcetap.sfa.util.UserInfo;
/**
* DOCUMENT ME!
*
*/
public class LeadQueueUserAvailableSelect extends UIDropDown {
public static final String module = LeadQueueUserAvailableSelect.class.getName();
public LeadQueueUserAvailableSelect() {
}
/**
* DOCUMENT ME!
*
* @param delegator
* @param filterValues
* @param userInfo
*
* @return
*/
public List getDropDownValues(GenericDelegator delegator, Map filterValues,
UserInfo userInfo) {
// See if the account ID was passed in the parameter map. If so, use that account ID. Otherwise, use the
// account ID from the leadQueue.
String accountId = "";
if (filterValues.containsKey("accountId")) {
accountId = (String) filterValues.get("accountId");
} else {
if (!filterValues.containsKey("leadQueueId")) {
Debug.logError(
"[LeadQueueUserAvailableSelect.getDropDownValues] Neither account ID nor leadQueue ID are included in the query parameters. Can't get eligible users.", module);
return new ArrayList();
}
// Get the account ID for this leadQueue.
String leadQueueId = (String) filterValues.get("leadQueueId");
GenericPK leadQueuePK = new GenericPK(delegator.getModelEntity(
"LeadQueue"));
leadQueuePK.set("leadQueueId", leadQueueId);
GenericValue leadQueueGV = null;
try {
leadQueueGV = delegator.findByPrimaryKey(leadQueuePK);
} catch (GenericEntityException e) {
Debug.logError(
"[LeadQueueUserAvailableSelect.getDropDownValues] Error retrieving the leadQueue: ", module);
Debug.logError(e.getLocalizedMessage(), module);
return new ArrayList();
}
accountId = (leadQueueGV.getString("accountId") == null) ? ""
: leadQueueGV.getString(
"accountId");
}
// Get a list of all eligible users.
ArrayList orderBy = new ArrayList();
orderBy.add("lastName");
orderBy.add("firstName");
EntityExpr condition = null;
if ((accountId != null) && (accountId.length() > 0) &&
(!accountId.equals("null"))) {
condition = new EntityExpr("accountId", EntityOperator.EQUALS, accountId);
}
try {
return SecurityWrapper.findByCondition("Contact", condition,
orderBy, userInfo,
new SecurityLinkInfo("Account", "accountId", true), delegator);
} catch (GenericEntityException e) {
Debug.logError(
"[LeadQueueUserAvailableSelect.getDropDownValues] Error retrieving the users: ", module);
Debug.logError(e.getLocalizedMessage(), module);
return new ArrayList();
}
}
}