Search in sources :

Example 41 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class ManagePackagesTab method smartcodeEntered.

private void smartcodeEntered(SmartCode c) throws SMException {
    log.info("===============================smartcodeEntered======================================");
    getProductCatalog(barcodeTextField.getText());
    int amountInStore = worker.getProductPackageAmount(new ProductPackage(c, 1, new Location(0, 0, PlaceInMarket.STORE))), amountInWarehouse = worker.getProductPackageAmount(new ProductPackage(c, 1, new Location(0, 0, PlaceInMarket.WAREHOUSE)));
    this.amountInStore = amountInStore;
    this.amountInWarehouse = amountInWarehouse;
    showScanCodePane(false);
    showSmartCodeOperationsPane(true);
    addProductParametersToQuickView(catalogProduct.getName(), barcodeTextField.getText(), c.getExpirationDate() + "", Integer.toString(amountInStore), Integer.toString(amountInWarehouse));
    log.info("amount in store: " + amountInStore);
    log.info("amount in werehouse: " + amountInWarehouse);
    log.info("===============================smartcodeEntered======================================");
}
Also used : ProductPackage(BasicCommonClasses.ProductPackage) SmartcodePrint(SmartcodeParser.SmartcodePrint) Location(BasicCommonClasses.Location)

Example 42 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class ManagePackagesTab method runTheOperationButtonPressed.

@FXML
private void runTheOperationButtonPressed(ActionEvent __) {
    SmartCode smartcode = new SmartCode(Long.parseLong(barcodeTextField.getText()), datePicker.getValue());
    int amountVal = editPackagesAmountSpinner.getValue();
    log.info("===============================runTheOperationButtonPressed======================================");
    log.info("amount in spinner: " + amountVal);
    try {
        if (barcodeOperationsPane.isVisible()) {
            log.info("barcode pane is visible");
            if (addPakageToWarhouseRadioButton.isSelected()) {
                log.info("addPakageToWarhouseRadioButton");
                // init
                Location loc = new Location(0, 0, PlaceInMarket.WAREHOUSE);
                ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
                // exec
                worker.addProductToWarehouse(pp);
                printToSuccessLog("Added (" + amountVal + ") " + "product packages (" + pp + ") to warehouse");
                this.expirationDate = datePicker.getValue();
                searchCodeButtonPressed(null);
            }
        } else if (addPackageToStoreRadioButton.isSelected()) {
            log.info("addPackageToStoreRadioButton");
            Location loc = new Location(0, 0, PlaceInMarket.STORE);
            ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
            worker.placeProductPackageOnShelves(pp);
            printToSuccessLog("Added (" + amountVal + ") " + "product packages (" + pp + ") to store");
            searchCodeButtonPressed(null);
        } else if (removePackageFromStoreRadioButton.isSelected()) {
            log.info("removePackageFromStoreRadioButton");
            Location loc = new Location(0, 0, PlaceInMarket.STORE);
            ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
            worker.removeProductPackageFromStore(pp);
            printToSuccessLog("Removed (" + amountVal + ") " + "product packages (" + pp + ") from store");
            searchCodeButtonPressed(null);
        } else if (!removePackageFromWarhouseRadioButton.isSelected()) {
            if (printSmartCodeRadioButton.isSelected())
                new SmartcodePrint(smartcode, amountVal).print();
        } else {
            log.info("removePackageFromWarhouseRadioButton");
            Location loc = new Location(0, 0, PlaceInMarket.WAREHOUSE);
            ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
            worker.removeProductPackageFromStore(pp);
            printToSuccessLog("Removed (" + amountVal + ") " + "product packages (" + pp + ") from warehouse");
            searchCodeButtonPressed(null);
        }
    } catch (SMException e) {
        log.fatal(e);
        log.debug(StackTraceUtil.getStackTrace(e));
        e.showInfoToUser();
    }
    log.info("===============================runTheOperationButtonPressed======================================");
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) SmartcodePrint(SmartcodeParser.SmartcodePrint) SMException(SMExceptions.SMException) SmartcodePrint(SmartcodeParser.SmartcodePrint) Location(BasicCommonClasses.Location) FXML(javafx.fxml.FXML)

Example 43 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testAddRemoveProductRealBarcodeFromCatalog.

@Test
public void testAddRemoveProductRealBarcodeFromCatalog() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
    HashSet<Location> locations = new HashSet<Location>();
    CatalogProduct newProduct = new CatalogProduct(7290010328246L, "thini", ingredients, new Manufacturer(1, "תנובה"), "", 20, "", locations);
    try {
        sqlConnection.addProductToCatalog(null, newProduct);
        assertEquals(sqlConnection.getProductFromCatalog(null, newProduct.getBarcode()), new Gson().toJson(newProduct));
        sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
    } catch (SQLDatabaseException e) {
        fail();
    }
    try {
        sqlConnection.getProductFromCatalog(null, newProduct.getBarcode());
        fail();
    } catch (ProductNotExistInCatalog e) {
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) Ingredient(BasicCommonClasses.Ingredient) Manufacturer(BasicCommonClasses.Manufacturer) SQLDatabaseException(SQLDatabase.SQLDatabaseException) HashSet(java.util.HashSet) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 44 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class RemoveProductPackageFromStoreTest method removeProductPackageFromStoreProductPackageAmountNotMatchTest.

@Test
public void removeProductPackageFromStoreProductPackageAmountNotMatchTest() {
    int senderID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        if (productPackage.getLocation().equals(PlaceInMarket.STORE))
            Mockito.doThrow(new ProductPackageAmountNotMatch()).when(sqlDatabaseConnection).removeProductPackageFromShelves(senderID, productPackage);
        else
            Mockito.doThrow(new ProductPackageAmountNotMatch()).when(sqlDatabaseConnection).removeProductPackageFromWarehouse(senderID, productPackage);
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageNotExist e) {
        fail();
    } catch (ProductPackageAmountNotMatch __) {
    /* Success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_AMOUNT_BIGGER_THEN_AVAILABLE, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 45 with Location

use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.

the class RemoveProductPackageFromStoreTest method placeProductPackageOnShelvesIllegalCatalogProductTest.

@Test
public void placeProductPackageOnShelvesIllegalCatalogProductTest() {
    assertEquals(ResultDescriptor.SM_ERR, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson("", String.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.REMOVE_PRODUCT_PACKAGE_FROM_STORE, new Gson().toJson(new ProductPackage(new SmartCode(1, null), -1, new Location(0, 0, PlaceInMarket.WAREHOUSE)), ProductPackage.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Aggregations

Location (BasicCommonClasses.Location)47 Test (org.junit.Test)43 SmartCode (BasicCommonClasses.SmartCode)41 ProductPackage (BasicCommonClasses.ProductPackage)40 Gson (com.google.gson.Gson)40 CommandWrapper (ClientServerApi.CommandWrapper)37 CommandExecuter (CommandHandler.CommandExecuter)37 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)35 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)34 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)34 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)23 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)23 Ingredient (BasicCommonClasses.Ingredient)6 CatalogProduct (BasicCommonClasses.CatalogProduct)5 Manufacturer (BasicCommonClasses.Manufacturer)5 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)3 HashSet (java.util.HashSet)3 SQLDatabaseException (SQLDatabase.SQLDatabaseException)2 SmartcodePrint (SmartcodeParser.SmartcodePrint)2 SMException (SMExceptions.SMException)1