Search in sources :

Example 21 with Location

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());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 22 with Location

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);
}
Also used : InsertQuery(com.healthmarketscience.sqlbuilder.InsertQuery) Ingredient(BasicCommonClasses.Ingredient) PreparedStatement(java.sql.PreparedStatement) Location(BasicCommonClasses.Location)

Example 23 with Location

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======================================");
}
Also used : ProductPackage(BasicCommonClasses.ProductPackage) SmartcodePrint(SmartcodeParser.SmartcodePrint) Location(BasicCommonClasses.Location)

Example 24 with Location

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======================================");
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) SmartcodePrint(SmartcodeParser.SmartcodePrint) SMException(SMExceptions.SMException) SmartcodePrint(SmartcodeParser.SmartcodePrint) Location(BasicCommonClasses.Location) FXML(javafx.fxml.FXML)

Example 25 with Location

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();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) CatalogProduct(BasicCommonClasses.CatalogProduct) Gson(com.google.gson.Gson) Ingredient(BasicCommonClasses.Ingredient) Manufacturer(BasicCommonClasses.Manufacturer) SQLDatabaseException(SQLDatabase.SQLDatabaseException) HashSet(java.util.HashSet) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Aggregations

Location (BasicCommonClasses.Location)47 Test (org.junit.Test)43 SmartCode (BasicCommonClasses.SmartCode)41 ProductPackage (BasicCommonClasses.ProductPackage)40 Gson (com.google.gson.Gson)40 CommandWrapper (ClientServerApi.CommandWrapper)37 CommandExecuter (CommandHandler.CommandExecuter)37 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)35 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)34 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)34 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)23 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)23 Ingredient (BasicCommonClasses.Ingredient)6 CatalogProduct (BasicCommonClasses.CatalogProduct)5 Manufacturer (BasicCommonClasses.Manufacturer)5 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)3 HashSet (java.util.HashSet)3 SQLDatabaseException (SQLDatabase.SQLDatabaseException)2 SmartcodePrint (SmartcodeParser.SmartcodePrint)2 SMException (SMExceptions.SMException)1