1 17 package com.opensourcestrategies.crmsfa.party; 18 19 import java.util.Iterator ; 20 import java.util.List ; 21 import java.util.Map ; 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 45 public class ViewPrefWorker { 46 47 public static String module = ViewPrefWorker.class.getName(); 48 49 50 public static Map getViewPreferencesByLocation(GenericValue userLogin, String application, String applicationSection, String screenName, String formName) 51 throws GenericEntityException { 52 Map conditions = UtilMisc.toMap("userLoginId", userLogin.get("userLoginId"), "application", application, "applicationSection", applicationSection, "screenName", screenName, "formName", formName); 53 List prefs = userLogin.getDelegator().findByAnd("ViewPrefAndLocation", conditions); 54 Map results = FastMap.newInstance(); 55 for (Iterator 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 67 public static Map getViewPreferencesByLocation(GenericValue userLogin, String application, String applicationSection) throws GenericEntityException { 68 return getViewPreferencesByLocation(userLogin, application, applicationSection, null, null); 69 } 70 71 72 public static String getViewPreferenceString(GenericValue userLogin, String 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 80 public static GenericValue getViewPreferenceValue(GenericValue userLogin, String 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 |