From 60a92df74b0076ee3113384aa101467d91891486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20P=C3=B6ppke?= Date: Tue, 21 Jun 2016 20:22:45 +0200 Subject: [PATCH] Added new pages and implemented part of enterprise management --- .../cloud-web-frontend/pom.xml | 5 + .../cocome/cloud/web/events/LoginEvent.java | 12 +- .../inventory/connection/EnterpriseQuery.java | 149 ++++++++++++++++++ .../connection/IEnterpriseQuery.java | 36 +++++ .../web/inventory/connection/IStoreQuery.java | 21 +++ .../web/inventory/connection/StoreQuery.java | 88 +++++++++++ .../web/inventory/enterprise/Enterprise.java | 37 +++++ .../enterprise/EnterpriseConverter.java | 63 ++++++++ .../enterprise/EnterpriseInformation.java | 103 ++++++++++++ .../enterprise/IEnterpriseInformation.java | 28 ++++ .../inventory/store/IStoreInformation.java | 20 +++ .../web/inventory/store/ProductConverter.java | 68 ++++++++ .../web/inventory/store/ProductDetails.java | 28 ++++ .../web/inventory/store/ProductWrapper.java | 80 ++++++++++ .../cloud/web/inventory/store/Store.java | 44 ++++++ .../web/inventory/store/StoreInformation.java | 78 +++++++++ .../org/cocome/cloud/web/login/Login.java | 7 +- .../org/cocome/cloud/web/login/UserRole.java | 23 +++ .../cocome/frontend/Strings.properties | 10 ++ .../src/main/webapp/change_price.xhtml | 19 +++ .../src/main/webapp/create_enterprise.xhtml | 19 +++ .../src/main/webapp/create_product.xhtml | 19 +++ .../src/main/webapp/create_store.xhtml | 38 +++++ .../src/main/webapp/order_products.xhtml | 19 +++ .../src/main/webapp/receive_products.xhtml | 19 +++ .../{image/add-icon.png => icon/icon_add.png} | Bin .../icon/{icon_Shop.png => icon_shop.png} | Bin .../src/main/webapp/show_enterprises.xhtml | 45 ++++++ .../src/main/webapp/show_products.xhtml | 19 +++ .../src/main/webapp/show_reports.xhtml | 19 +++ .../src/main/webapp/show_stores.xhtml | 56 +++++++ .../src/main/webapp/start_sale.xhtml | 19 +++ .../webapp/templates/commonTemplate.xhtml | 20 +++ 33 files changed, 1207 insertions(+), 4 deletions(-) create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/EnterpriseQuery.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IEnterpriseQuery.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IStoreQuery.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/StoreQuery.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/Enterprise.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/EnterpriseConverter.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/EnterpriseInformation.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/IEnterpriseInformation.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/IStoreInformation.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductConverter.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductDetails.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductWrapper.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/Store.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/StoreInformation.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/login/UserRole.java create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/change_price.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/create_enterprise.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/create_product.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/create_store.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/order_products.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/receive_products.xhtml rename cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/{image/add-icon.png => icon/icon_add.png} (100%) rename cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/icon/{icon_Shop.png => icon_shop.png} (100%) create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/show_enterprises.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/show_products.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/show_reports.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/show_stores.xhtml create mode 100644 cocome-maven-project/cloud-web-frontend/src/main/webapp/start_sale.xhtml diff --git a/cocome-maven-project/cloud-web-frontend/pom.xml b/cocome-maven-project/cloud-web-frontend/pom.xml index d0c2f857..b2128d65 100644 --- a/cocome-maven-project/cloud-web-frontend/pom.xml +++ b/cocome-maven-project/cloud-web-frontend/pom.xml @@ -31,6 +31,11 @@ cloud-logic-core-services 1.1 + + org.cocome + cloud-registry-client + 1.1 + javax.faces jsf-impl diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/events/LoginEvent.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/events/LoginEvent.java index 5e5c80ef..29cf19f6 100644 --- a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/events/LoginEvent.java +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/events/LoginEvent.java @@ -9,10 +9,12 @@ public class LoginEvent { private IUser user; private UserRole role; + private long storeID; - public LoginEvent(@NotNull IUser user, @NotNull UserRole role) { + public LoginEvent(@NotNull IUser user, @NotNull UserRole role, long storeID) { this.user = user; this.role = role; + this.setStoreID(storeID); } public UserRole getRole() { @@ -34,5 +36,13 @@ public void setUser(@NotNull IUser user) { public NavigationViewStates getRequestedView() { return role.associatedView(); } + + public long getStoreID() { + return storeID; + } + + public void setStoreID(long storeID) { + this.storeID = storeID; + } } diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/EnterpriseQuery.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/EnterpriseQuery.java new file mode 100644 index 00000000..446ae43b --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/EnterpriseQuery.java @@ -0,0 +1,149 @@ +package org.cocome.cloud.web.inventory.connection; + +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; +import javax.xml.ws.WebServiceRef; + +import org.apache.log4j.Logger; +import org.cocome.cloud.logic.stub.IEnterpriseManager; +import org.cocome.cloud.logic.stub.IEnterpriseManagerService; +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; +import org.cocome.cloud.web.inventory.enterprise.Enterprise; +import org.cocome.cloud.web.inventory.store.ProductWrapper; +import org.cocome.cloud.web.inventory.store.Store; +import org.cocome.tradingsystem.inventory.application.store.EnterpriseTO; +import org.cocome.tradingsystem.inventory.application.store.ProductTO; +import org.cocome.tradingsystem.inventory.application.store.StoreWithEnterpriseTO; + +/** + * Implements the enterprise query interface to retrieve information + * from the backend about available enterprises and stores. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +@Named +@ApplicationScoped +public class EnterpriseQuery implements IEnterpriseQuery { + private static final Logger LOG = Logger.getLogger(EnterpriseQuery.class); + + private Map enterprises; + private Map> storeCollections; + private Map stores; + + @WebServiceRef(IEnterpriseManagerService.class) + IEnterpriseManager enterpriseManager; + + /* (non-Javadoc) + * @see org.cocome.cloud.shop.inventory.connection.IEnterpriseQuery#getEnterprises() + */ + @Override + public Collection getEnterprises() { + if(enterprises != null) { + return enterprises.values(); + } + + updateEnterpriseInformation(); + return enterprises.values(); + } + + /* (non-Javadoc) + * @see org.cocome.cloud.shop.inventory.connection.IEnterpriseQuery#getStores(long) + */ + @Override + public Collection getStores(long enterpriseID) throws NotInDatabaseException_Exception { + if(storeCollections == null) { + updateStoreInformation(); + } + + Collection storeCollection = storeCollections.get(enterpriseID); + return storeCollection != null ? storeCollection : new LinkedList(); + } + + @Override + public void updateEnterpriseInformation() { + this.enterprises = new HashMap(); + + for (EnterpriseTO enterprise : enterpriseManager.getEnterprises()) { + enterprises.put(enterprise.getId(), new Enterprise(enterprise.getId(), enterprise.getName())); + } + } + + @Override + public void updateStoreInformation() throws NotInDatabaseException_Exception { + if (this.enterprises == null) { + updateEnterpriseInformation(); + } + + // This collection has a fixed size depending on the number of enterprises, + // so we can set the initial capacity to this to avoid overhead + storeCollections = new HashMap>((int)(enterprises.size() / 0.75) + 1); + + this.stores = new HashMap(); + + for (Enterprise ent : enterprises.values()) { + LinkedList stores = new LinkedList(); + + for (StoreWithEnterpriseTO store : enterpriseManager.queryStoresByEnterpriseID(ent.getId())) { + Store tempStore = new Store(store.getId(), store.getLocation(), store.getName()); + this.stores.put(tempStore.getID(), tempStore); + stores.add(tempStore); + } + this.storeCollections.put(ent.getId(), stores); + } + } + + @Override + public Enterprise getEnterpriseByID(long enterpriseID) { + if (enterprises == null) { + updateEnterpriseInformation(); + } + + return enterprises.get(enterpriseID); + } + + @Override + public Store getStoreByID(long storeID) throws NotInDatabaseException_Exception { + LOG.debug("Retrieving store with id " + storeID); + + if (stores == null) { + updateStoreInformation(); + } + Store store = stores.get(storeID); + + if (store == null) { + throw new NotInDatabaseException_Exception("Store not found!"); + } + + LOG.debug("Got store " + store.getName()); + return store; + } + + public List getAllProducts() { + // TODO should definitely be cached somehow, especially when there are lots of products + List products = new LinkedList(); + for (ProductTO product : enterpriseManager.getAllProducts()) { + ProductWrapper wrapper = new ProductWrapper(product); + products.add(wrapper); + } + return products; + } + + @Override + public ProductWrapper getProductByID(long productID) throws NotInDatabaseException_Exception { + ProductWrapper product = new ProductWrapper(enterpriseManager.getProductByID(productID)); + return product; + } + + @Override + public ProductWrapper getProductByBarcode(long barcode) throws NotInDatabaseException_Exception { + ProductWrapper product = new ProductWrapper(enterpriseManager.getProductByBarcode(barcode)); + return product; + } +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IEnterpriseQuery.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IEnterpriseQuery.java new file mode 100644 index 00000000..a3dee6e5 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IEnterpriseQuery.java @@ -0,0 +1,36 @@ +package org.cocome.cloud.web.inventory.connection; + +import java.util.Collection; +import java.util.List; + +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; +import org.cocome.cloud.web.inventory.enterprise.Enterprise; +import org.cocome.cloud.web.inventory.store.ProductWrapper; +import org.cocome.cloud.web.inventory.store.Store; + +/** + * Interface for the retrieval of enterprise and store related information from the backend. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +public interface IEnterpriseQuery { + + public Collection getEnterprises(); + + public Collection getStores(long enterpriseID) throws NotInDatabaseException_Exception; + + public void updateEnterpriseInformation(); + + public void updateStoreInformation() throws NotInDatabaseException_Exception; + + public Enterprise getEnterpriseByID(long enterpriseID); + + public Store getStoreByID(long storeID) throws NotInDatabaseException_Exception; + + public List getAllProducts(); + + public ProductWrapper getProductByID(long productID) throws NotInDatabaseException_Exception; + + public ProductWrapper getProductByBarcode(long barcode) throws NotInDatabaseException_Exception; +} \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IStoreQuery.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IStoreQuery.java new file mode 100644 index 00000000..8cf06219 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IStoreQuery.java @@ -0,0 +1,21 @@ +package org.cocome.cloud.web.inventory.connection; + +import java.util.List; + +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; +import org.cocome.cloud.web.inventory.store.ProductWrapper; +import org.cocome.cloud.web.inventory.store.Store; + +/** + * Interface to retrieve stock items from a specific store and to account sales at that store. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +public interface IStoreQuery { + public List queryStockItems(Store store) throws NotInDatabaseException_Exception; + + public ProductWrapper getStockItemByProductID(Store store, long productID); + + public ProductWrapper getStockItemByBarcode(Store store, long barcode); +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/StoreQuery.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/StoreQuery.java new file mode 100644 index 00000000..5d8cc92d --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/StoreQuery.java @@ -0,0 +1,88 @@ +package org.cocome.cloud.web.inventory.connection; + +import java.lang.reflect.InvocationTargetException; +import java.net.MalformedURLException; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import org.apache.log4j.Logger; +import org.cocome.cloud.logic.registry.client.IApplicationHelper; +import org.cocome.cloud.logic.stub.IStoreManager; +import org.cocome.cloud.logic.stub.IStoreManagerService; +import org.cocome.cloud.logic.stub.NotBoundException_Exception; +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; +import org.cocome.cloud.logic.stub.ProductOutOfStockException_Exception; +import org.cocome.cloud.logic.stub.UpdateException_Exception; +import org.cocome.cloud.registry.service.Names; +import org.cocome.cloud.web.inventory.store.ProductWrapper; +import org.cocome.cloud.web.inventory.store.Store; +import org.cocome.tradingsystem.inventory.application.store.ProductWithStockItemTO; +import org.cocome.tradingsystem.inventory.application.store.ProductWithSupplierAndStockItemTO; +import org.cocome.tradingsystem.inventory.application.store.SaleTO; + +/** + * Implements the store query interface to retrieve store related information. + * Uses the web service interface from CoCoMEs logic. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +@RequestScoped +public class StoreQuery implements IStoreQuery { + private static final Logger LOG = Logger.getLogger(StoreQuery.class); + + IStoreManager storeManager; + + @Inject + long defaultStoreIndex; + + @Inject + IApplicationHelper applicationHelper; + + private IStoreManager lookupStoreManager(long storeID) throws NotInDatabaseException_Exception { + try { + return applicationHelper.getComponent( + Names.getStoreManagerRegistryName(storeID), + IStoreManagerService.SERVICE, + IStoreManagerService.class).getIStoreManagerPort(); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException + | MalformedURLException | NoSuchMethodException | SecurityException | NotBoundException_Exception e) { + if (storeID == defaultStoreIndex) { + LOG.error("Got exception while retrieving store manager location: " + e.getMessage()); + e.printStackTrace(); + throw new NotInDatabaseException_Exception(e.getMessage()); + } else { + return lookupStoreManager(defaultStoreIndex); + } + } + } + + @Override + public List queryStockItems(Store store) throws NotInDatabaseException_Exception { + long storeID = store.getID(); + storeManager = lookupStoreManager(storeID); + List stockItems = new LinkedList(); + List items = storeManager.getProductsWithStockItems(storeID); + for (ProductWithSupplierAndStockItemTO item : items) { + ProductWrapper newItem = new ProductWrapper(item, item.getStockItemTO(), store); + stockItems.add(newItem); + } + return stockItems; + } + + @Override + public ProductWrapper getStockItemByProductID(Store store, long productID) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ProductWrapper getStockItemByBarcode(Store store, long barcode) { + return null; + } +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/Enterprise.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/Enterprise.java new file mode 100644 index 00000000..d437c518 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/Enterprise.java @@ -0,0 +1,37 @@ +package org.cocome.cloud.web.inventory.enterprise; + +/** + * Holds information on an enterprise. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +public class Enterprise { + private long id; + private String name; + + public Enterprise() { + id = 0; + name = "N/A"; + } + + public Enterprise(long id, String name) { + this.id = id; + this.name = name; + } + + public long getId() { + return id; + } + public void setId(long id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/EnterpriseConverter.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/EnterpriseConverter.java new file mode 100644 index 00000000..f591fa73 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/EnterpriseConverter.java @@ -0,0 +1,63 @@ +package org.cocome.cloud.web.inventory.enterprise; + +import javax.enterprise.context.RequestScoped; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.log4j.Logger; +import org.cocome.cloud.web.inventory.connection.IEnterpriseQuery; + +/** + * Converts an Enterprise from the UI representation into an {@link Enterprise} + * object or vice versa. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +@Named +@RequestScoped +public class EnterpriseConverter implements Converter { + private static final Logger LOG = Logger.getLogger(EnterpriseConverter.class); + + @Inject + IEnterpriseQuery enterpriseQuery; + + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + LOG.debug("Converting String: " + value); + + if (value == null || value.isEmpty()) { + return null; + } + + Long enterpriseID = Long.valueOf(value); + Enterprise enterprise = null; + enterprise = enterpriseQuery.getEnterpriseByID(enterpriseID); + + if (enterprise == null) { + throw new ConverterException("The value is not a valid Enterprise ID: " + value); + } + + return enterprise; + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + LOG.debug("Converting object: " + value); + if (value == null) { + return ""; + } + + if (value instanceof Enterprise) { + Long enterpriseID = ((Enterprise) value).getId(); + return (enterpriseID != null) ? String.valueOf(enterpriseID) : null; + } else { + throw new ConverterException("The value is not a valid Enterprise instance: " + value); + } + } + +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/EnterpriseInformation.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/EnterpriseInformation.java new file mode 100644 index 00000000..0388b137 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/EnterpriseInformation.java @@ -0,0 +1,103 @@ +package org.cocome.cloud.web.inventory.enterprise; + +import java.util.Collection; +import java.util.LinkedList; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Inject; +import javax.inject.Named; +import javax.validation.constraints.NotNull; + +import org.apache.log4j.Logger; +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; +import org.cocome.cloud.web.inventory.connection.IEnterpriseQuery; +import org.cocome.cloud.web.inventory.store.Store; + +import java.io.Serializable; + +/** + * Holds information about the currently active enterprise. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +@Named +@SessionScoped +public class EnterpriseInformation implements Serializable, IEnterpriseInformation { + private static final long serialVersionUID = 1L; + + private long activeEnterpriseID = Long.MIN_VALUE; + private Enterprise activeEnterprise; + + private static final Logger LOG = Logger.getLogger(EnterpriseInformation.class); + + @Inject + IEnterpriseQuery enterpriseQuery; + + private boolean enterpriseSubmitted = false; + + @Override + public Collection getEnterprises() { + return enterpriseQuery.getEnterprises(); + } + + @Override + public Collection getStores() throws NotInDatabaseException_Exception { + if (activeEnterpriseID != Long.MIN_VALUE) { + return enterpriseQuery.getStores(activeEnterpriseID); + } + // TODO Throw custom exception to signal error here + return new LinkedList(); + } + + @Override + public long getActiveEnterpriseID() { + return activeEnterpriseID; + } + + @Override + public void setActiveEnterpriseID(long enterpriseID) { + LOG.debug("Active enterprise was set to " + enterpriseID); + this.activeEnterpriseID = enterpriseID; + } + + @Override + public Enterprise getActiveEnterprise() { + if (activeEnterprise == null && activeEnterpriseID != Long.MIN_VALUE) { + activeEnterprise = enterpriseQuery.getEnterpriseByID(activeEnterpriseID); + } + return activeEnterprise; + } + + @Override + public String submitActiveEnterprise() { + if (isEnterpriseSet()) { + enterpriseSubmitted = true; + // return null to only refresh the current form and not create a new view + return null; + } else { + return "error"; + } + } + + @Override + public boolean isEnterpriseSubmitted() { + return enterpriseSubmitted; + } + + @Override + public boolean isEnterpriseSet() { + return activeEnterpriseID != Long.MIN_VALUE; + } + + @Override + public void setEnterpriseSubmitted(boolean submitted) { + this.enterpriseSubmitted = submitted; + } + + @Override + public void setActiveEnterprise(@NotNull Enterprise enterprise) { + activeEnterpriseID = enterprise.getId(); + this.activeEnterprise = enterprise; + } +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/IEnterpriseInformation.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/IEnterpriseInformation.java new file mode 100644 index 00000000..d787f9e1 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/IEnterpriseInformation.java @@ -0,0 +1,28 @@ +package org.cocome.cloud.web.inventory.enterprise; + +import java.util.Collection; + +import javax.validation.constraints.NotNull; + +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; +import org.cocome.cloud.web.inventory.store.Store; + +/** + * Interface for information regarding the currently active enterprise. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +public interface IEnterpriseInformation { + public Collection getEnterprises(); + public Collection getStores() throws NotInDatabaseException_Exception; + + public long getActiveEnterpriseID(); + public void setActiveEnterpriseID(long enterpriseID); + public Enterprise getActiveEnterprise(); + public void setActiveEnterprise(@NotNull Enterprise enterprise); + public String submitActiveEnterprise(); + public boolean isEnterpriseSubmitted(); + public void setEnterpriseSubmitted(boolean submitted); + public boolean isEnterpriseSet(); +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/IStoreInformation.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/IStoreInformation.java new file mode 100644 index 00000000..fb30c50c --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/IStoreInformation.java @@ -0,0 +1,20 @@ +package org.cocome.cloud.web.inventory.store; + +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; + +/** + * Interface to retrieve information about the currently active store. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +public interface IStoreInformation { + public static final long STORE_ID_NOT_SET = Long.MIN_VALUE; + + public void setActiveStoreID(long storeID); + public long getActiveStoreID(); + public Store getActiveStore() throws NotInDatabaseException_Exception; + public String submitStore(); + + public boolean isStoreSet(); +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductConverter.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductConverter.java new file mode 100644 index 00000000..65574273 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductConverter.java @@ -0,0 +1,68 @@ +package org.cocome.cloud.web.inventory.store; + +import javax.enterprise.context.RequestScoped; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.log4j.Logger; +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; +import org.cocome.cloud.web.inventory.connection.IEnterpriseQuery; + +/** + * Converts a product from the UI representation into a {@link ProductWrapper} + * object or vice versa. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +@Named +@RequestScoped +public class ProductConverter implements Converter { + private static final Logger LOG = Logger.getLogger(ProductConverter.class); + + @Inject + IEnterpriseQuery enterpriseQuery; + + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + LOG.debug("Converting String: " + value); + + if (value == null || value.isEmpty()) { + return null; + } + + Long barcode = Long.valueOf(value); + ProductWrapper product = null; + try { + product = enterpriseQuery.getProductByBarcode(barcode); + } catch (NotInDatabaseException_Exception e) { + // Do nothing, exception will be thrown by next check + } + + if (product == null) { + throw new ConverterException("The value is not a valid Product Barcode: " + value); + } + + return product; + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + LOG.debug("Converting object: " + value); + if (value == null) { + return ""; + } + + if (value instanceof ProductWrapper) { + Long barcode = ((ProductWrapper) value).getBarcode(); + return (barcode != null) ? String.valueOf(barcode) : null; + } else { + throw new ConverterException("The value is not a valid Product instance: " + value); + } + } + +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductDetails.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductDetails.java new file mode 100644 index 00000000..127cb9f9 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductDetails.java @@ -0,0 +1,28 @@ +package org.cocome.cloud.web.inventory.store; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Named; + +/** + * Holds information about a currently selected product. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +@Named +@SessionScoped +public class ProductDetails implements Serializable { + private static final long serialVersionUID = 1L; + + private ProductWrapper product; + + public void setProduct(ProductWrapper product) { + this.product = product; + } + + public ProductWrapper getProduct() { + return product; + } +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductWrapper.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductWrapper.java new file mode 100644 index 00000000..565bad60 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/ProductWrapper.java @@ -0,0 +1,80 @@ +package org.cocome.cloud.web.inventory.store; + +import org.apache.log4j.Logger; +import org.cocome.tradingsystem.inventory.application.store.ProductTO; +import org.cocome.tradingsystem.inventory.application.store.StockItemTO; + +/** + * Wraps the {@link ProductTO} and {@link StockItemTO} objects received from + * the backend to better accommodate the needs of the UI. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +public class ProductWrapper { + private static final Logger LOG = Logger.getLogger(ProductWrapper.class); + private ProductTO product; + private StockItemTO stockItem; + + // TODO should be included in the database product + private String description; + + private Store originStore; + + public ProductWrapper(ProductTO product) { + this.product = product; + } + + public ProductWrapper(ProductTO product, StockItemTO stockItem, Store originStore) { + this(product); + this.stockItem = stockItem; + this.originStore = originStore; + } + + public void setStockItem(StockItemTO stockItem) { + this.stockItem = stockItem; + } + + public String getName() { + return product.getName(); + } + + public double getSalesPrice() { + return stockItem != null ? stockItem.getSalesPrice() : -1; + } + + public String getDescription() { + return description; + } + + public long getAmount() { + return stockItem != null ? stockItem.getAmount() : -1; + } + + public long getBarcode() { + return product.getBarcode(); + } + + public long getID() { + return product.getId(); + } + + public Store getOriginStore() { + return originStore; + } + + public void setOriginStore(Store store) { + if (store != null) { + this.originStore = store; + } + } + + public ProductTO getProductTO() { + return product; + } + + public StockItemTO getStockItemTO() { + return stockItem; + } + +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/Store.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/Store.java new file mode 100644 index 00000000..ab6e8f7c --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/Store.java @@ -0,0 +1,44 @@ +package org.cocome.cloud.web.inventory.store; + +/** + * Holds informtaion about a Store. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +public class Store { + private long id; + private String name; + private String location; + + public Store(long id, String location, String name) { + this.id = id; + this.name = name; + this.location = location; + } + + public long getID() { + return id; + } + + public void setID(long storeID) { + this.id = storeID; + } + + public String getName() { + return name; + } + + public void setName(String storeName) { + this.name = storeName; + } + + public String getLocation() { + return location; + } + + public void setLocation(String storeLocation) { + this.location = storeLocation; + } + +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/StoreInformation.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/StoreInformation.java new file mode 100644 index 00000000..1c2d59ca --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/store/StoreInformation.java @@ -0,0 +1,78 @@ +package org.cocome.cloud.web.inventory.store; + +import java.io.Serializable; + +import javax.enterprise.context.SessionScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.log4j.Logger; +import org.cocome.cloud.logic.stub.NotInDatabaseException_Exception; +import org.cocome.cloud.web.events.LoginEvent; +import org.cocome.cloud.web.inventory.connection.IEnterpriseQuery; + +/** + * Holds information about the currently active store. + * + * @author Tobias Pöppke + * @author Robert Heinrich + */ +@Named +@SessionScoped +public class StoreInformation implements IStoreInformation, Serializable { + private static final long serialVersionUID = 1L; + + private static final Logger LOG = Logger.getLogger(StoreInformation.class); + + private long activeStoreID = IStoreInformation.STORE_ID_NOT_SET; + private Store activeStore; + private boolean hasChanged = false; + + @Inject + IEnterpriseQuery enterpriseQuery; + + + @Override + public Store getActiveStore() throws NotInDatabaseException_Exception { + LOG.debug("Active store is being retrieved from the database"); + if ((activeStore == null || hasChanged == true) && activeStoreID != STORE_ID_NOT_SET) { + activeStore = enterpriseQuery.getStoreByID(activeStoreID); + } else { + hasChanged = false; + } + return activeStore; + } + + @Override + public void setActiveStoreID(long storeID) { + LOG.debug("Active store was set to id " + storeID); + activeStoreID = storeID; + hasChanged = true; + } + + @Override + public long getActiveStoreID() { + return activeStoreID; + } + + @Override + public String submitStore() { + LOG.debug("Submit store was called"); + if (isStoreSet()) { + hasChanged = true; + return "showStockItems"; + } else { + return "error"; + } + } + + @Override + public boolean isStoreSet() { + return activeStoreID != IStoreInformation.STORE_ID_NOT_SET; + } + + public void observeLoginEvent(@Observes LoginEvent event) { + setActiveStoreID(event.getStoreID()); + } +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/login/Login.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/login/Login.java index 45675526..db4f5f67 100644 --- a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/login/Login.java +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/login/Login.java @@ -13,6 +13,7 @@ import org.cocome.cloud.web.events.LogoutEvent; import org.cocome.cloud.web.frontend.navigation.NavigationElements; import org.cocome.cloud.web.frontend.navigation.NavigationViewStates; +import org.cocome.cloud.web.inventory.store.StoreInformation; @ManagedBean @@ -34,7 +35,7 @@ public class Login { private IUser user = null; - private long requestedStoreId; + private long requestedStoreId = StoreInformation.STORE_ID_NOT_SET; private boolean loggedIn = false; @@ -62,7 +63,7 @@ public String login() { if (storedUser != null) { setLoggedIn(true); user = storedUser; - loginEvent.fire(new LoginEvent(storedUser, requestedRole)); + loginEvent.fire(new LoginEvent(storedUser, requestedRole, requestedStoreId)); LOG.info(String.format("Successful login: username %s.", getUserName())); return NavigationElements.MAIN_PAGE.getNavigationOutcome(); } @@ -99,7 +100,7 @@ public void setLoggedIn(boolean loggedIn) { } public long getRequestedStoreId() { - return requestedStoreId; + return requestedStoreId == StoreInformation.STORE_ID_NOT_SET ? 0 : requestedStoreId; } public void setRequestedStoreId(long requestedStoreId) { diff --git a/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/login/UserRole.java b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/login/UserRole.java new file mode 100644 index 00000000..eaa27745 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/java/org/cocome/cloud/web/login/UserRole.java @@ -0,0 +1,23 @@ +package org.cocome.cloud.web.login; + +import org.cocome.cloud.web.frontend.navigation.NavigationViewStates; + +public enum UserRole { + ENTERPRISE_MANAGER(NavigationViewStates.ENTERPRISE_VIEW), + STORE_MANAGER(NavigationViewStates.STORE_VIEW), + STOCK_MANAGER(NavigationViewStates.STORE_VIEW), + CASHIER(NavigationViewStates.STORE_VIEW), + ADMIN(NavigationViewStates.STORE_VIEW), + DATABASE_MANAGER(NavigationViewStates.ENTERPRISE_VIEW), + DEFAULT(NavigationViewStates.DEFAULT_VIEW); + + private NavigationViewStates assocView; + + UserRole(NavigationViewStates assocView) { + this.assocView = assocView; + } + + public NavigationViewStates associatedView() { + return assocView; + } +} diff --git a/cocome-maven-project/cloud-web-frontend/src/main/resources/cocome/frontend/Strings.properties b/cocome-maven-project/cloud-web-frontend/src/main/resources/cocome/frontend/Strings.properties index cd80138e..07885ace 100644 --- a/cocome-maven-project/cloud-web-frontend/src/main/resources/cocome/frontend/Strings.properties +++ b/cocome-maven-project/cloud-web-frontend/src/main/resources/cocome/frontend/Strings.properties @@ -1,4 +1,14 @@ navigation.logout.label=Logout +enterprise.conversion.error.text=Unknown Enterprise +enterprise.required.text=Enterprise ID is required\! +store.table.header_id=Store ID +store.table.header_name=Store Name +store.table.header_loc=Store Location +enterprise.table.header_name=Enterprise Name +enterprise.table.header_id=Enterprise ID +enterprise.table.header_action=Action +enterprise.table.action.show_stores=Show all stores in this enterprise +enterprise.table.action.create_store=Create new store navigation.no_store_selected.text=No Store selected login.enterprise_manager.text=Enterprise Manager login.store_manager.text=Store Manager diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/change_price.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/change_price.xhtml new file mode 100644 index 00000000..9c070d52 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/change_price.xhtml @@ -0,0 +1,19 @@ + + + + + + + + + + Change Price + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_enterprise.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_enterprise.xhtml new file mode 100644 index 00000000..04694b0e --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_enterprise.xhtml @@ -0,0 +1,19 @@ + + + + + + + + + + Create Enterprise + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_product.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_product.xhtml new file mode 100644 index 00000000..7aba4312 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_product.xhtml @@ -0,0 +1,19 @@ + + + + + + + + + + Create Product + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_store.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_store.xhtml new file mode 100644 index 00000000..ee71c04d --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/create_store.xhtml @@ -0,0 +1,38 @@ + + + + + + + + + + + + #{strings['enterprise.table.header_id']} + #{enterprise.id} + + + #{strings['enterprise.table.header_name']} + #{enterprise.name} + + + #{strings['enterprise.table.header_action']} + + + + + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/order_products.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/order_products.xhtml new file mode 100644 index 00000000..6fce0beb --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/order_products.xhtml @@ -0,0 +1,19 @@ + + + + + + + + + + Order Products + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/receive_products.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/receive_products.xhtml new file mode 100644 index 00000000..19dce19c --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/receive_products.xhtml @@ -0,0 +1,19 @@ + + + + + + + + + + Receive Products + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/image/add-icon.png b/cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/icon/icon_add.png similarity index 100% rename from cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/image/add-icon.png rename to cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/icon/icon_add.png diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/icon/icon_Shop.png b/cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/icon/icon_shop.png similarity index 100% rename from cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/icon/icon_Shop.png rename to cocome-maven-project/cloud-web-frontend/src/main/webapp/resources/icon/icon_shop.png diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_enterprises.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_enterprises.xhtml new file mode 100644 index 00000000..2517085d --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_enterprises.xhtml @@ -0,0 +1,45 @@ + + + + + + + + + + + + #{strings['enterprise.table.header_id']} + #{enterprise.id} + + + #{strings['enterprise.table.header_name']} + #{enterprise.name} + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_products.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_products.xhtml new file mode 100644 index 00000000..52e3faa6 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_products.xhtml @@ -0,0 +1,19 @@ + + + + + + + + + + Show Products + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_reports.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_reports.xhtml new file mode 100644 index 00000000..4129b1f6 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_reports.xhtml @@ -0,0 +1,19 @@ + + + + + + + + + + Show Reports + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_stores.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_stores.xhtml new file mode 100644 index 00000000..066be6b8 --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/show_stores.xhtml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + #{strings['enterprise.table.header_name']} + #{enterpriseInformation.activeEnterprise.name} + + + #{strings['store.table.header_id']} + #{store.ID} + + + #{strings['store.table.header_name']} + #{store.name} + + + #{strings['store.table.header_loc']} + #{store.location} + + + + + + + + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/start_sale.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/start_sale.xhtml new file mode 100644 index 00000000..4667754d --- /dev/null +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/start_sale.xhtml @@ -0,0 +1,19 @@ + + + + + + + + + + Start Sale + + + + + \ No newline at end of file diff --git a/cocome-maven-project/cloud-web-frontend/src/main/webapp/templates/commonTemplate.xhtml b/cocome-maven-project/cloud-web-frontend/src/main/webapp/templates/commonTemplate.xhtml index 4506e212..232713b1 100644 --- a/cocome-maven-project/cloud-web-frontend/src/main/webapp/templates/commonTemplate.xhtml +++ b/cocome-maven-project/cloud-web-frontend/src/main/webapp/templates/commonTemplate.xhtml @@ -37,6 +37,7 @@ .product-table { border-collapse: collapse; + width: 100%; } .product-table-header { @@ -110,6 +111,25 @@ text-decoration: underline !important; } + .button { + margin: 2px; + padding: 1; + border: 1; + width: 25px; + height: 25px; + cursor: pointer; + } + + .show-stores-button { + background-image: url("#{resource['icon:icon_shop.png']}"); + background-repeat: no-repeat; + } + + .create-store-button { + background-image: url("#{resource['icon:icon_add.png']}"); + background-repeat: no-repeat; + } +