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");
}
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();
}
}
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();
}
}
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);
}
}
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");
}
Aggregations