use of BasicCommonClasses.Ingredient in project SmartCity-Market by TechnionYP5777.
the class ManageCatalogProductDetailsTab method renameIngrPressed.
void renameIngrPressed() {
long id = ingredients.get(selectedIngr.iterator().next()).getId();
try {
manager.editIngredient(new Ingredient(id, renameIngrLbl.getText()));
} catch (InvalidParameter | CriticalError | EmployeeNotConnected | ConnectionFailure | ParamIDDoesNotExist e) {
log.debug(StackTraceUtil.getStackTrace(e));
log.fatal(e);
e.showInfoToUser();
}
selectedIngr.clear();
createIngredientList();
enableButtons();
enableAddButtons();
}
use of BasicCommonClasses.Ingredient in project SmartCity-Market by TechnionYP5777.
the class Manager method getAllIngredients.
@Override
public List<Ingredient> getAllIngredients() throws InvalidParameter, CriticalError, ConnectionFailure {
log.info("Creating getAllIngredients command wrapper");
String serverResponse = sendRequestWithRespondToServer((new CommandWrapper(getClientId(), CommandDescriptor.GET_ALL_INGREDIENTS, Serialization.serialize(""))).serialize());
CommandWrapper commandDescriptor = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler(commandDescriptor.getResultDescriptor());
} catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | ProductAlreadyExistInCatalog | ProductNotExistInCatalog | WorkerAlreadyExists | ParamIDAlreadyExists | ParamIDDoesNotExist | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse | EmployeeNotConnected ¢) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("getAllIngredients command succeed.");
return new Gson().fromJson(commandDescriptor.getData(), new TypeToken<List<Ingredient>>() {
}.getType());
}
use of BasicCommonClasses.Ingredient in project SmartCity-Market by TechnionYP5777.
the class SQLDatabaseConnectionTest method testEditIngredient.
@Test
public void testEditIngredient() {
SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
final String ingredientName = "glotendebug";
String result = null;
Ingredient ingredient = null;
//test add ingredient
try {
String tempID = sqlConnection.addIngredient(null, ingredientName);
ingredient = Serialization.deserialize(tempID, Ingredient.class);
ingredient.setName("newIngredient");
sqlConnection.editIngredient(null, ingredient);
result = sqlConnection.getIngredientsList();
} catch (CriticalError | ClientNotConnected | IngredientNotExist e) {
fail();
}
assert result != null;
HashSet<Ingredient> set = Serialization.deserializeIngredientHashSet(result);
assert set != null;
assert set.contains(ingredient);
//remove ingredient
try {
sqlConnection.removeIngredient(null, ingredient);
} catch (CriticalError | ClientNotConnected | IngredientNotExist | IngredientStillUsed e) {
fail();
}
}
use of BasicCommonClasses.Ingredient 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.Ingredient 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();
}
}
Aggregations