Search in sources :

Example 66 with SmartCode

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

the class ManageCatalogProductTab method runTheOperationButtonPressed.

@FXML
void runTheOperationButtonPressed(ActionEvent __) {
    try {
        if (addCatalogProductRadioButton.isSelected()) {
            manager.addProductToCatalog(new CatalogProduct(Long.parseLong(barcodeTextField.getText()), productNameTextField.getText(), new HashSet<Ingredient>(), getManufacturer(), productDescriptionTextField.getText().isEmpty() ? "N/A" : productDescriptionTextField.getText(), Double.parseDouble(productPriceTextField.getText()), "", new HashSet<Location>()));
            printToSuccessLog("Added new product '" + productNameTextField.getText() + "' to catalog");
        } else if (removeCatalogProductRadioButton.isSelected()) {
            manager.removeProductFromCatalog(new SmartCode(Long.parseLong(barcodeTextField.getText()), null));
            printToSuccessLog("Remove product '" + productNameTextField.getText() + "' from catalog");
        }
    } catch (SMException e) {
        log.fatal(e);
        log.debug(StackTraceUtil.getStackTrace(e));
        e.showInfoToUser();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) CatalogProduct(BasicCommonClasses.CatalogProduct) SMException(SMExceptions.SMException) HashSet(java.util.HashSet) FXML(javafx.fxml.FXML)

Example 67 with SmartCode

use of BasicCommonClasses.SmartCode 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 68 with SmartCode

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

the class ViewCatalogProductTest method viewCatalogProductSuccessfulTest.

@Test
public void viewCatalogProductSuccessfulTest() {
    int senderID = 1;
    SmartCode smartCode = new SmartCode(0, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.getProductFromCatalog(senderID, smartCode.getBarcode())).thenReturn("");
    } catch (ClientNotConnected | ProductNotExistInCatalog | CriticalError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 69 with SmartCode

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

the class ViewCatalogProductTest method viewCatalogProductProductDoesNotExistTest.

@Test
public void viewCatalogProductProductDoesNotExistTest() {
    int senderID = 1;
    SmartCode smartCode = new SmartCode(0, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.when(sqlDatabaseConnection.getProductFromCatalog(senderID, smartCode.getBarcode())).thenThrow(new ProductNotExistInCatalog());
    } catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 70 with SmartCode

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

the class SQLDatabaseConnectionTest method testRemoveNotExistedPakageFromCart.

@Test
public void testRemoveNotExistedPakageFromCart() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 10, locationWarehouse);
    int sessionCart = 0;
    try {
        sessionCart = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
    } catch (AuthenticationError | ClientAlreadyConnected | CriticalError | NumberOfConnectionsExceeded e1) {
        fail();
    }
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        assertEquals("10", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
        fail();
    }
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
        fail();
    }
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.addProductToGroceryList(sessionCart, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("10", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
        fail();
    }
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e1) {
        fail();
    }
    try {
        sqlConnection.removeProductFromGroceryList(sessionCart, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.logout(sessionCart, ClientServerDefs.anonymousCustomerUsername);
    } catch (ClientNotConnected | CriticalError e) {
        fail();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Aggregations

SmartCode (BasicCommonClasses.SmartCode)82 Test (org.junit.Test)71 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)63 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)63 ProductPackage (BasicCommonClasses.ProductPackage)58 CommandWrapper (ClientServerApi.CommandWrapper)51 Gson (com.google.gson.Gson)50 CommandExecuter (CommandHandler.CommandExecuter)47 Location (BasicCommonClasses.Location)41 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)39 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)39 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)20 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)8 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)8 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)8 ProductStillForSale (SQLDatabase.SQLDatabaseException.ProductStillForSale)8 CatalogProduct (BasicCommonClasses.CatalogProduct)5 Manufacturer (BasicCommonClasses.Manufacturer)3 SMException (SMExceptions.SMException)3