use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.
the class AddProductToGroceryListTest method addProductToGroceryListProductPackageNotExistTest.
@Test
public void addProductToGroceryListProductPackageNotExistTest() {
int cartID = 1;
ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
String command = new CommandWrapper(cartID, CommandDescriptor.ADD_PRODUCT_TO_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
CommandExecuter commandExecuter = new CommandExecuter(command);
CommandWrapper out;
try {
Mockito.doThrow(new ProductPackageNotExist()).when(sqlDatabaseConnection).addProductToGroceryList(cartID, productPackage);
} catch (ClientNotConnected | CriticalError | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
fail();
} catch (ProductPackageNotExist __) {
/* Successful */
}
out = commandExecuter.execute(sqlDatabaseConnection);
assertEquals(ResultDescriptor.SM_PRODUCT_PACKAGE_DOES_NOT_EXIST, out.getResultDescriptor());
}
use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnection method addCatalogProduct.
/**
* Add product to the SQL database
*
* @param p
* New product to add
* @throws CriticalError
* @throws SQLException
*/
private void addCatalogProduct(CatalogProduct p) throws CriticalError, SQLException {
// add all ingredients of product
for (Ingredient ¢ : p.getIngredients()) {
String insertToProductQuery = new InsertQuery(ProductsCatalogIngredientsTable.table).addColumn(ProductsCatalogIngredientsTable.barcodeCol, PARAM_MARK).addColumn(ProductsCatalogIngredientsTable.ingredientIDCol, PARAM_MARK).validate() + "";
insertToProductQuery.hashCode();
PreparedStatement statement = getParameterizedQuery(insertToProductQuery, p.getBarcode(), ¢.getId());
statement.executeUpdate();
closeResources(statement);
}
// add all locations of product
for (Location ¢ : p.getLocations()) {
int newID = allocateIDToTable(LocationsTable.table, LocationsTable.locationIDCol);
String insertLocationQuery = new InsertQuery(LocationsTable.table).addColumn(LocationsTable.locationIDCol, PARAM_MARK).addColumn(LocationsTable.placeInStoreCol, PARAM_MARK).addColumn(LocationsTable.pointXCol, PARAM_MARK).addColumn(LocationsTable.pointYCol, PARAM_MARK).validate() + "";
insertLocationQuery.hashCode();
PreparedStatement insertLocationStatement = getParameterizedQuery(insertLocationQuery, newID, ¢.getPlaceInMarket().equals(PlaceInMarket.STORE) ? LOCATIONS_TABLE.VALUE_PLACE_STORE : LOCATIONS_TABLE.VALUE_PLACE_WAREHOUSE, ¢.getX(), ¢.getY());
String insertToProductQuery = new InsertQuery(ProductsCatalogLocationsTable.table).addColumn(ProductsCatalogLocationsTable.barcodeCol, PARAM_MARK).addColumn(ProductsCatalogLocationsTable.locationIDCol, PARAM_MARK).validate() + "";
PreparedStatement statement = getParameterizedQuery(insertToProductQuery, p.getBarcode(), newID);
insertLocationStatement.executeUpdate();
statement.executeUpdate();
closeResources(insertLocationStatement);
closeResources(statement);
}
// add the product itself
String insertQuery = new InsertQuery(ProductsCatalogTable.table).addColumn(ProductsCatalogTable.barcodeCol, PARAM_MARK).addColumn(ProductsCatalogTable.manufacturerIDCol, PARAM_MARK).addColumn(ProductsCatalogTable.productDescriptionCol, PARAM_MARK).addColumn(ProductsCatalogTable.productNameCol, PARAM_MARK).addColumn(ProductsCatalogTable.productPictureCol, PARAM_MARK).addColumn(ProductsCatalogTable.productPriceCol, PARAM_MARK).validate() + "";
PreparedStatement statement = getParameterizedQuery(insertQuery, p.getBarcode(), p.getManufacturer().getId(), p.getDescription(), p.getName(), p.getImageUrl(), p.getPrice());
statement.executeUpdate();
closeResources(statement);
}
use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.
the class ManagePackagesTab method smartcodeEntered.
private void smartcodeEntered(SmartCode c) throws SMException {
log.info("===============================smartcodeEntered======================================");
getProductCatalog(barcodeTextField.getText());
int amountInStore = worker.getProductPackageAmount(new ProductPackage(c, 1, new Location(0, 0, PlaceInMarket.STORE))), amountInWarehouse = worker.getProductPackageAmount(new ProductPackage(c, 1, new Location(0, 0, PlaceInMarket.WAREHOUSE)));
this.amountInStore = amountInStore;
this.amountInWarehouse = amountInWarehouse;
showScanCodePane(false);
showSmartCodeOperationsPane(true);
addProductParametersToQuickView(catalogProduct.getName(), barcodeTextField.getText(), c.getExpirationDate() + "", Integer.toString(amountInStore), Integer.toString(amountInWarehouse));
log.info("amount in store: " + amountInStore);
log.info("amount in werehouse: " + amountInWarehouse);
log.info("===============================smartcodeEntered======================================");
}
use of BasicCommonClasses.Location in project SmartCity-Market by TechnionYP5777.
the class ManagePackagesTab method runTheOperationButtonPressed.
@FXML
private void runTheOperationButtonPressed(ActionEvent __) {
SmartCode smartcode = new SmartCode(Long.parseLong(barcodeTextField.getText()), datePicker.getValue());
int amountVal = editPackagesAmountSpinner.getValue();
log.info("===============================runTheOperationButtonPressed======================================");
log.info("amount in spinner: " + amountVal);
try {
if (barcodeOperationsPane.isVisible()) {
log.info("barcode pane is visible");
if (addPakageToWarhouseRadioButton.isSelected()) {
log.info("addPakageToWarhouseRadioButton");
// init
Location loc = new Location(0, 0, PlaceInMarket.WAREHOUSE);
ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
// exec
worker.addProductToWarehouse(pp);
printToSuccessLog("Added (" + amountVal + ") " + "product packages (" + pp + ") to warehouse");
this.expirationDate = datePicker.getValue();
searchCodeButtonPressed(null);
}
} else if (addPackageToStoreRadioButton.isSelected()) {
log.info("addPackageToStoreRadioButton");
Location loc = new Location(0, 0, PlaceInMarket.STORE);
ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
worker.placeProductPackageOnShelves(pp);
printToSuccessLog("Added (" + amountVal + ") " + "product packages (" + pp + ") to store");
searchCodeButtonPressed(null);
} else if (removePackageFromStoreRadioButton.isSelected()) {
log.info("removePackageFromStoreRadioButton");
Location loc = new Location(0, 0, PlaceInMarket.STORE);
ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
worker.removeProductPackageFromStore(pp);
printToSuccessLog("Removed (" + amountVal + ") " + "product packages (" + pp + ") from store");
searchCodeButtonPressed(null);
} else if (!removePackageFromWarhouseRadioButton.isSelected()) {
if (printSmartCodeRadioButton.isSelected())
new SmartcodePrint(smartcode, amountVal).print();
} else {
log.info("removePackageFromWarhouseRadioButton");
Location loc = new Location(0, 0, PlaceInMarket.WAREHOUSE);
ProductPackage pp = new ProductPackage(smartcode, amountVal, loc);
worker.removeProductPackageFromStore(pp);
printToSuccessLog("Removed (" + amountVal + ") " + "product packages (" + pp + ") from warehouse");
searchCodeButtonPressed(null);
}
} catch (SMException e) {
log.fatal(e);
log.debug(StackTraceUtil.getStackTrace(e));
e.showInfoToUser();
}
log.info("===============================runTheOperationButtonPressed======================================");
}
use of BasicCommonClasses.Location 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();
}
}
Aggregations