use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method getSecurityQuestionWorker.
@Override
public String getSecurityQuestionWorker(String username) throws CriticalError, ClientNotExist {
log.debug("SQL Public getSecurityQuestionWorker: Worker: " + username + " get security question.");
if (!isWorkerExist(username)) {
log.debug("SQL Public getSecurityQuestionWorker: no such worker with username: " + username);
throw new ClientNotExist();
}
try {
//Read part of transaction
String result = getSecurityQuestionForRegisteredClient(new WorkersTable(), username);
log.debug("SQL Public getSecurityQuestionWorker: the security question of user: " + username + " is: \n" + result);
return result;
} catch (SQLDatabaseException e) {
throw e;
}
}
use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testRemoveCatalogProductStillForSell.
@Test
public void testRemoveCatalogProductStillForSell() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
CatalogProduct newProduct = createDummyProduct(456L, "testRemoveCatalogProductStillForSell", 1, "תנובה", 3.0);
ProductPackage newPackage = new ProductPackage(new SmartCode(newProduct.getBarcode(), date232015), 5, locationWarehouse);
// add catalog-product and add it to warehouse
try {
sqlConnection.addProductToCatalog(null, newProduct);
assertEquals(sqlConnection.getProductFromCatalog(null, newProduct.getBarcode()), new Gson().toJson(newProduct));
sqlConnection.addProductPackageToWarehouse(null, newPackage);
assertEquals("5", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
} catch (SQLDatabaseException e) {
fail();
}
// try to remove
try {
sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
fail();
} catch (ProductStillForSale e1) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
fail();
}
// move to shelf
try {
sqlConnection.placeProductPackageOnShelves(null, newPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, newPackage));
} catch (SQLDatabaseException e) {
fail();
}
// try to remove
try {
sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
fail();
} catch (ProductStillForSale e1) {
} catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog e1) {
fail();
}
// move to shelf
try {
sqlConnection.removeProductPackageFromShelves(null, newPackage);
assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, newPackage));
assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, newPackage));
sqlConnection.removeProductFromCatalog(null, new SmartCode(newProduct.getBarcode(), null));
} catch (SQLDatabaseException e) {
fail();
}
}
use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testSimpleAddRemoveProductFromCatalog.
@Test
public void testSimpleAddRemoveProductFromCatalog() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
HashSet<Location> locations = new HashSet<Location>();
CatalogProduct newProduct = new CatalogProduct(123L, "name", 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 getSecurityQuestionCustomer.
@Override
public String getSecurityQuestionCustomer(String username) throws CriticalError, ClientNotExist {
log.debug("SQL Public getSecurityQuestionCustomer: Customer: " + username + " get security question.");
if (!isCustomerExist(username)) {
log.debug("SQL Public getSecurityQuestionCustomer: no such customer with username: " + username);
throw new ClientNotExist();
}
try {
//Read part of transaction
String result = getSecurityQuestionForRegisteredClient(new CustomersTable(), username);
log.debug("SQL Public getSecurityQuestionCustomer: the security question of user: " + username + " is: \n" + result);
return result;
} catch (SQLDatabaseException e) {
throw e;
}
}
use of SQLDatabase.SQLDatabaseException in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method addWorker.
@Override
public void addWorker(Integer sessionID, Login l, ForgotPasswordData security) throws CriticalError, ClientAlreadyExist, ClientNotConnected {
log.debug("SQL Public addWorker: add new worker with username: " + l.getUserName());
validateSessionEstablished(sessionID);
if (isWorkerExist(l.getUserName())) {
log.debug("SQL Public addWorker: already exist worker with username: " + l.getUserName());
throw new ClientAlreadyExist();
}
PreparedStatement statement = null;
try {
// START transaction
connectionStartTransaction();
//Write part of transaction
String insertCustomerQuery = new InsertQuery(WorkersTable.workertable).addColumn(WorkersTable.workerusernameCol, PARAM_MARK).addColumn(WorkersTable.workerpasswordCol, PARAM_MARK).addColumn(WorkersTable.workerPrivilegesCol, PARAM_MARK).addColumn(WorkersTable.workersecurityQuestionCol, PARAM_MARK).addColumn(WorkersTable.workersecurityAnswerCol, PARAM_MARK).addColumn(WorkersTable.workerisLoggedInCol, PARAM_MARK).validate() + "";
statement = getParameterizedQuery(insertCustomerQuery, l.getUserName(), l.getPassword(), WORKERS_TABLE.VALUE_PRIVILEGE_WORKER, security.getQuestion(), security.getAnswer(), 0);
statement.executeUpdate();
log.debug("SQL Public addWorker: worker " + l.getUserName() + "added successfuly");
// END transaction
connectionCommitTransaction();
} catch (SQLDatabaseException e) {
// NOTE: all exceptions flows here - for doing rollback
connectionRollbackTransaction();
throw e;
} catch (SQLException e) {
connectionRollbackTransaction();
throw new CriticalError();
} finally {
connectionEndTransaction();
closeResources(statement);
}
}
Aggregations