01: /*
02: *
03: * Copyright (c) 2004 SourceTap - www.sourcetap.com
04: *
05: * The contents of this file are subject to the SourceTap Public License
06: * ("License"); You may not use this file except in compliance with the
07: * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
10: * the specific language governing rights and limitations under the License.
11: *
12: * The above copyright notice and this permission notice shall be included
13: * in all copies or substantial portions of the Software.
14: *
15: */
16:
17: package com.sourcetap.sfa.ui;
18:
19: import java.util.ArrayList;
20: import java.util.LinkedList;
21: import java.util.List;
22:
23: import org.ofbiz.base.util.Debug;
24: import org.ofbiz.base.util.UtilMisc;
25: import org.ofbiz.entity.GenericDelegator;
26: import org.ofbiz.entity.GenericEntityException;
27: import org.ofbiz.entity.condition.EntityCondition;
28: import org.ofbiz.entity.condition.EntityConditionList;
29: import org.ofbiz.entity.condition.EntityExpr;
30: import org.ofbiz.entity.condition.EntityOperator;
31:
32: import com.sourcetap.sfa.security.SecurityLinkInfo;
33: import com.sourcetap.sfa.security.SecurityWrapper;
34: import com.sourcetap.sfa.util.UserInfo;
35:
36: /** Return list of accounts accessible by the specified user
37: */
38: public class UIAccountSearchField extends UISearchField {
39: public static final String module = UIAccountSearchField.class
40: .getName();
41:
42: /**
43: * Dynamically retrieves accounts to display as a drop down list when the search field is in list mode.
44: * Accounts are filtered so only accounts in the user's company are shown. In addition, the current system
45: * filtering preferences are applied to filter accounts so they can be viewed only by people on the
46: * account team, or in the same territory as the account's owner.
47: *
48: * @author <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
49: * @author <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
50: *
51: * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
52: * @param entityName The name of the entity whose instances are to be displayed in the list.
53: * @param searchField Name of attribute in the listed entity to be compared to the searchValue
54: * @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.
55: * @param userInfo Reference to user info object containing information about the currently logged-in user
56: *
57: * @return String containing the HTML text that will draw the current field on the web page
58: *
59: * @see com.sourcetap.sfa.ui.UIWebScreenSection
60: */
61: public List getSearchFieldValuesDynamic(GenericDelegator delegator,
62: String entityName, String searchField, String searchValue,
63: UserInfo userInfo) {
64:
65: ArrayList orderBy = new ArrayList();
66: orderBy.add("accountName");
67:
68: EntityCondition condition = new EntityConditionList(UtilMisc
69: .toList(new EntityExpr("accountTypeId",
70: EntityOperator.NOT_EQUAL, "base"),
71: new EntityExpr(searchField,
72: EntityOperator.LIKE, searchValue)),
73: EntityOperator.AND);
74:
75: try {
76: return SecurityWrapper.findByCondition("Account",
77: condition, orderBy, userInfo, new SecurityLinkInfo(
78: "Account", "accountId", true), delegator);
79: } catch (GenericEntityException e) {
80: Debug
81: .logError(
82: "[UIAccountSearchField.getSearchFieldValues] Error retrieving the search field values: ",
83: module);
84: Debug.logError(e.getLocalizedMessage(), module);
85:
86: return new LinkedList();
87: }
88: }
89: }
|