Search in sources :

Example 1 with CartProduct

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 $;
}
Also used : AuthenticationError(CustomerContracts.ACustomerExceptions.AuthenticationError) CriticalError(SMExceptions.CommonExceptions.CriticalError) GroceryList(BasicCommonClasses.GroceryList) CommandWrapper(ClientServerApi.CommandWrapper) InvalidParameter(CustomerContracts.ACustomerExceptions.InvalidParameter) SocketTimeoutException(java.net.SocketTimeoutException) AmountBiggerThanAvailable(CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable) InvalidCommandDescriptor(CustomerContracts.ACustomerExceptions.InvalidCommandDescriptor) ForgotPasswordWrongAnswer(CustomerContracts.ACustomerExceptions.ForgotPasswordWrongAnswer) CartProduct(BasicCommonClasses.CartProduct) ProductPackageDoesNotExist(CustomerContracts.ACustomerExceptions.ProductPackageDoesNotExist) UsernameAlreadyExists(CustomerContracts.ACustomerExceptions.UsernameAlreadyExists) ProductCatalogDoesNotExist(CustomerContracts.ACustomerExceptions.ProductCatalogDoesNotExist)

Example 2 with CartProduct

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();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) CartProduct(BasicCommonClasses.CartProduct)

Example 3 with CartProduct

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);
        }
    });
}
Also used : CartProduct(BasicCommonClasses.CartProduct) SMException(SMExceptions.SMException)

Example 4 with CartProduct

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.");
}
Also used : AuthenticationError(CustomerContracts.ACustomerExceptions.AuthenticationError) AmountIsBiggerThanAvailable(CommonDefs.GroceryListExceptions.AmountIsBiggerThanAvailable) CriticalError(SMExceptions.CommonExceptions.CriticalError) ProductPackage(BasicCommonClasses.ProductPackage) CommandWrapper(ClientServerApi.CommandWrapper) GroceryListIsEmpty(CustomerContracts.ACustomerExceptions.GroceryListIsEmpty) InvalidParameter(CustomerContracts.ACustomerExceptions.InvalidParameter) SocketTimeoutException(java.net.SocketTimeoutException) InvalidCommandDescriptor(CustomerContracts.ACustomerExceptions.InvalidCommandDescriptor) ForgotPasswordWrongAnswer(CustomerContracts.ACustomerExceptions.ForgotPasswordWrongAnswer) ProductNotInList(CommonDefs.GroceryListExceptions.ProductNotInList) CartProduct(BasicCommonClasses.CartProduct) UsernameAlreadyExists(CustomerContracts.ACustomerExceptions.UsernameAlreadyExists) ProductCatalogDoesNotExist(CustomerContracts.ACustomerExceptions.ProductCatalogDoesNotExist)

Example 5 with CartProduct

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);
}
Also used : Button(javafx.scene.control.Button) TempCustomerPassingData(CustomerGuiHelpers.TempCustomerPassingData) Initializable(javafx.fxml.Initializable) ListView(javafx.scene.control.ListView) URL(java.net.URL) ListCell(javafx.scene.control.ListCell) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) IConfiramtionDialog(UtilsContracts.IConfiramtionDialog) ICustomer(CustomerContracts.ICustomer) Logger(org.apache.log4j.Logger) CatalogProduct(BasicCommonClasses.CatalogProduct) ResourceBundle(java.util.ResourceBundle) BarcodeEventHandler(UtilsImplementations.BarcodeEventHandler) Subscribe(com.google.common.eventbus.Subscribe) Callback(javafx.util.Callback) CustomerProductCellFormat(CustomerGuiHelpers.CustomerProductCellFormat) GridPane(javafx.scene.layout.GridPane) CartProduct(BasicCommonClasses.CartProduct) Label(javafx.scene.control.Label) MalformedURLException(java.net.MalformedURLException) SmartCode(BasicCommonClasses.SmartCode) StackTraceUtil(UtilsImplementations.StackTraceUtil) JFXListView(com.jfoenix.controls.JFXListView) FilteredList(javafx.collections.transformation.FilteredList) SMException(SMExceptions.SMException) DialogMessagesService(GuiUtils.DialogMessagesService) File(java.io.File) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) InjectionFactory(UtilsImplementations.InjectionFactory) ActionEvent(javafx.event.ActionEvent) IBarcodeEventHandler(UtilsContracts.IBarcodeEventHandler) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) LocalDate(java.time.LocalDate) SmartcodeScanEvent(UtilsContracts.SmartcodeScanEvent) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) AbstractApplicationScreen(GuiUtils.AbstractApplicationScreen) ChangeListener(javafx.beans.value.ChangeListener) Image(javafx.scene.image.Image) JFXTextField(com.jfoenix.controls.JFXTextField) ListView(javafx.scene.control.ListView) JFXListView(com.jfoenix.controls.JFXListView) ListCell(javafx.scene.control.ListCell) CartProduct(BasicCommonClasses.CartProduct) CustomerProductCellFormat(CustomerGuiHelpers.CustomerProductCellFormat)

Aggregations

CartProduct (BasicCommonClasses.CartProduct)5 ProductPackage (BasicCommonClasses.ProductPackage)2 SmartCode (BasicCommonClasses.SmartCode)2 CommandWrapper (ClientServerApi.CommandWrapper)2 AuthenticationError (CustomerContracts.ACustomerExceptions.AuthenticationError)2 ForgotPasswordWrongAnswer (CustomerContracts.ACustomerExceptions.ForgotPasswordWrongAnswer)2 InvalidCommandDescriptor (CustomerContracts.ACustomerExceptions.InvalidCommandDescriptor)2 InvalidParameter (CustomerContracts.ACustomerExceptions.InvalidParameter)2 ProductCatalogDoesNotExist (CustomerContracts.ACustomerExceptions.ProductCatalogDoesNotExist)2 UsernameAlreadyExists (CustomerContracts.ACustomerExceptions.UsernameAlreadyExists)2 CriticalError (SMExceptions.CommonExceptions.CriticalError)2 SMException (SMExceptions.SMException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 CatalogProduct (BasicCommonClasses.CatalogProduct)1 GroceryList (BasicCommonClasses.GroceryList)1 AmountIsBiggerThanAvailable (CommonDefs.GroceryListExceptions.AmountIsBiggerThanAvailable)1 ProductNotInList (CommonDefs.GroceryListExceptions.ProductNotInList)1 AmountBiggerThanAvailable (CustomerContracts.ACustomerExceptions.AmountBiggerThanAvailable)1 GroceryListIsEmpty (CustomerContracts.ACustomerExceptions.GroceryListIsEmpty)1 ProductPackageDoesNotExist (CustomerContracts.ACustomerExceptions.ProductPackageDoesNotExist)1