-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new pages and implemented part of enterprise management
- Loading branch information
Showing
33 changed files
with
1,207 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
...web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/EnterpriseQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...eb-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IEnterpriseQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
21 changes: 21 additions & 0 deletions
21
...oud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/IStoreQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
88 changes: 88 additions & 0 deletions
88
...loud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/connection/StoreQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...loud-web-frontend/src/main/java/org/cocome/cloud/web/inventory/enterprise/Enterprise.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.