/*
*
* 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.ui;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.entity.condition.EntityConditionList;
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.util.UserInfo;
/** Return list of accounts accessible by the specified user
*/
public class UIAccountSearchField extends UISearchField {
public static final String module = UIAccountSearchField.class.getName();
/**
* Dynamically retrieves accounts to display as a drop down list when the search field is in list mode.
* Accounts are filtered so only accounts in the user's company are shown. In addition, the current system
* filtering preferences are applied to filter accounts so they can be viewed only by people on the
* account team, or in the same territory as the account's owner.
*
* @author <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
* @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
*
* @param delegator Reference to the OFBIZ delegator being used to connect to the data base
* @param entityName The name of the entity whose instances are to be displayed in the list.
* @param searchField Name of attribute in the listed entity to be compared to the searchValue
* @param searchValue Value entered by the user into the search field. To be used in a LIKE clause to filter the items in the drop down.
* @param userInfo Reference to user info object containing information about the currently logged-in user
*
* @return String containing the HTML text that will draw the current field on the web page
*
* @see com.sourcetap.sfa.ui.UIWebScreenSection
*/
public List getSearchFieldValuesDynamic(GenericDelegator delegator,
String entityName, String searchField, String searchValue,
UserInfo userInfo) {
ArrayList orderBy = new ArrayList();
orderBy.add("accountName");
EntityCondition condition = new EntityConditionList( UtilMisc.toList(
new EntityExpr( "accountTypeId", EntityOperator.NOT_EQUAL, "base"),
new EntityExpr( searchField, EntityOperator.LIKE, searchValue)), EntityOperator.AND);
try {
return SecurityWrapper.findByCondition("Account", condition,
orderBy, userInfo,
new SecurityLinkInfo("Account", "accountId", true), delegator);
} catch (GenericEntityException e) {
Debug.logError(
"[UIAccountSearchField.getSearchFieldValues] Error retrieving the search field values: ", module);
Debug.logError(e.getLocalizedMessage(), module);
return new LinkedList();
}
}
}