Search in sources :

Example 1 with IngredientNotExist

use of SQLDatabase.SQLDatabaseException.IngredientNotExist 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 IngredientNotExist

use of SQLDatabase.SQLDatabaseException.IngredientNotExist 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 IngredientNotExist

use of SQLDatabase.SQLDatabaseException.IngredientNotExist 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 IngredientNotExist

use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method registerNewCustomer.

private void registerNewCustomer(SQLDatabaseConnection c) {
    CustomerProfile profile = null;
    log.info("Register new customer from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        profile = Serialization.deserialize(inCommandWrapper.getData(), CustomerProfile.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Register New Customer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to register new customer " + profile + " to system");
    try {
        c.registerCustomer(profile.getUserName(), profile.getPassword());
        c.setCustomerProfile(profile.getUserName(), profile);
        c.setSecurityQACustomer(profile.getUserName(), profile.getForgetPassword());
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Register new customer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientAlreadyExist e) {
        log.info("Register new customer command failed, client already exists");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_ALREADY_EXISTS);
    } catch (ClientNotExist e) {
        log.fatal("Register new customer command failed, the sql report that the client not exists but i added it just now");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (IngredientNotExist e) {
        log.info("Register new customer command failed, client try to use not existed ingredient");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    }
    log.info("Register new customer " + profile + " to system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) CommandWrapper(ClientServerApi.CommandWrapper) CustomerProfile(BasicCommonClasses.CustomerProfile) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Example 5 with IngredientNotExist

use of SQLDatabase.SQLDatabaseException.IngredientNotExist in project SmartCity-Market by TechnionYP5777.

the class RemoveIngredientTest method removeIngredientSuccessfulTest.

@Test
public void removeIngredientSuccessfulTest() {
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_INGREDIENT, new Gson().toJson(ingredient, Ingredient.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doNothing().when(sqlDatabaseConnection).removeIngredient(senderID, ingredient);
    } catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e1) {
        fail();
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_OK, out.getResultDescriptor());
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) IngredientStillUsed(SQLDatabase.SQLDatabaseException.IngredientStillUsed) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Aggregations

CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)45 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)45 CommandWrapper (ClientServerApi.CommandWrapper)39 Test (org.junit.Test)38 CommandExecuter (CommandHandler.CommandExecuter)32 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)32 Gson (com.google.gson.Gson)32 CatalogProduct (BasicCommonClasses.CatalogProduct)16 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)16 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)13 IngredientStillUsed (SQLDatabase.SQLDatabaseException.IngredientStillUsed)10 ProductAlreadyExistInCatalog (SQLDatabase.SQLDatabaseException.ProductAlreadyExistInCatalog)8 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)8 Ingredient (BasicCommonClasses.Ingredient)7 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)7 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)6 CustomerProfile (BasicCommonClasses.CustomerProfile)4 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)2