Search in sources :

Example 11 with CriticalError

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

the class CommandExecuter method loginEmployeeCommand.

private void loginEmployeeCommand(SQLDatabaseConnection c) {
    Login login = null;
    log.info("Login employee command called");
    try {
        login = Serialization.deserialize(inCommandWrapper.getData(), Login.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for login command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!login.isValid()) {
        log.info("Login command failed, username and password can't be empty");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        return;
    }
    try {
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
        outCommandWrapper.setSenderID(c.loginWorker(login.getUserName(), login.getPassword()));
        try {
            outCommandWrapper.setData(c.getClientType(outCommandWrapper.getSenderID()));
        } catch (ClientNotConnected e) {
            log.fatal("Client is not connected for sender ID " + outCommandWrapper.getSenderID());
        }
        log.info("Login command succeded with sender ID " + outCommandWrapper.getSenderID() + " with client type " + outCommandWrapper.getData());
    } catch (AuthenticationError e) {
        log.info("Login command failed, username dosen't exist or wrong password received");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST_WRONG_PASSWORD);
    } catch (CriticalError e) {
        log.fatal("Login command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientAlreadyConnected e) {
        log.info("Login command failed, user already connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_ALREADY_CONNECTED);
    } catch (NumberOfConnectionsExceeded e) {
        log.fatal("Login command failed, too much connections (try to increase TRYS_NUMBER)");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    }
    log.info("Login employee with User " + login.getUserName() + " finished");
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)

Example 12 with CriticalError

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

the class CommandExecuter method removeCustomer.

private void removeCustomer(SQLDatabaseConnection c) {
    String username = null;
    log.info("Remove customer from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        username = Serialization.deserialize(inCommandWrapper.getData(), String.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Remove Customer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (ClientServerDefs.anonymousCustomerUsername.equals(username)) {
        log.info("Remove customer command failed, can't remove guest");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
        return;
    }
    log.info("Trying to remove customer " + username + " from system");
    try {
        c.removeCustomer(username);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Remove customer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotExist e) {
        log.info("Remove customer command failed, customer is not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST);
    }
    log.info("Remove customer " + username + " from system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Example 13 with CriticalError

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

the class CommandExecuter method removeManufacturer.

private void removeManufacturer(SQLDatabaseConnection c) {
    Manufacturer manufacturer = null;
    log.info("Remove 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 Remove Manufacturer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to remove manufacturer " + manufacturer + " from system");
    try {
        c.removeManufacturer(inCommandWrapper.getSenderID(), manufacturer);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Remove manufacturer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotConnected e) {
        log.info("Remove manufacturer command failed, client is not connected");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
    } catch (ManufacturerNotExist e) {
        log.info("Remove manufacturer customer command failed, manufacturer does not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.PARAM_ID_IS_NOT_EXIST);
    } catch (ManufacturerStillUsed e) {
        log.info("Remove manufacturer customer command failed, manufacturer still in use");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_MANUFACTURER_STILL_IN_USE);
    }
    log.info("Remove manufacturer " + manufacturer + " from system finished");
}
Also used : ManufacturerNotExist(SQLDatabase.SQLDatabaseException.ManufacturerNotExist) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Manufacturer(BasicCommonClasses.Manufacturer) ManufacturerStillUsed(SQLDatabase.SQLDatabaseException.ManufacturerStillUsed) CommandWrapper(ClientServerApi.CommandWrapper)

Example 14 with CriticalError

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

the class CommandExecuter method getProductPackageAmount.

private void getProductPackageAmount(SQLDatabaseConnection c) {
    ProductPackage productPackage = null;
    log.info("Get Product Package Amount command called");
    try {
        productPackage = Serialization.deserialize(inCommandWrapper.getData(), ProductPackage.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Get Product Package Amount command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    if (!productPackage.isValid()) {
        log.info("Get Product Package Amount command failed, product package is invalid");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    } else {
        String amount = "";
        try {
            amount = productPackage.getLocation().getPlaceInMarket().equals(PlaceInMarket.STORE) ? c.getProductPackageAmonutOnShelves(inCommandWrapper.getSenderID(), productPackage) : c.getProductPackageAmonutInWarehouse(inCommandWrapper.getSenderID(), productPackage);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, amount);
        } catch (CriticalError e) {
            log.fatal("Get Product Package Amount command failed, critical error occured from SQL Database connection");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        } catch (ClientNotConnected e) {
            log.info("Get Product Package Amount command failed, username dosen't login to the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
        } catch (ProductNotExistInCatalog e) {
            log.info("Get Product Package Amount command failed, product dosen't exist in the system");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
        }
        log.info("Get Product Package Amount returned with amount " + amount + " finished");
    }
}
Also used : ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) CommandWrapper(ClientServerApi.CommandWrapper)

Example 15 with CriticalError

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

the class CommandExecuter method forgetPasswordGetQuestion.

private void forgetPasswordGetQuestion(SQLDatabaseConnection c) {
    String username;
    log.info("Get question for forget password command called with from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        username = Serialization.deserialize(inCommandWrapper.getData(), String.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Get question for forget password command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    try {
        if (inCommandWrapper.getSenderID() == 0) {
            /* Command sent from employee */
            String SecurityQuestion = c.getSecurityQuestionWorker(username);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, SecurityQuestion);
        } else {
            /* Command sent from customer */
            String SecurityQuestion = c.getSecurityQuestionCustomer(username);
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, SecurityQuestion);
        }
        log.info("Get question for forget password command for user: " + username + "succeded. the question is: " + outCommandWrapper.getData());
    } catch (CriticalError e) {
        log.fatal("Get question for forget password command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotExist e) {
        log.info("Get question for forget password command failed, client is not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST);
    }
    log.info("Get question for forget password command system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

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