Search in sources :

Example 1 with Ingredient

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

the class CommandExecuter method forceRemoveIngredient.

private void forceRemoveIngredient(SQLDatabaseConnection c) {
    Ingredient ingredient = null;
    log.info("Force remove ingredient from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        ingredient = Serialization.deserialize(inCommandWrapper.getData(), Ingredient.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Force Remove Ingredient command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to force remove ingredient " + ingredient + " from system");
    try {
        //TODO noam call here to force remove ingredient
        c.removeIngredient(inCommandWrapper.getSenderID(), ingredient);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Force Remove ingredient command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Force Remove ingredient customer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (IngredientNotExist e) {
        log.info("Force Remove ingredient customer command failed, ingredient does not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
    } catch (IngredientStillUsed e) {
        log.info("Force Remove ingredient customer command failed, ingredient still in use");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INGREDIENT_STILL_IN_USE);
    }
    log.info("Force Remove ingredient " + ingredient + " from system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist)

Example 2 with Ingredient

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

the class CommandExecuter method editIngredient.

private void editIngredient(SQLDatabaseConnection c) {
    Ingredient ingredient = null;
    log.info("Edit ingredient from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        ingredient = Serialization.deserialize(inCommandWrapper.getData(), Ingredient.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Edit Ingredient command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to edit ingredient " + ingredient);
    try {
        c.editIngredient(inCommandWrapper.getSenderID(), ingredient);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Edit ingredient command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Edit ingredient customer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (IngredientNotExist e) {
        log.info("Edit ingredient customer command failed, ingredient does not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
    }
    log.info("Edit ingredient " + ingredient + " from system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist)

Example 3 with Ingredient

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

the class CommandExecuter method removeIngredient.

private void removeIngredient(SQLDatabaseConnection c) {
    Ingredient ingredient = null;
    log.info("Remove ingredient from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        ingredient = Serialization.deserialize(inCommandWrapper.getData(), Ingredient.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Remove Ingredient command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to remove ingredient " + ingredient + " from system");
    try {
        c.removeIngredient(inCommandWrapper.getSenderID(), ingredient);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Remove ingredient command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Remove ingredient customer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (IngredientNotExist e) {
        log.info("Remove ingredient customer command failed, ingredient does not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
    } catch (IngredientStillUsed e) {
        log.info("Remove ingredient customer command failed, ingredient still in use");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INGREDIENT_STILL_IN_USE);
    }
    log.info("Remove ingredient " + ingredient + " from system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Ingredient(BasicCommonClasses.Ingredient) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist)

Example 4 with Ingredient

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

the class SQLDatabaseConnectionTest method testAddRemoveIngredient.

@Test
public void testAddRemoveIngredient() {
    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);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected e) {
        fail();
    }
    assert result != null;
    HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert set.contains(ingredient);
    //test remove ingredient
    try {
        sqlConnection.removeIngredient(null, ingredient);
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
        fail();
    }
    assert result != null;
    set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert !set.contains(ingredient);
}
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 5 with Ingredient

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

the class SQLDatabaseConnectionTest method testGetEmptyIngredientsList.

public void testGetEmptyIngredientsList() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    String result = null;
    try {
        result = sqlConnection.getIngredientsList();
    } catch (CriticalError e) {
        fail();
    }
    assert result != null;
    HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
    assert set != null;
    assert set.isEmpty();
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) Ingredient(BasicCommonClasses.Ingredient)

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