Skip to content

Commit

Permalink
Added new pages and implemented part of enterprise management
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoeppke committed Jun 21, 2016
1 parent 91d8f5c commit 60a92df
Show file tree
Hide file tree
Showing 33 changed files with 1,207 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cocome-maven-project/cloud-web-frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<artifactId>cloud-logic-core-services</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.cocome</groupId>
<artifactId>cloud-registry-client</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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<Long, Enterprise> enterprises;
private Map<Long, Collection<Store>> storeCollections;
private Map<Long, Store> stores;

@WebServiceRef(IEnterpriseManagerService.class)
IEnterpriseManager enterpriseManager;

/* (non-Javadoc)
* @see org.cocome.cloud.shop.inventory.connection.IEnterpriseQuery#getEnterprises()
*/
@Override
public Collection<Enterprise> 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<Store> getStores(long enterpriseID) throws NotInDatabaseException_Exception {
if(storeCollections == null) {
updateStoreInformation();
}

Collection<Store> storeCollection = storeCollections.get(enterpriseID);
return storeCollection != null ? storeCollection : new LinkedList<Store>();
}

@Override
public void updateEnterpriseInformation() {
this.enterprises = new HashMap<Long, Enterprise>();

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<Long, Collection<Store>>((int)(enterprises.size() / 0.75) + 1);

this.stores = new HashMap<Long, Store>();

for (Enterprise ent : enterprises.values()) {
LinkedList<Store> stores = new LinkedList<Store>();

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<ProductWrapper> getAllProducts() {
// TODO should definitely be cached somehow, especially when there are lots of products
List<ProductWrapper> products = new LinkedList<ProductWrapper>();
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;
}
}
Original file line number Diff line number Diff line change
@@ -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<Enterprise> getEnterprises();

public Collection<Store> 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<ProductWrapper> getAllProducts();

public ProductWrapper getProductByID(long productID) throws NotInDatabaseException_Exception;

public ProductWrapper getProductByBarcode(long barcode) throws NotInDatabaseException_Exception;
}
Original file line number Diff line number Diff line change
@@ -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<ProductWrapper> queryStockItems(Store store) throws NotInDatabaseException_Exception;

public ProductWrapper getStockItemByProductID(Store store, long productID);

public ProductWrapper getStockItemByBarcode(Store store, long barcode);
}
Original file line number Diff line number Diff line change
@@ -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<ProductWrapper> queryStockItems(Store store) throws NotInDatabaseException_Exception {
long storeID = store.getID();
storeManager = lookupStoreManager(storeID);
List<ProductWrapper> stockItems = new LinkedList<ProductWrapper>();
List<ProductWithSupplierAndStockItemTO> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}


}
Loading

0 comments on commit 60a92df

Please sign in to comment.