001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.pos.container;
019:
020: import java.util.Locale;
021:
022: import org.ofbiz.base.container.ContainerConfig;
023: import org.ofbiz.base.container.ContainerException;
024: import org.ofbiz.base.util.UtilMisc;
025: import org.ofbiz.base.util.UtilValidate;
026: import org.ofbiz.guiapp.xui.XuiContainer;
027: import org.ofbiz.guiapp.xui.XuiSession;
028: import org.ofbiz.entity.GenericEntityException;
029: import org.ofbiz.entity.GenericValue;
030: import org.ofbiz.product.store.ProductStoreWorker;
031:
032: public class PosContainer extends XuiContainer {
033:
034: public String getContainerConfigName() {
035: return "pos-container";
036: }
037:
038: public void configure(ContainerConfig.Container cc)
039: throws ContainerException {
040: XuiSession session = XuiContainer.getSession();
041: GenericValue productStore = null;
042: GenericValue facility = null;
043:
044: // get the facility id
045: String facilityId = ContainerConfig.getPropertyValue(cc,
046: "facility-id", null);
047: if (UtilValidate.isEmpty(facilityId)) {
048: throw new ContainerException(
049: "No facility-id value set in pos-container!");
050: } else {
051: try {
052: facility = session.getDelegator().findByPrimaryKey(
053: "Facility",
054: UtilMisc.toMap("facilityId", facilityId));
055: } catch (GenericEntityException e) {
056: throw new ContainerException("Invalid facilityId : "
057: + facilityId);
058: }
059: }
060:
061: // verify the facility exists
062: if (facility == null) {
063: throw new ContainerException(
064: "Invalid facility; facility ID not found ["
065: + facilityId + "]");
066: }
067: session.setAttribute("facilityId", facilityId);
068: session.setAttribute("facility", facility);
069:
070: // get the product store id
071: String productStoreId = facility.getString("productStoreId");
072: if (UtilValidate.isEmpty(productStoreId)) {
073: throw new ContainerException(
074: "No productStoreId set on facility [" + facilityId
075: + "]!");
076: } else {
077: productStore = ProductStoreWorker.getProductStore(
078: productStoreId, session.getDelegator());
079: if (productStore == null) {
080: throw new ContainerException(
081: "Invalid productStoreId : " + productStoreId);
082: }
083: }
084: session.setAttribute("productStoreId", productStoreId);
085: session.setAttribute("productStore", productStore);
086:
087: // get the store locale
088: String localeStr = ContainerConfig.getPropertyValue(cc,
089: "locale", null);
090: if (UtilValidate.isEmpty(localeStr)) {
091: localeStr = productStore.getString("defaultLocaleString");
092: }
093: if (UtilValidate.isEmpty(localeStr)) {
094: throw new ContainerException("Invalid Locale for POS!");
095: }
096: Locale locale = UtilMisc.parseLocale(localeStr);
097: session.setAttribute("locale", locale);
098:
099: // get the store currency
100: String currencyStr = ContainerConfig.getPropertyValue(cc,
101: "currency", null);
102: if (UtilValidate.isEmpty(currencyStr)) {
103: currencyStr = productStore
104: .getString("defaultCurrencyUomId");
105: }
106: if (UtilValidate.isEmpty(currencyStr)) {
107: throw new ContainerException("Invalid Currency for POS!");
108: }
109: session.setAttribute("currency", currencyStr);
110: }
111: }
|