Search in sources :

Example 1 with CustomerProfile

use of BasicCommonClasses.CustomerProfile 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 2 with CustomerProfile

use of BasicCommonClasses.CustomerProfile in project SmartCity-Market by TechnionYP5777.

the class SQLJsonGenerator method CostumerProfileToJson.

/**
	 * convert customerProfile from ResultSet to Json representation of product
	 * 
	 * @param customer
	 *            - ResultSet of the customer profile. the
	 *            ResultSet need to point to the username to convert). this
	 *            object will point the next product after returning.
	 * @param customerIngredients
	 *            - ResultSet of the customer\s ingredients (assuming the
	 *            ResultSet ordered by username column) the ResultSet should
	 *            pointing the product to convert, if it has ingredients. if so,
	 *            this object will point the next customer (or after last line) after returning.
	 * @return
	 * @throws CriticalError
	 */
static String CostumerProfileToJson(ResultSet customer, ResultSet customerIngredients) throws CriticalError {
    HashSet<Ingredient> ingredients;
    try {
        //get customer username
        String customerUsername = getStringFromResultset(customer, CustomersTable.customerusernameCol);
        // get all customer ingredients
        ingredients = createIngredientsListForCustomer(customerUsername, customerIngredients);
        String customeraddress = getStringFromResultset(customer, CustomersTable.customerAddressCol), customerCity = getStringFromResultset(customer, CustomersTable.customerCityCol), customerEmail = getStringFromResultset(customer, CustomersTable.customerEmailCol), customerFirstname = getStringFromResultset(customer, CustomersTable.customerFirstnameCol), customerLastname = getStringFromResultset(customer, CustomersTable.customerLastnameCol), customerPhonenumber = getStringFromResultset(customer, CustomersTable.customerPhonenumberCol);
        LocalDate customerBirthdate = customer.getDate(CustomersTable.customerBirthdateCol.getColumnNameSQL()).toLocalDate();
        customer.next();
        return Serialization.serialize(new CustomerProfile(customerUsername, null, customerFirstname, customerLastname, customerPhonenumber, customerEmail, customerCity, customeraddress, customerBirthdate, ingredients, null));
    } catch (SQLException e) {
        throw new SQLDatabaseException.CriticalError();
    }
}
Also used : Ingredient(BasicCommonClasses.Ingredient) SQLException(java.sql.SQLException) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CustomerProfile(BasicCommonClasses.CustomerProfile) LocalDate(java.time.LocalDate)

Example 3 with CustomerProfile

use of BasicCommonClasses.CustomerProfile in project SmartCity-Market by TechnionYP5777.

the class CustomerRegistration_FinalStepScreen method registerButtonPressed.

@FXML
void registerButtonPressed(ActionEvent __) {
    ICustomer customer = InjectionFactory.getInstance(Customer.class);
    ICustomerProfile iProfile = TempCustomerProfilePassingData.customerProfile;
    CustomerProfile profile = new CustomerProfile(iProfile.getUserName(), TempCustomerProfilePassingData.password, iProfile.getFirstName(), iProfile.getLastName(), iProfile.getPhoneNumber(), iProfile.getEmailAddress(), iProfile.getCity(), iProfile.getStreet(), iProfile.getBirthdate(), iProfile.getAllergens(), new ForgotPasswordData(TempCustomerProfilePassingData.sequrityQuestion, TempCustomerProfilePassingData.sequrityAnswer));
    try {
        customer.registerNewCustomer(profile);
        AbstractApplicationScreen.setScene("/CustomerLoginScreen/CustomerLoginScreen.fxml");
        TempCustomerProfilePassingData.clear();
    } catch (SMException e) {
        log.fatal(e);
        log.debug(StackTraceUtil.getStackTrace(e));
        e.showInfoToUser();
    }
}
Also used : ICustomer(CustomerContracts.ICustomer) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) ICustomerProfile(BasicCommonClasses.ICustomerProfile) ICustomerProfile(BasicCommonClasses.ICustomerProfile) CustomerProfile(BasicCommonClasses.CustomerProfile) SMException(SMExceptions.SMException) FXML(javafx.fxml.FXML)

Example 4 with CustomerProfile

use of BasicCommonClasses.CustomerProfile in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnection method getCustomerProfile.

@Override
public String getCustomerProfile(String username) throws CriticalError, ClientNotExist {
    log.debug("SQL Public getCustomerProfile: Customer get profile: for username: " + username);
    //case of guest login
    boolean isGuest = ClientServerDefs.anonymousCustomerUsername.equals(username);
    if (isGuest)
        return Serialization.serialize(new CustomerProfile(username));
    //case of registered client
    if (!isCustomerExist(username)) {
        log.debug("SQL Public getCustomerProfile: no such customer with username: " + username);
        throw new ClientNotExist();
    }
    PreparedStatement selectCustomerStatement = null, selectCustomerIngredientsStatement = null;
    ResultSet selectCustomerResult = null, selectCustomerIngredientsResult = null;
    try {
        String selectCustomerQuery = generateSelectQuery1Table(CustomersTable.customertable, BinaryCondition.equalTo(CustomersTable.customerusernameCol, PARAM_MARK));
        String selectCustomerIngredientsQuery = generateSelectInnerJoinWithQuery2Tables(CustomersIngredientsTable.table, IngredientsTable.table, CustomersIngredientsTable.ingredientIDCol, CustomersIngredientsTable.customerUsernameCol, BinaryCondition.equalTo(CustomersIngredientsTable.customerUsernameCol, PARAM_MARK));
        selectCustomerStatement = getParameterizedQuery(selectCustomerQuery + "", username);
        selectCustomerIngredientsStatement = getParameterizedQuery(selectCustomerIngredientsQuery + "", username);
        selectCustomerResult = selectCustomerStatement.executeQuery();
        selectCustomerResult.first();
        selectCustomerIngredientsResult = selectCustomerIngredientsStatement.executeQuery();
        String result = SQLJsonGenerator.CostumerProfileToJson(selectCustomerResult, selectCustomerIngredientsResult);
        log.debug("SQL Public setCustomerProfile: Success getting profile for username: " + username);
        return result;
    } catch (SQLDatabaseException e) {
        throw e;
    } catch (SQLException e) {
        throw new CriticalError();
    } finally {
        closeResources(selectCustomerStatement, selectCustomerIngredientsStatement, selectCustomerResult, selectCustomerIngredientsResult);
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) CustomerProfile(BasicCommonClasses.CustomerProfile) SQLDatabaseException(SQLDatabase.SQLDatabaseException)

Example 5 with CustomerProfile

use of BasicCommonClasses.CustomerProfile in project SmartCity-Market by TechnionYP5777.

the class CommandExecuter method updateCustomerProfile.

private void updateCustomerProfile(SQLDatabaseConnection c) {
    CustomerProfile profile = null;
    log.info("Update 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 Update Customer Data command");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
        return;
    }
    log.info("Trying to update customer " + profile + " to system");
    try {
        c.setCustomerProfile(profile.getUserName(), profile);
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
    } catch (CriticalError e) {
        log.fatal("Update customer command failed, critical error occured from SQL Database connection");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
    } catch (ClientNotExist e) {
        log.info("Update customer command failed, client is not exist");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_USERNAME_DOES_NOT_EXIST);
    } catch (IngredientNotExist e) {
        log.info("Update customer command failed, client try to use not existed ingredient");
        outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
    }
    log.info("Update customer " + profile + " to system finished");
}
Also used : CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) CustomerProfile(BasicCommonClasses.CustomerProfile) IngredientNotExist(SQLDatabase.SQLDatabaseException.IngredientNotExist) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist)

Aggregations

CustomerProfile (BasicCommonClasses.CustomerProfile)7 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)5 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)4 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)4 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)3 CommandWrapper (ClientServerApi.CommandWrapper)2 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)2 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)2 SQLException (java.sql.SQLException)2 Test (org.junit.Test)2 ICustomerProfile (BasicCommonClasses.ICustomerProfile)1 Ingredient (BasicCommonClasses.Ingredient)1 ICustomer (CustomerContracts.ICustomer)1 SMException (SMExceptions.SMException)1 SQLDatabaseException (SQLDatabase.SQLDatabaseException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 LocalDate (java.time.LocalDate)1 FXML (javafx.fxml.FXML)1