use of BasicCommonClasses.GroceryList in project SmartCity-Market by TechnionYP5777.
the class Customer method checkOutGroceryList.
@Override
public Double checkOutGroceryList() throws CriticalError, CustomerNotConnected, GroceryListIsEmpty {
String serverResponse;
Double $ = totalSum;
log.info("Creating CHECKOUT_GROCERY_LIST command wrapper to customer with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer((new CommandWrapper(id, CommandDescriptor.CHECKOUT_GROCERY_LIST)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
try {
resultDescriptorHandler(getCommandWrapper(serverResponse).getResultDescriptor());
} catch (InvalidCommandDescriptor | InvalidParameter | AmountBiggerThanAvailable | ProductPackageDoesNotExist | AuthenticationError | ProductCatalogDoesNotExist | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
/* update customer data: groceryList, cartProductCache, totalSum */
groceryList = new GroceryList();
cartProductCache = new HashMap<Long, CartProduct>();
totalSum = Double.valueOf(0);
totalProductsAmount = 0;
log.info("CHECKOUT_GROCERY_LIST command succeed.");
return $;
}
use of BasicCommonClasses.GroceryList in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method logoutAsCart.
/**
* logout cart from system. (remove cartID entry and it grocery list)
*
* @param cartID
* @throws CriticalError
*/
private void logoutAsCart(int cartID) throws CriticalError {
// READ part of transaction
int listID = getCartListId(cartID);
PreparedStatement deleteGroceryList = null, deleteCart = null;
try {
// WRITE part of transaction
// get grocery list and returns each product to shelf
ResultSet groceryListResultSet = getGroceryListResultSetByCartID(cartID);
groceryListResultSet.first();
GroceryList groceryList = SQLJsonGenerator.resultSetToGroceryList(groceryListResultSet);
if (groceryList.getList() != null)
for (ProductPackage p : groceryList.getList().values()) moveProductPackage(cartID, LOCATIONS_TYPES.CART, LOCATIONS_TYPES.STORE, p, p.getAmount());
// delete grocery list and cart
deleteGroceryList = getParameterizedQuery(generateDeleteQuery(GroceriesListsTable.table, BinaryCondition.equalTo(GroceriesListsTable.listIDCol, PARAM_MARK)), listID);
deleteCart = getParameterizedQuery(generateDeleteQuery(CartsListTable.table, BinaryCondition.equalTo(CartsListTable.listIDCol, PARAM_MARK)), listID);
log.debug("logoutAsCart: delete groceryList " + listID + ".\n by run query: " + deleteGroceryList);
deleteGroceryList.executeUpdate();
log.debug("logoutAsCart: disconnect cart " + cartID + ".\n by run query: " + deleteCart);
deleteCart.executeUpdate();
} catch (SQLException e) {
throw new CriticalError();
} catch (ProductPackageAmountNotMatch e) {
log.error("logoutAsCart: trying to return product to shelf but amount not matched to what in the grocery list");
throw new CriticalError();
} catch (ProductPackageNotExist e) {
log.error("logoutAsCart: trying to return product to shelf but product package not exist in grocery list");
throw new CriticalError();
} finally {
closeResources(deleteGroceryList, deleteCart);
}
}
use of BasicCommonClasses.GroceryList in project SmartCity-Market by TechnionYP5777.
the class Customer method resume.
@Override
public void resume(int _id) throws CriticalError, CustomerNotConnected {
CommandWrapper $ = null;
String serverResponse;
log.info("Creating customer Load grocery list command wrapper with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer((new CommandWrapper(id, CommandDescriptor.LOAD_GROCERY_LIST)).serialize());
} catch (SocketTimeoutException e) {
log.fatal("Critical bug: failed to get respond from server");
throw new CriticalError();
}
terminateCommunication();
try {
$ = getCommandWrapper(serverResponse);
resultDescriptorHandler($.getResultDescriptor());
id = _id;
groceryList = Serialization.deserialize($.getData(), GroceryList.class);
} catch (InvalidCommandDescriptor | InvalidParameter | ProductCatalogDoesNotExist | AmountBiggerThanAvailable | ProductPackageDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
/* Restoring Grocery list */
try {
loadCartProductCacheAndUpdateCartData();
} catch (ProductCatalogDoesNotExist | CriticalError | CustomerNotConnected e) {
log.fatal("Critical bug: Failed to fetch grocery list items from server");
}
log.info("load grocery list from server succeed.");
}
Aggregations