Search in sources :

Example 6 with CommandWrapper

use of ClientServerApi.CommandWrapper in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method getAllWorkers.

private void getAllWorkers(SQLDatabaseConnection c) {
    log.info("Get all workers from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        String workersList = c.getWorkersList(inCommandWrapper.getSenderID());
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, workersList);
    } catch (ClientNotConnected e) {
        log.info("Get all workers command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (CriticalError e) {
        log.fatal("Get all workers command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    }
    log.info("Get all workers from system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper)

Example 7 with CommandWrapper

use of ClientServerApi.CommandWrapper 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 8 with CommandWrapper

use of ClientServerApi.CommandWrapper 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 9 with CommandWrapper

use of ClientServerApi.CommandWrapper 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 10 with CommandWrapper

use of ClientServerApi.CommandWrapper 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)

Aggregations

CommandWrapper (ClientServerApi.CommandWrapper)218 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)162 Test (org.junit.Test)144 CommandExecuter (CommandHandler.CommandExecuter)135 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)124 Gson (com.google.gson.Gson)123 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)57 SmartCode (BasicCommonClasses.SmartCode)51 ProductPackage (BasicCommonClasses.ProductPackage)45 CriticalError (SMExceptions.CommonExceptions.CriticalError)39 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)39 Location (BasicCommonClasses.Location)37 ManufacturerNotExist (SQLDatabase.SQLDatabaseException.ManufacturerNotExist)27 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)27 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)27 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)23 InvalidCommandDescriptor (EmployeeDefs.AEmployeeException.InvalidCommandDescriptor)22 AuthenticationError (EmployeeDefs.AEmployeeException.AuthenticationError)21 EmployeeAlreadyConnected (EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected)21 IngredientStillInUse (EmployeeDefs.AEmployeeException.IngredientStillInUse)21