1 25 package org.ofbiz.pos.container; 26 27 import java.util.Locale ; 28 29 import org.ofbiz.base.container.ContainerConfig; 30 import org.ofbiz.base.container.ContainerException; 31 import org.ofbiz.base.util.UtilMisc; 32 import org.ofbiz.base.util.UtilValidate; 33 import org.ofbiz.guiapp.xui.XuiContainer; 34 import org.ofbiz.guiapp.xui.XuiSession; 35 import org.ofbiz.entity.GenericEntityException; 36 import org.ofbiz.entity.GenericValue; 37 import org.ofbiz.product.store.ProductStoreWorker; 38 39 45 public class PosContainer extends XuiContainer { 46 47 public String getContainerConfigName() { 48 return "pos-container"; 49 } 50 51 public void configure(ContainerConfig.Container cc) throws ContainerException { 52 XuiSession session = XuiContainer.getSession(); 53 GenericValue productStore = null; 54 GenericValue facility = null; 55 56 String facilityId = ContainerConfig.getPropertyValue(cc, "facility-id", null); 58 if (UtilValidate.isEmpty(facilityId)) { 59 throw new ContainerException("No facility-id value set in pos-container!"); 60 } else { 61 try { 62 facility = session.getDelegator().findByPrimaryKey("Facility", UtilMisc.toMap("facilityId", facilityId)); 63 } catch (GenericEntityException e) { 64 throw new ContainerException("Invalid facilityId : " + facilityId); 65 } 66 } 67 68 if (facility == null) { 70 throw new ContainerException("Invalid facility; facility ID not found [" + facilityId + "]"); 71 } 72 session.setAttribute("facilityId", facilityId); 73 session.setAttribute("facility", facility); 74 75 String productStoreId = facility.getString("productStoreId"); 77 if (UtilValidate.isEmpty(productStoreId)) { 78 throw new ContainerException("No productStoreId set on facility [" + facilityId + "]!"); 79 } else { 80 productStore = ProductStoreWorker.getProductStore(productStoreId, session.getDelegator()); 81 if (productStore == null) { 82 throw new ContainerException("Invalid productStoreId : " + productStoreId); 83 } 84 } 85 session.setAttribute("productStoreId", productStoreId); 86 session.setAttribute("productStore", productStore); 87 88 String localeStr = ContainerConfig.getPropertyValue(cc, "locale", null); 90 if (UtilValidate.isEmpty(localeStr)) { 91 localeStr = productStore.getString("defaultLocaleString"); 92 } 93 if (UtilValidate.isEmpty(localeStr)) { 94 throw new ContainerException("Invalid Locale for POS!"); 95 } 96 Locale locale = UtilMisc.parseLocale(localeStr); 97 session.setAttribute("locale", locale); 98 99 String currencyStr = ContainerConfig.getPropertyValue(cc, "currency", null); 101 if (UtilValidate.isEmpty(currencyStr)) { 102 currencyStr = productStore.getString("defaultCurrencyUomId"); 103 } 104 if (UtilValidate.isEmpty(currencyStr)) { 105 throw new ContainerException("Invalid Currency for POS!"); 106 } 107 session.setAttribute("currency", currencyStr); 108 } 109 } 110 | Popular Tags |