Search in sources :

Example 11 with CatalogProduct

use of BasicCommonClasses.CatalogProduct 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 12 with CatalogProduct

use of BasicCommonClasses.CatalogProduct 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 13 with CatalogProduct

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

the class SQLDatabaseConnectionTest method testSimpleGetProductFromCatalog.

@Test
public void testSimpleGetProductFromCatalog() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
    ingredients.add(new Ingredient(1, "חלב"));
    HashSet<Location> locations = new HashSet<Location>();
    // locations.add(new Location(1, 1, PlaceInMarket.STORE));
    String milkImage = "";
    try {
        assertEquals(sqlConnection.getProductFromCatalog(null, 1234567890), new Gson().toJson(new CatalogProduct(1234567890L, "חלב", ingredients, new Manufacturer(1, "תנובה"), "", 10.5, milkImage, locations)));
    } catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
        fail();
    }
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CatalogProduct(BasicCommonClasses.CatalogProduct) Ingredient(BasicCommonClasses.Ingredient) Manufacturer(BasicCommonClasses.Manufacturer) HashSet(java.util.HashSet) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 14 with CatalogProduct

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

the class ViewProductFromCatalogTest method ViewProductFromCatalogSuccessfulTest.

@Test
public void ViewProductFromCatalogSuccessfulTest() {
    CatalogProduct testCatalogProduct = null, catalogProduct = new CatalogProduct(1234567890, "name", null, new Manufacturer(1, "Manufacturer"), "description", 22.0, null, null);
    CommandWrapper commandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(catalogProduct));
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(new SmartCode(1234567890, null))).serialize())).thenReturn(commandWrapper.serialize());
    } catch (IOException ¢) {
        fail();
    }
    try {
        testCatalogProduct = worker.viewProductFromCatalog(1234567890);
    } catch (InvalidParameter | CriticalError | EmployeeNotConnected | ProductNotExistInCatalog | ConnectionFailure ¢) {
        fail();
    }
    assertEquals(testCatalogProduct.getBarcode(), 1234567890);
    assertEquals(testCatalogProduct.getManufacturer().getId(), 1);
    assertEquals(testCatalogProduct.getManufacturer().getName(), "Manufacturer");
    assertEquals(testCatalogProduct.getName(), "name");
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) Manufacturer(BasicCommonClasses.Manufacturer) CatalogProduct(BasicCommonClasses.CatalogProduct) CommandWrapper(ClientServerApi.CommandWrapper) IOException(java.io.IOException) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) Test(org.junit.Test)

Example 15 with CatalogProduct

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

the class CommandExecuter method editProductFromCatalogCommand.

private void editProductFromCatalogCommand(SQLDatabaseConnection c) {
    CatalogProduct catalogProduct = null;
    log.info("Edit Product From Catalog command called");
    try {
        catalogProduct = Serialization.deserialize(inCommandWrapper.getData(), CatalogProduct.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Edit Product From Catalog command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!catalogProduct.isValid()) {
        log.info("Edit Product From Catalog command failed, barcode can't be negative");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    } else {
        try {
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
            c.editProductInCatalog(inCommandWrapper.getSenderID(), catalogProduct);
        } catch (CriticalError e) {
            log.fatal("Edit Product From Catalog command failed, critical error occured from SQL Database connection");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        } catch (ClientNotConnected e) {
            log.info("Edit Product From Catalog command failed, username dosen't login to the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
        } catch (ProductNotExistInCatalog e) {
            log.info("Edit Product From Catalog command failed, product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
        } catch (IngredientNotExist e) {
            log.info("Edit Product From Catalog command failed, ingredient in the product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        } catch (ManufacturerNotExist e) {
            log.info("Edit Product From Catalog command failed, manufacturer in the product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        }
        log.info("Edit Product From Catalog with product " + catalogProduct + " finished");
    }
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist)

Aggregations

CatalogProduct (BasicCommonClasses.CatalogProduct)26 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)22 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)21 Test (org.junit.Test)21 Gson (com.google.gson.Gson)19 CommandWrapper (ClientServerApi.CommandWrapper)18 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)16 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)16 CommandExecuter (CommandHandler.CommandExecuter)14 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)13 ProductAlreadyExistInCatalog (SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog)8 Manufacturer (BasicCommonClasses.Manufacturer)6 Ingredient (BasicCommonClasses.Ingredient)5 Location (BasicCommonClasses.Location)5 SmartCode (BasicCommonClasses.SmartCode)5 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)5 HashSet (java.util.HashSet)4 SQLDatabaseException (SQLDatabase.SQLDatabaseException)3 ProductPackage (BasicCommonClasses.ProductPackage)2 CriticalError (SMExceptions.CommonExceptions.CriticalError)2