use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.
the class Worker method viewProductFromCatalog.
@Override
public CatalogProduct viewProductFromCatalog(long barcode) throws InvalidParameter, CriticalError, EmployeeNotConnected, ProductNotExistInCatalog, ConnectionFailure {
log.info("Creating viewProductFromCatalog command wrapper with barcode: " + barcode);
String serverResponse = sendRequestWithRespondToServer(new CommandWrapper(getClientId(), CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(new SmartCode(barcode, null))).serialize());
CommandWrapper $ = getCommandWrapper(serverResponse);
try {
resultDescriptorHandler($.getResultDescriptor());
} catch (InvalidCommandDescriptor | EmployeeAlreadyConnected | AuthenticationError | ProductAlreadyExistInCatalog | ProductStillForSale | AmountBiggerThanAvailable | ProductPackageDoesNotExist | WorkerAlreadyExists | ParamIDAlreadyExists | ParamIDDoesNotExist | WorkerDoesNotExist | IngredientStillInUse | ManfacturerStillInUse ยข) {
log.fatal("Critical bug: this command result isn't supposed to return here");
throw new CriticalError();
}
log.info("viewProductFromCatalog command succeed.");
return Serialization.deserialize($.getData(), CatalogProduct.class);
}
use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.
the class ManagePackagesTab method searchCodeButtonPressed.
@FXML
private void searchCodeButtonPressed(MouseEvent __) {
try {
LocalDate expirationDate = this.expirationDate != null ? this.expirationDate : datePickerForSmartCode.getValue();
if (expirationDate == null)
barcodeEntered(barcodeTextField.getText());
else
smartcodeEntered(new SmartCode(Long.parseLong(barcodeTextField.getText()), expirationDate));
this.expirationDate = expirationDate;
} catch (SMException e) {
log.fatal(e);
log.debug(StackTraceUtil.getStackTrace(e));
e.showInfoToUser();
return;
}
enableRunTheOperationButton();
}
use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.
the class Customer method addProductToCacheAndUpdateCartData.
private void addProductToCacheAndUpdateCartData(ProductPackage p, CatalogProduct catalogProduct) {
CartProduct cartProduct = cartProductCache.get(p.getSmartCode().getBarcode());
/* No packages from this CartProduct, adding new one */
if (cartProduct == null)
cartProduct = new CartProduct(catalogProduct, new HashMap<SmartCode, ProductPackage>(), 0);
cartProduct.addProductPackage(p);
cartProductCache.put(catalogProduct.getBarcode(), cartProduct);
totalProductsAmount += p.getAmount();
totalSum += p.getAmount() * catalogProduct.getPrice();
}
use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.
the class ProductPackageTest method ProductPackageTestMethod.
@Test
public void ProductPackageTestMethod() {
LocalDate ld = LocalDate.of(2016, 12, 11);
SmartCode sc = new SmartCode(123, ld);
Location lo = new Location(1, 1, PlaceInMarket.WAREHOUSE);
ProductPackage pp = new ProductPackage(sc, 2, lo);
if (!sc.equals(pp.getSmartCode()) || pp.getAmount() != 2 || !lo.equals(pp.getLocation()))
fail();
sc.setBarcode(111);
lo.setX(2);
pp.setSmartCode(sc);
pp.setAmount(1);
pp.setLocation(lo);
if (!sc.equals(pp.getSmartCode()) || pp.getAmount() != 1 || !lo.equals(pp.getLocation()))
fail();
LocalDate ld2 = LocalDate.of(2015, 12, 12);
SmartCode sc2 = new SmartCode(111, ld2);
ProductPackage pp2 = new ProductPackage(sc2, 1, lo);
if (pp2.equals(pp))
fail();
sc2.setExpirationDate(sc.getExpirationDate());
pp.setSmartCode(sc2);
if (!pp2.equals(pp))
fail();
}
use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.
the class SmartCodeTest method SmartCodeTestMethod.
@Test
public void SmartCodeTestMethod() {
LocalDate ld = LocalDate.of(2016, 12, 11);
SmartCode sc = new SmartCode(123, ld);
if (sc.getBarcode() != 123 || !sc.getExpirationDate().equals(ld))
fail();
sc.setBarcode(111);
ld.plusDays(1);
sc.setExpirationDate(ld);
if (sc.getBarcode() != 111 || !sc.getExpirationDate().equals(ld))
fail();
LocalDate ld2 = LocalDate.of(2015, 12, 12);
SmartCode sc2 = new SmartCode(111, ld2);
if (sc2.equals(sc))
fail();
sc2.setExpirationDate(sc.getExpirationDate());
if (!sc2.equals(sc))
fail();
}
Aggregations