Search in sources :

Example 6 with CriticalError

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

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

the class CommandExecuter method isLoggedInCommand.

private void isLoggedInCommand(SQLDatabaseConnection c) {
    log.info("Is logged in command called with senderID " + inCommandWrapper.getSenderID());
    try {
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(c.isClientLoggedIn(inCommandWrapper.getSenderID())));
    } catch (CriticalError e) {
        log.fatal("Is logged in command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    }
    log.info("Is logged in command finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper)

Example 8 with CriticalError

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

the class CommandExecuter method removeProductPackageFromStoreCommand.

private void removeProductPackageFromStoreCommand(SQLDatabaseConnection c) {
    ProductPackage productPackage = null;
    log.info("Remove Product Package From Store command called");
    try {
        productPackage = Serialization.deserialize(inCommandWrapper.getData(), ProductPackage.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Remove Product Package From Store command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!productPackage.isValid()) {
        log.info("Remove Product Package From Store command failed, product package is invalid");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    } else {
        try {
            if (productPackage.getLocation().getPlaceInMarket().equals(PlaceInMarket.STORE))
                c.removeProductPackageFromShelves(inCommandWrapper.getSenderID(), productPackage);
            else
                c.removeProductPackageFromWarehouse(inCommandWrapper.getSenderID(), productPackage);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
        } catch (CriticalError e) {
            log.fatal("Remove Product Package From Store command failed, critical error occured from SQL Database connection");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        } catch (ClientNotConnected e) {
            log.info("Remove Product Package From Store command failed, username dosen't login to the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
        } catch (ProductNotExistInCatalog e) {
            log.info("Remove Product Package From Store command failed, product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
        } catch (ProductPackageAmountNotMatch e) {
            log.info("Remove Product Package From Store command failed, try to place more than available");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_PRODUCT_PACKAGE_AMOUNT_BIGGER_THEN_AVAILABLE);
        } catch (ProductPackageNotExist e) {
            log.info("Remove Product Package From Store command failed, package dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST);
        }
        log.info("Remove Product Package From Store with product package barcode " + productPackage.getSmartCode().getBarcode() + " and amount " + productPackage.getAmount() + " finished");
    }
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist)

Example 9 with CriticalError

use of SQLDatabase.SQLDatabaseException.CriticalError 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 10 with CriticalError

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

the class CommandExecuter method addNewManufacturer.

private void addNewManufacturer(SQLDatabaseConnection c) {
    Manufacturer manufacturer = null;
    log.info("Add new manufacturer from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        manufacturer = Serialization.deserialize(inCommandWrapper.getData(), Manufacturer.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Add New Manufacturer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to add new manufacturer " + manufacturer + " to system");
    try {
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, c.addManufacturer(inCommandWrapper.getSenderID(), manufacturer.getName()));
    } catch (CriticalError e) {
        log.fatal("Add new manufacturer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Add new manufacturer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    }
    log.info("Add new manufacturer " + manufacturer + " to system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) CommandWrapper(ClientServerApi.CommandWrapper)

Aggregations

CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)225 Test (org.junit.Test)186 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)172 CommandWrapper (ClientServerApi.CommandWrapper)162 CommandExecuter (CommandHandler.CommandExecuter)128 Gson (com.google.gson.Gson)118 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)81 SmartCode (BasicCommonClasses.SmartCode)63 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)61 ProductPackage (BasicCommonClasses.ProductPackage)55 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)45 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)43 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)43 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)40 Location (BasicCommonClasses.Location)35 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)31 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)27 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)27 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)27 CatalogProduct (BasicCommonClasses.CatalogProduct)22