use of BasicCommonClasses.CartProduct 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.CartProduct in project SmartCity-Market by TechnionYP5777.
the class Customer method addProductToCacheAndUpdateCartData.
private void addProductToCacheAndUpdateCartData(ProductPackage p, CatalogProduct catalogProduct) {
CartProduct cartProduct = cartProductCache.get(p.getSmartCode().getBarcode());
/* No packages from this CartProduct, adding new one */
if (cartProduct == null)
cartProduct = new CartProduct(catalogProduct, new HashMap<SmartCode, ProductPackage>(), 0);
cartProduct.addProductPackage(p);
cartProductCache.put(catalogProduct.getBarcode(), cartProduct);
totalProductsAmount += p.getAmount();
totalSum += p.getAmount() * catalogProduct.getPrice();
}
use of BasicCommonClasses.CartProduct in project SmartCity-Market by TechnionYP5777.
the class CustomerMainScreen method smartcodeScannedHandler.
private void smartcodeScannedHandler() {
Integer amount;
CartProduct cartPtoduct = customer.getCartProduct(scannedSmartCode);
if (cartPtoduct != null) {
catalogProduct = cartPtoduct.getCatalogProduct();
amount = cartPtoduct.getTotalAmount();
} else {
try {
catalogProduct = customer.viewCatalogProduct(scannedSmartCode);
} catch (SMException e) {
log.fatal(e);
log.debug(StackTraceUtil.getStackTrace(e));
e.showInfoToUser();
return;
}
amount = 0;
}
Platform.runLater(new Runnable() {
@Override
public void run() {
addOrRemoveScannedProduct(catalogProduct, amount);
}
});
}
use of BasicCommonClasses.CartProduct in project SmartCity-Market by TechnionYP5777.
the class Customer method returnProductToShelf.
@Override
public void returnProductToShelf(SmartCode c, int amount) throws AmountBiggerThanAvailable, ProductPackageDoesNotExist, CriticalError, CustomerNotConnected {
String serverResponse;
log.info("Creating REMOVE_PRODUCT_FROM_GROCERY_LIST command wrapper to customer with id: " + id);
establishCommunication(CustomerDefs.port, CustomerDefs.host, CustomerDefs.timeout);
try {
serverResponse = sendRequestWithRespondToServer(new CommandWrapper(id, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, Serialization.serialize(new ProductPackage(c, amount, null))).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 | ProductCatalogDoesNotExist | GroceryListIsEmpty | AuthenticationError | UsernameAlreadyExists | ForgotPasswordWrongAnswer ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
/* update customer data: groceryList, cartProductCache, totalSum */
if (groceryList == null)
throw new CriticalError();
try {
groceryList.removeProduct(new ProductPackage(c, amount, null));
} catch (ProductNotInList | AmountIsBiggerThanAvailable ¢) {
throw new CriticalError();
}
long barcode = c.getBarcode();
CartProduct cartProduct = cartProductCache.get(barcode);
ProductPackage productPackage = new ProductPackage(c, amount, null);
cartProduct.removeProductPackage(productPackage);
if (cartProduct.getTotalAmount() <= 0)
cartProductCache.remove(barcode);
else
cartProductCache.put(barcode, cartProduct);
totalProductsAmount -= amount;
totalSum -= amount * cartProduct.getCatalogProduct().getPrice();
log.info("REMOVE_PRODUCT_FROM_GROCERY_LIST command succeed.");
}
use of BasicCommonClasses.CartProduct in project SmartCity-Market by TechnionYP5777.
the class CustomerMainScreen method initialize.
@Override
public void initialize(URL location, ResourceBundle __) {
AbstractApplicationScreen.fadeTransition(customerMainScreenPane);
barcodeEventHandler.register(this);
customer = TempCustomerPassingData.customer;
filteredProductList = new FilteredList<>(productsObservableList, s -> true);
searchField.textProperty().addListener(obs -> {
String filter = searchField.getText();
filteredProductList.setPredicate((filter == null || filter.length() == 0) ? s -> true : s -> s.getCatalogProduct().getName().contains(filter));
});
productsListView.setItems(filteredProductList);
productsListView.setCellFactory(new Callback<ListView<CartProduct>, ListCell<CartProduct>>() {
@Override
public ListCell<CartProduct> call(ListView<CartProduct> __) {
return new CustomerProductCellFormat();
}
});
productsListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<CartProduct>() {
@Override
public void changed(ObservableValue<? extends CartProduct> __, CartProduct oldValue, CartProduct newValue) {
updateProductInfoPaine(newValue.getCatalogProduct(), newValue.getTotalAmount(), ProductInfoPaneVisibleMode.PRESSED_PRODUCT);
}
});
productsListView.depthProperty().set(1);
productsListView.setExpanded(true);
setAbilityAndVisibilityOfProductInfoPane(false);
}
Aggregations