KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensourcestrategies > crmsfa > party > ViewPrefWorker


1 /*
2  *
3  * Copyright (c) 2006 - 2007 Open Source Strategies, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Honest Public License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * Honest Public License for more details.
12  *
13  * You should have received a copy of the Honest Public License
14  * along with this program; if not, write to Funambol,
15  * 643 Bair Island Road, Suite 305 - Redwood City, CA 94063, USA
16  */

17 package com.opensourcestrategies.crmsfa.party;
18
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Map JavaDoc;
22
23 import javolution.util.FastMap;
24 import javolution.util.FastList;
25
26 import org.ofbiz.base.util.Debug;
27 import org.ofbiz.base.util.UtilMisc;
28 import org.ofbiz.base.util.UtilDateTime;
29 import org.ofbiz.entity.GenericDelegator;
30 import org.ofbiz.entity.GenericEntityException;
31 import org.ofbiz.entity.GenericValue;
32 import org.ofbiz.entity.condition.*;
33 import org.ofbiz.entity.util.EntityUtil;
34 import org.ofbiz.service.GenericServiceException;
35 import org.ofbiz.service.LocalDispatcher;
36 import org.ofbiz.service.ServiceUtil;
37
38 /**
39  * ViewPreference helper methods
40  *
41  * @author <a HREF="mailto:leon@opensourcestrategies.org">Leon Torres</a>
42  * @version $Rev: $
43  * @since 3.1
44  */

45 public class ViewPrefWorker {
46     
47     public static String JavaDoc module = ViewPrefWorker.class.getName();
48
49     /** Gets the view preferences as a Map of String values keyed to the preference type for the given location. */
50     public static Map JavaDoc getViewPreferencesByLocation(GenericValue userLogin, String JavaDoc application, String JavaDoc applicationSection, String JavaDoc screenName, String JavaDoc formName)
51         throws GenericEntityException {
52         Map JavaDoc conditions = UtilMisc.toMap("userLoginId", userLogin.get("userLoginId"), "application", application, "applicationSection", applicationSection, "screenName", screenName, "formName", formName);
53         List JavaDoc prefs = userLogin.getDelegator().findByAnd("ViewPrefAndLocation", conditions);
54         Map JavaDoc results = FastMap.newInstance();
55         for (Iterator JavaDoc iter = prefs.iterator(); iter.hasNext(); ) {
56             GenericValue pref = (GenericValue) iter.next();
57             if ("VPREF_VALTYPE_ENUM".equals(pref.get("viewPrefValueTypeId"))) {
58                 results.put(pref.get("viewPrefTypeId"), pref.get("viewPrefEnumId"));
59             } else {
60                 results.put(pref.get("viewPrefTypeId"), pref.get("viewPrefString"));
61             }
62         }
63         return results;
64     }
65
66     /** As above, but for application and section */
67     public static Map JavaDoc getViewPreferencesByLocation(GenericValue userLogin, String JavaDoc application, String JavaDoc applicationSection) throws GenericEntityException {
68         return getViewPreferencesByLocation(userLogin, application, applicationSection, null, null);
69     }
70
71     /** Gets the value of the preference as a String. Speficy the userLogin and viewPrefTypeId. */
72     public static String JavaDoc getViewPreferenceString(GenericValue userLogin, String JavaDoc viewPrefTypeId) throws GenericEntityException {
73         GenericValue pref = getViewPreferenceValue(userLogin, viewPrefTypeId);
74         if (pref == null) return null;
75         if ("VPREF_VALTYPE_ENUM".equals(pref.get("viewPrefValueTypeId"))) return pref.getString("viewPrefEnumId");
76         return pref.getString("viewPrefString");
77     }
78
79     /** Fetch the user login's active view preference as a GenericValue given a preference type. */
80     public static GenericValue getViewPreferenceValue(GenericValue userLogin, String JavaDoc viewPrefTypeId) throws GenericEntityException {
81         GenericDelegator delegator = userLogin.getDelegator();
82         return delegator.findByPrimaryKey("ViewPreference",
83                     UtilMisc.toMap("viewPrefTypeId", viewPrefTypeId, "userLoginId", userLogin.get("userLoginId")));
84     }
85 }
86
Popular Tags