use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method verifySecurityAnswerCustomer.
@Override
public boolean verifySecurityAnswerCustomer(String username, String givenAnswer) throws CriticalError, ClientNotExist {
log.debug("SQL Public verifySecurityAnswerCustomer: Customer: " + username + " verify security answer.");
if (!isCustomerExist(username)) {
log.debug("SQL Public verifySecurityAnswerCustomer: no such customer with username: " + username);
throw new ClientNotExist();
}
try {
//Read part of transaction
boolean result = verifySecurityAnswerForRegisteredClient(new CustomersTable(), username, givenAnswer);
log.debug("SQL Public verifySecurityAnswerCustomer: result of verification for user: " + username + " is: " + result);
return result;
} catch (SQLDatabaseException e) {
throw e;
}
}
use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method removeCustomer.
@Override
public void removeCustomer(String username) throws CriticalError, ClientNotExist {
log.debug("SQL Public removeCustomer: Remove customer with username: " + username);
if (!isCustomerExist(username)) {
log.debug("SQL Public removeCustomer: no such customer with username: " + username);
throw new ClientNotExist();
}
try {
// START transaction
connectionStartTransaction();
//Read part of transaction
Integer customerSessionID = getSessionByUsernameOfRegisteredClient(new CustomersTable(), username);
//Write part of transaction
if (customerSessionID != null) {
log.debug("SQL Public removeCustomer: user " + username + " connected! doing logout first");
logoutAsCart(customerSessionID);
}
log.debug("SQL Public removeCustomer: remove user " + username + " from customers table and his ingredients");
setIngredientsForCustomer(username, new HashSet<>());
removeRegisteredClient(new CustomersTable(), username);
log.debug("SQL Public removeCustomer: Success removing username: " + username);
// END transaction
connectionCommitTransaction();
} catch (SQLDatabaseException e) {
log.debug("SQL Public removeCustomer: known error occured:" + e.getMessage());
connectionRollbackTransaction();
throw e;
} catch (SQLException e) {
log.fatal("SQL Public removeCustomer: SQL error occured:" + e.getMessage());
connectionRollbackTransaction();
throw new CriticalError();
} finally {
connectionEndTransaction();
}
}
use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method verifySecurityAnswerWorker.
@Override
public boolean verifySecurityAnswerWorker(String username, String givenAnswer) throws CriticalError, ClientNotExist {
log.debug("SQL Public verifySecurityAnswerWorker: Worker: " + username + " verify security answer.");
if (!isWorkerExist(username)) {
log.debug("SQL Public verifySecurityAnswerWorker: no such worker with username: " + username);
throw new ClientNotExist();
}
try {
//Read part of transaction
boolean result = verifySecurityAnswerForRegisteredClient(new WorkersTable(), username, givenAnswer);
log.debug("SQL Public verifySecurityAnswerWorker: result of verification for user: " + username + " is: " + result);
return result;
} catch (SQLDatabaseException e) {
throw e;
}
}
use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testAddRemoveProductRealBarcodeFromCatalog.
@Test
public void testAddRemoveProductRealBarcodeFromCatalog() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
HashSet<Location> locations = new HashSet<Location>();
CatalogProduct newProduct = new CatalogProduct(7290010328246L, "thini", ingredients, new Manufacturer(1, "תנובה"), "", 20, "", locations);
try {
sqlConnection.addProductToCatalog(null, newProduct);
assertEquals(sqlConnection.getProductFromCatalog(null, newProduct.getBarcode()), new Gson().toJson(newProduct));
sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
} catch (SQLDatabaseException e) {
fail();
}
try {
sqlConnection.getProductFromCatalog(null, newProduct.getBarcode());
fail();
} catch (ProductNotExistInCatalog e) {
} catch (CriticalError | ClientNotConnected e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException 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);
}
}
Aggregations