1 25 package org.ofbiz.common; 26 27 import java.util.ArrayList ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import javolution.util.FastList; 32 33 import org.ofbiz.base.util.Debug; 34 import org.ofbiz.base.util.UtilMisc; 35 import org.ofbiz.base.util.UtilProperties; 36 import org.ofbiz.entity.GenericDelegator; 37 import org.ofbiz.entity.GenericEntityException; 38 import org.ofbiz.entity.GenericValue; 39 import org.ofbiz.entity.condition.EntityCondition; 40 import org.ofbiz.entity.condition.EntityConditionList; 41 import org.ofbiz.entity.condition.EntityExpr; 42 import org.ofbiz.entity.condition.EntityOperator; 43 44 52 public class CommonWorkers { 53 54 public final static String module = CommonWorkers.class.getName(); 55 56 public static List getCountryList(GenericDelegator delegator) { 57 List geoList = FastList.newInstance(); 58 String defaultCountry = UtilProperties.getPropertyValue("general.properties", "country.geo.id.default"); 59 GenericValue defaultGeo = null; 60 if (defaultCountry != null && defaultCountry.length() > 0) { 61 try { 62 defaultGeo = delegator.findByPrimaryKeyCache("Geo", UtilMisc.toMap("geoId", defaultCountry)); 63 } catch (GenericEntityException e) { 64 Debug.logError(e, "Cannot lookup Geo", module); 65 } 66 } 67 try { 68 List countryGeoList = delegator.findByAndCache("Geo", UtilMisc.toMap("geoTypeId", "COUNTRY"), UtilMisc.toList("geoName")); 69 if (defaultGeo != null) { 70 geoList.add(defaultGeo); 71 geoList.addAll(countryGeoList); 72 } else { 73 geoList = countryGeoList; 74 } 75 } catch (GenericEntityException e) { 76 Debug.logError(e, "Cannot lookup Geo", module); 77 } 78 return geoList; 79 } 80 81 public static List getStateList(GenericDelegator delegator) { 82 List geoList = new ArrayList (); 83 EntityCondition condition = new EntityConditionList(UtilMisc.toList( 84 new EntityExpr("geoTypeId", EntityOperator.EQUALS, "STATE"), new EntityExpr("geoTypeId", EntityOperator.EQUALS, "PROVINCE")), EntityOperator.OR); 85 List sortList = UtilMisc.toList("geoName"); 86 try { 87 geoList = delegator.findByConditionCache("Geo", condition, null, sortList); 88 } catch (GenericEntityException e) { 89 Debug.logError(e, "Cannot lookup State Geos: " + e.toString(), module); 90 } 91 return geoList; 92 } 93 94 97 public static List getAssociatedStateList(GenericDelegator delegator, String country) { 98 if ( country == null || country.length() == 0 ) { 99 country = UtilProperties.getPropertyValue("general.properties", "country.geo.id.default"); 101 } 102 List geoList = new ArrayList (); 103 Map geoAssocFindMap = UtilMisc.toMap("geoId", country, "geoAssocTypeId", "REGIONS"); 104 List sortList = UtilMisc.toList("geoIdTo"); 105 try { 106 geoList = delegator.findByAndCache("GeoAssoc", geoAssocFindMap, sortList); 107 } catch (GenericEntityException e) { 108 Debug.logError(e, "Cannot lookup Geo", module); 109 } 110 return geoList; 111 112 } 113 } 114 | Popular Tags |