Search in sources :

Example 11 with SmartCode

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);
}
Also used : AuthenticationError(EmployeeDefs.AEmployeeException.AuthenticationError) SmartCode(BasicCommonClasses.SmartCode) CriticalError(SMExceptions.CommonExceptions.CriticalError) CommandWrapper(ClientServerApi.CommandWrapper) IngredientStillInUse(EmployeeDefs.AEmployeeException.IngredientStillInUse) EmployeeAlreadyConnected(EmployeeDefs.AEmployeeException.EmployeeAlreadyConnected) WorkerDoesNotExist(EmployeeDefs.AEmployeeException.WorkerDoesNotExist) ProductAlreadyExistInCatalog(EmployeeDefs.AEmployeeException.ProductAlreadyExistInCatalog) ProductStillForSale(EmployeeDefs.AEmployeeException.ProductStillForSale) AmountBiggerThanAvailable(EmployeeDefs.AEmployeeException.AmountBiggerThanAvailable) InvalidCommandDescriptor(EmployeeDefs.AEmployeeException.InvalidCommandDescriptor) WorkerAlreadyExists(EmployeeDefs.AEmployeeException.WorkerAlreadyExists) ParamIDAlreadyExists(EmployeeDefs.AEmployeeException.ParamIDAlreadyExists) ParamIDDoesNotExist(EmployeeDefs.AEmployeeException.ParamIDDoesNotExist) ManfacturerStillInUse(EmployeeDefs.AEmployeeException.ManfacturerStillInUse) ProductPackageDoesNotExist(EmployeeDefs.AEmployeeException.ProductPackageDoesNotExist)

Example 12 with SmartCode

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();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) SMException(SMExceptions.SMException) LocalDate(java.time.LocalDate) FXML(javafx.fxml.FXML)

Example 13 with SmartCode

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();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) CartProduct(BasicCommonClasses.CartProduct)

Example 14 with SmartCode

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();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) LocalDate(java.time.LocalDate) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 15 with SmartCode

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();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Aggregations

SmartCode (BasicCommonClasses.SmartCode)82 Test (org.junit.Test)71 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)63 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)63 ProductPackage (BasicCommonClasses.ProductPackage)58 CommandWrapper (ClientServerApi.CommandWrapper)51 Gson (com.google.gson.Gson)50 CommandExecuter (CommandHandler.CommandExecuter)47 Location (BasicCommonClasses.Location)41 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)39 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)39 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)20 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)8 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)8 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)8 ProductStillForSale (SQLDatabase.SQLDatabaseException.ProductStillForSale)8 CatalogProduct (BasicCommonClasses.CatalogProduct)5 Manufacturer (BasicCommonClasses.Manufacturer)3 SMException (SMExceptions.SMException)3