use of BasicCommonClasses.CatalogProduct in project SmartCity-Market by TechnionYP5777.
the class ManageCatalogProductTab method runTheOperationButtonPressed.
@FXML
void runTheOperationButtonPressed(ActionEvent __) {
try {
if (addCatalogProductRadioButton.isSelected()) {
manager.addProductToCatalog(new CatalogProduct(Long.parseLong(barcodeTextField.getText()), productNameTextField.getText(), new HashSet<Ingredient>(), getManufacturer(), productDescriptionTextField.getText().isEmpty() ? "N/A" : productDescriptionTextField.getText(), Double.parseDouble(productPriceTextField.getText()), "", new HashSet<Location>()));
printToSuccessLog("Added new product '" + productNameTextField.getText() + "' to catalog");
} else if (removeCatalogProductRadioButton.isSelected()) {
manager.removeProductFromCatalog(new SmartCode(Long.parseLong(barcodeTextField.getText()), null));
printToSuccessLog("Remove product '" + productNameTextField.getText() + "' from catalog");
}
} catch (SMException e) {
log.fatal(e);
log.debug(StackTraceUtil.getStackTrace(e));
e.showInfoToUser();
}
}
use of BasicCommonClasses.CatalogProduct 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 BasicCommonClasses.CatalogProduct in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testSimpleGetProductFromCatalog.
@Test
public void testSimpleGetProductFromCatalog() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
HashSet<Ingredient> ingredients = new HashSet<Ingredient>();
ingredients.add(new Ingredient(1, "חלב"));
HashSet<Location> locations = new HashSet<Location>();
// locations.add(new Location(1, 1, PlaceInMarket.STORE));
String milkImage = "";
try {
assertEquals(sqlConnection.getProductFromCatalog(null, 1234567890), new Gson().toJson(new CatalogProduct(1234567890L, "חלב", ingredients, new Manufacturer(1, "תנובה"), "", 10.5, milkImage, locations)));
} catch (ProductNotExistInCatalog | ClientNotConnected | CriticalError e) {
fail();
}
}
use of BasicCommonClasses.CatalogProduct in project SmartCity-Market by TechnionYP5777.
the class ViewProductFromCatalogTest method ViewProductFromCatalogSuccessfulTest.
@Test
public void ViewProductFromCatalogSuccessfulTest() {
CatalogProduct testCatalogProduct = null, catalogProduct = new CatalogProduct(1234567890, "name", null, new Manufacturer(1, "Manufacturer"), "description", 22.0, null, null);
CommandWrapper commandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(catalogProduct));
try {
Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(new SmartCode(1234567890, null))).serialize())).thenReturn(commandWrapper.serialize());
} catch (IOException ¢) {
fail();
}
try {
testCatalogProduct = worker.viewProductFromCatalog(1234567890);
} catch (InvalidParameter | CriticalError | EmployeeNotConnected | ProductNotExistInCatalog | ConnectionFailure ¢) {
fail();
}
assertEquals(testCatalogProduct.getBarcode(), 1234567890);
assertEquals(testCatalogProduct.getManufacturer().getId(), 1);
assertEquals(testCatalogProduct.getManufacturer().getName(), "Manufacturer");
assertEquals(testCatalogProduct.getName(), "name");
}
use of BasicCommonClasses.CatalogProduct in project SmartCity-Market by TechnionYP5777.
the class CommandExecuter method editProductFromCatalogCommand.
private void editProductFromCatalogCommand(SQLDatabaseConnection c) {
CatalogProduct catalogProduct = null;
log.info("Edit Product From Catalog command called");
try {
catalogProduct = Serialization.deserialize(inCommandWrapper.getData(), CatalogProduct.class);
} catch (java.lang.RuntimeException e) {
log.fatal("Failed to parse data for Edit Product From Catalog command");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
return;
}
if (!catalogProduct.isValid()) {
log.info("Edit Product From Catalog command failed, barcode can't be negative");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
} else {
try {
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_OK);
c.editProductInCatalog(inCommandWrapper.getSenderID(), catalogProduct);
} catch (CriticalError e) {
log.fatal("Edit Product From Catalog command failed, critical error occured from SQL Database connection");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_ERR);
} catch (ClientNotConnected e) {
log.info("Edit Product From Catalog command failed, username dosen't login to the system");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_SENDER_IS_NOT_CONNECTED);
} catch (ProductNotExistInCatalog e) {
log.info("Edit Product From Catalog command failed, product dosen't exist in the system");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST);
} catch (IngredientNotExist e) {
log.info("Edit Product From Catalog command failed, ingredient in the product dosen't exist in the system");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
} catch (ManufacturerNotExist e) {
log.info("Edit Product From Catalog command failed, manufacturer in the product dosen't exist in the system");
outCommandWrapper = new CommandWrapper(ResultDescriptor.SM_INVALID_PARAMETER);
}
log.info("Edit Product From Catalog with product " + catalogProduct + " finished");
}
}
Aggregations