Search in sources :

Example 1 with ClientNotExist

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

the class CommandExecuter method forgetPasswordSendAnswerWithNewPassword.

private void forgetPasswordSendAnswerWithNewPassword(SQLDatabaseConnection c) {
    Login login;
    log.info("Get question for forget password send answer command called with from serderID " + inCommandWrapper.getSenderID() + " command called");
    try {
        login = Serialization.deserialize(inCommandWrapper.getData(), Login.class);
    } catch (java.lang.RuntimeException e) {
        log.fatal("Failed to parse data for Get question for forget password send answer command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    boolean goodAnswer;
    try {
        goodAnswer = inCommandWrapper.getSenderID() == 0 ? /* Command sent from employee */
        c.verifySecurityAnswerWorker(login.getUserName(), login.getForgetPassword().getAnswer()) : /* Command sent from customer */
        c.verifySecurityAnswerCustomer(login.getUserName(), login.getForgetPassword().getAnswer());
        if (!goodAnswer) {
            log.info("the anwser is incorrect.");
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_FOROGT_PASSWORD_WRONG_ANSWER, Serialization.serialize(false));
        } else {
            log.info("the anwser is correct");
            if (inCommandWrapper.getSenderID() == 0)
                /* Command sent from employee */
                c.setPasswordWorker(login.getUserName(), login.getPassword());
            else
                /* Command sent from customer */
                c.setPasswordCustomer(login.getUserName(), login.getPassword());
            outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(true));
            log.info("the anwser is correct. password changed succesfully.");
        }
    } catch (CriticalError e) {
        log.fatal("Get question for forget password send answer 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 send answer command failed, client is not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST);
    }
    log.info("Get question for forget password send answer command system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Example 2 with ClientNotExist

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

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

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

Example 5 with ClientNotExist

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

the class CommandExecuter method loginClientCommand.

private void loginClientCommand(SQLDatabaseConnection c) {
    Login login = null;
    log.info("Login client 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);
        int senderID = c.loginCustomer(login.getUserName(), login.getPassword());
        outCommandWrapper.setSenderID(senderID);
        try {
            outCommandWrapper.setData(c.getCustomerProfile(login.getUserName()));
        } catch (ClientNotExist e) {
            log.fatal("Client is not exist with username: " + 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 client with User " + login.getUserName() + " finished");
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) Login(BasicCommonClasses.Login) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Aggregations

ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)40 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)40 Test (org.junit.Test)33 CommandWrapper (ClientServerApi.CommandWrapper)23 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)17 CommandExecuter (CommandHandler.CommandExecuter)16 Gson (com.google.gson.Gson)16 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)14 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)13 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)12 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)9 Login (BasicCommonClasses.Login)6 CustomerProfile (BasicCommonClasses.CustomerProfile)4 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)4 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)4 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)4