Search in sources :

Example 16 with Ingredient

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

the class ManageCatalogProductDetailsTab method renameIngrPressed.

void renameIngrPressed() {
    long id = ingredients.get(selectedIngr.iterator().next()).getId();
    try {
        manager.editIngredient(new Ingredient(id, renameIngrLbl.getText()));
    } catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | ParamIDDoesNotExist e) {
        log.debug(StackTraceUtil.getStackTrace(e));
        log.fatal(e);
        e.showInfoToUser();
    }
    selectedIngr.clear();
    createIngredientList();
    enableButtons();
    enableAddButtons();
}
Also used : InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) Ingredient(BasicCommonClasses.Ingredient) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected)

Example 17 with Ingredient

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

the class Manager method getAllIngredients.

@Override
public List<Ingredient> getAllIngredients() throws InvalidParameter, CriticalError, ConnectionFailure {
    log.info("Creating getAllIngredients command wrapper");
    String serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.GET_ALL_INGREDIENTS, Serialization.serialize(""))).serialize());
    CommandWrapper commandDescriptor = getCommandWrapper(serverResponse);
    try {
        resultDescriptorHandler(commandDescriptor.getResultDescriptor());
    } catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | ProductAlreadyExistInCatalog | ProductNotExistInCatalog | WorkerAlreadyExists | ParamIDAlreadyExists | ParamIDDoesNotExist | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse | EmployeeNotConnected ¢) {
        log.fatal("Critical bug: this command result isn't supposed to return here");
        throw new CriticalError();
    }
    log.info("getAllIngredients command succeed.");
    return new Gson().fromJson(commandDescriptor.getData(), new TypeToken<List<Ingredient>>() {
    }.getType());
}
Also used : AuthenticationError(EmployeeDefs.AEmployeeException.AuthenticationError) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) CriticalError(SMExceptions.CommonExceptions.CriticalError) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientStillInUse(EmployeeDefs.AEmployeeException.IngredientStillInUse) EmployeeAlreadyConnected(EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected) WorkerDoesNotExist(EmployeeDefs.AEmployeeException.WorkerDoesNotExist) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) ProductAlreadyExistInCatalog(EmployeeDefs.AEmployeeException.ProductAlreadyExistInCatalog) ProductStillForSale(EmployeeDefs.AEmployeeException.ProductStillForSale) AmountBiggerThanAvailable(EmployeeDefs.AEmployeeException.AmountBiggerThanAvailable) Ingredient(BasicCommonClasses.Ingredient) InvalidCommandDescriptor(EmployeeDefs.AEmployeeException.InvalidCommandDescriptor) TypeToken(com.google.gson.reflect.TypeToken) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) ParamIDAlreadyExists(EmployeeDefs.AEmployeeException.ParamIDAlreadyExists) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) ManfacturerStillInUse(EmployeeDefs.AEmployeeException.ManfacturerStillInUse) ProductPackageDoesNotExist(EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)

Example 18 with Ingredient

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

the class SQLDatabaseConnectionTest method testEditIngredient.

@Test
public void testEditIngredient() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    final String ingredientName = "glotendebug";
    String result = null;
    Ingredient ingredient = null;
    //test add ingredient
    try {
        String tempID = sqlConnection.addIngredient(null, ingredientName);
        ingredient = Serialization.deserialize(tempID, Ingredient.class);
        ingredient.setName("newIngredient");
        sqlConnection.editIngredient(null, ingredient);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected | IngredientNotExist e) {
        fail();
    }
    assert result != null;
    HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert set.contains(ingredient);
    //remove ingredient
    try {
        sqlConnection.removeIngredient(null, ingredient);
    } catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
        fail();
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) Test(org.junit.Test)

Example 19 with Ingredient

use of BasicCommonClasses.Ingredient 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 20 with Ingredient

use of BasicCommonClasses.Ingredient 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)

Aggregations

Ingredient (BasicCommonClasses.Ingredient)27 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)14 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)11 Test (org.junit.Test)9 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)8 Location (BasicCommonClasses.Location)6 Manufacturer (BasicCommonClasses.Manufacturer)6 CommandWrapper (ClientServerApi.CommandWrapper)6 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)6 Gson (com.google.gson.Gson)6 CatalogProduct (BasicCommonClasses.CatalogProduct)5 CriticalError (SMExceptions.CommonExceptions.CriticalError)5 HashSet (java.util.HashSet)5 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)4 IngredientStillUsed (SQLDatabase.SQLDatabaseException.IngredientStillUsed)4 SQLException (java.sql.SQLException)4 ConnectionFailure (EmployeeDefs.AEmployeeException.ConnectionFailure)3 InvalidParameter (EmployeeDefs.AEmployeeException.InvalidParameter)3 ParamIDAlreadyExists (EmployeeDefs.AEmployeeException.ParamIDAlreadyExists)3 ParamIDDoesNotExist (EmployeeDefs.AEmployeeException.ParamIDDoesNotExist)3