Search in sources :

Example 1 with PicoProduct

use of eu.ggnet.dwoss.uniqueunit.api.PicoProduct in project dwoss by gg-net.

the class UniqueUnitAgentStub method createOrUpdate.

@Override
public CategoryProduct createOrUpdate(CategoryProductDto dto, String username) throws NullPointerException {
    CategoryProduct cp = new CategoryProduct();
    cp.setName(dto.getName());
    cp.setDescription(dto.getDescription());
    cp.setSalesChannel(dto.getSalesChannel());
    cp.getProducts().forEach(p -> p.setCategoryProduct(null));
    for (PicoProduct pp : dto.getProducts()) {
        Product p = new Product();
        p.setName(pp.getShortDescription());
        cp.getProducts().add(p);
    }
    for (Map.Entry<PriceType, Double> price : dto.getPrices().entrySet()) {
        cp.setPrice(price.getKey(), price.getValue(), "Price changed by " + username);
    }
    System.out.println("Storing " + cp);
    return cp;
}
Also used : CategoryProduct(eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) CategoryProduct(eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) PriceType(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType)

Example 2 with PicoProduct

use of eu.ggnet.dwoss.uniqueunit.api.PicoProduct in project dwoss by gg-net.

the class AssignmentController method addUnitCollection.

@FXML
private void addUnitCollection() {
    final PicoProduct selectedProduct = productList.getSelectionModel().getSelectedItem();
    if (selectedProduct == null)
        return;
    Ui.exec(() -> {
        Ui.build(root).fxml().eval(() -> new UnitCollection(), UnitCollectionEditorController.class).opt().map(dto -> Dl.remote().lookup(UniqueUnitAgent.class).createOnProduct(selectedProduct.getId(), dto, Dl.local().lookup(Guardian.class).getUsername())).filter(Ui.failure()::handle).map(Reply::getPayload).ifPresent(uc -> {
            unitCollectionList.getItems().add(uc);
        });
    });
}
Also used : EventHandler(javafx.event.EventHandler) Title(eu.ggnet.saft.api.ui.Title) java.util(java.util) Initializable(javafx.fxml.Initializable) ListView(javafx.scene.control.ListView) URL(java.net.URL) ListCell(javafx.scene.control.ListCell) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) MULTIPLE(javafx.scene.control.SelectionMode.MULTIPLE) Ui(eu.ggnet.saft.Ui) Dl(eu.ggnet.saft.Dl) FxController(eu.ggnet.saft.api.ui.FxController) StockApi(eu.ggnet.dwoss.stock.api.StockApi) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) UniqueUnitAgent(eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent) javafx.scene.input(javafx.scene.input) Logger(org.slf4j.Logger) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) UnitCollection(eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection) Collectors(java.util.stream.Collectors) FXML(javafx.fxml.FXML) Guardian(eu.ggnet.saft.core.auth.Guardian) ActionEvent(javafx.event.ActionEvent) Reply(eu.ggnet.saft.api.Reply) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ObservableValue(javafx.beans.value.ObservableValue) BorderPane(javafx.scene.layout.BorderPane) ChangeListener(javafx.beans.value.ChangeListener) UnitCollection(eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection) UniqueUnitAgent(eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) FXML(javafx.fxml.FXML)

Example 3 with PicoProduct

use of eu.ggnet.dwoss.uniqueunit.api.PicoProduct in project dwoss by gg-net.

the class UniqueUnitAgentIT method testCreateOrUpdateCategoryProduct.

@Test
public void testCreateOrUpdateCategoryProduct() throws Exception {
    // Create a some Products.
    utx.begin();
    em.joinTransaction();
    Product p1 = new Product(ProductGroup.DESKTOP, TradeName.ACER, "LX.11111.222", "Verition Stein");
    p1.setDescription("Ein Tolles Gerät");
    p1.setPrice(PriceType.MANUFACTURER_COST, 200.0, "JUnit - Testcase");
    p1.setPrice(PriceType.CONTRACTOR_REFERENCE, 240.0, "JUnit - Testcase");
    p1.addFlag(Product.Flag.PRICE_FIXED);
    Product p2 = new Product(ProductGroup.COMMENTARY, TradeName.DELL, "DL", "Dienstleistung 1h");
    p2.setDescription("Eine Dienstleistungs Stunde");
    em.persist(p1);
    em.persist(p2);
    utx.commit();
    // Store a simple cp.
    CategoryProductDto dto1 = new CategoryProductDto();
    dto1.setName("CP1");
    dto1.setDescription("Some Description");
    CategoryProduct cp = agent.createOrUpdate(dto1, "Test");
    assertThat(cp).as("CategroyProduct").isNotNull();
    dto1.setId(cp.getId());
    dto1.getProducts().add(new PicoProduct(p1.getId(), "irrelevant"));
    dto1.getPrices().put(PriceType.SALE, 200.0);
    long lastid = cp.getId();
    cp = agent.createOrUpdate(dto1, "TEst");
    assertThat(cp).as("CategroyProtuct").isNotNull().as("CategroyProtuct id is equal").returns(lastid, CategoryProduct::getId);
    assertThat(cp.getProducts()).contains(p1);
    assertThat(cp.getPrice(PriceType.SALE)).isEqualTo(200.0);
    Reply<Void> reply = agent.deleteCategoryProduct(cp.getId());
    assertThat(reply).isNotNull().returns(true, Reply::hasSucceded);
    CategoryProduct notFound = agent.findById(CategoryProduct.class, cp.getId());
    assertThat(notFound).isNull();
}
Also used : CategoryProduct(eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) CategoryProduct(eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) Reply(eu.ggnet.saft.api.Reply) CategoryProductDto(eu.ggnet.dwoss.uniqueunit.ee.entity.dto.CategoryProductDto) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) Test(org.junit.Test)

Example 4 with PicoProduct

use of eu.ggnet.dwoss.uniqueunit.api.PicoProduct in project dwoss by gg-net.

the class ProductListController method initialize.

/**
 * Adding the filters to the combo box. Setting the cell values and the
 * filtered list containing the data.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    tableView.getSelectionModel().setSelectionMode(MULTIPLE);
    menuTradeName.getItems().addAll(FXCollections.observableArrayList(TradeName.values()));
    menuProductGroup.getItems().addAll(ProductGroup.values());
    tableView.setOnDragDetected((MouseEvent event) -> {
        ArrayList<Product> selectedProducts = new ArrayList<>();
        selectedProducts.addAll(tableView.getSelectionModel().getSelectedItems());
        ArrayList<PicoProduct> selectedPicoProducts = new ArrayList<>();
        if (selectedProducts.isEmpty())
            return;
        Dragboard db = tableView.startDragAndDrop(TransferMode.ANY);
        ClipboardContent content = new ClipboardContent();
        selectedPicoProducts.addAll(selectedProducts.stream().map(p -> new PicoProduct(p.getId(), p.getName())).collect(Collectors.toList()));
        content.put(PICO_PRODUCT_DATA_FORMAT, selectedPicoProducts);
        db.setContent(content);
        event.consume();
    });
    setCellValues();
    progressBar.progressProperty().bind(LOADING_TASK.progressProperty());
    progressBar.visibleProperty().bind(LOADING_TASK.runningProperty());
    filteredProducts = new FilteredList<>(LOADING_TASK.getPartialResults(), p -> true);
    // filteredList does not allow sorting so it needs to be wrapped in a sortedList
    SortedList<Product> sortedProducts = new SortedList<>(filteredProducts);
    sortedProducts.comparatorProperty().bind(tableView.comparatorProperty());
    tableView.setItems(sortedProducts);
    editButton.disableProperty().bind(tableView.getSelectionModel().selectedItemProperty().isNull());
    Ui.progress().observe(LOADING_TASK);
    Ui.exec(LOADING_TASK);
}
Also used : java.util(java.util) Initializable(javafx.fxml.Initializable) TradeName(eu.ggnet.dwoss.rules.TradeName) javafx.scene.control(javafx.scene.control) URL(java.net.URL) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) MULTIPLE(javafx.scene.control.SelectionMode.MULTIPLE) Ui(eu.ggnet.saft.Ui) FxController(eu.ggnet.saft.api.ui.FxController) java.time(java.time) ProductTask(eu.ggnet.dwoss.uniqueunit.ui.ProductTask) SortedList(javafx.collections.transformation.SortedList) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) DateFormats(eu.ggnet.dwoss.util.DateFormats) javafx.scene.input(javafx.scene.input) Logger(org.slf4j.Logger) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Predicate(java.util.function.Predicate) ProductGroup(eu.ggnet.dwoss.rules.ProductGroup) FilteredList(javafx.collections.transformation.FilteredList) ClosedListener(eu.ggnet.saft.api.ui.ClosedListener) Collectors(java.util.stream.Collectors) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) FxSaft(eu.ggnet.saft.core.ui.FxSaft) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) SortedList(javafx.collections.transformation.SortedList) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct)

Example 5 with PicoProduct

use of eu.ggnet.dwoss.uniqueunit.api.PicoProduct in project dwoss by gg-net.

the class AssignmentController method dragAndDropHandling.

private void dragAndDropHandling() {
    /**
     * Start of the Drag an Drop from the unassigned units List.
     */
    unassignedUnitsList.setOnDragDetected(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            ArrayList<UniqueUnit> selected = new ArrayList<>();
            selected.addAll(unassignedUnitsList.getSelectionModel().getSelectedItems());
            if (selected.isEmpty() || unitCollectionList.getSelectionModel().getSelectedItem() == null)
                return;
            Dragboard db = unassignedUnitsList.startDragAndDrop(TransferMode.ANY);
            ClipboardContent content = new ClipboardContent();
            content.put(df, selected);
            db.setContent(content);
            L.info("DnD of {} Units started", selected.size());
            event.consume();
        }
    });
    /**
     * Handling the DragOver for only UniqueUnits with the right dataformat.
     */
    unassignedUnitsList.setOnDragOver(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent event) {
            if (event.getGestureSource() != unassignedUnitsList && event.getDragboard().hasContent(df)) {
                event.acceptTransferModes(TransferMode.ANY);
            }
            event.consume();
        }
    });
    /**
     * Handling the Dropped UniqueUnit and saving it.
     */
    unassignedUnitsList.setOnDragDropped(new EventHandler<DragEvent>() {

        @Override
        public void handle(final DragEvent event) {
            Dragboard db = event.getDragboard();
            if (db.hasContent(df)) {
                List<UniqueUnit> dragged = (List<UniqueUnit>) db.getContent(df);
                for (UniqueUnit draggedUnit : dragged) {
                    Optional.of(Dl.remote().lookup(UniqueUnitAgent.class).unsetUnitCollection(new PicoUnit(draggedUnit.getId(), "RefurbishedId=" + draggedUnit.getRefurbishId()))).filter(r -> {
                        if (!r.hasSucceded())
                            event.setDropCompleted(false);
                        return Ui.failure().handle(r);
                    }).ifPresent(c -> {
                        unassignedUnitsList.getItems().add(draggedUnit);
                        assignedUnitsList.getItems().remove(draggedUnit);
                    });
                }
                event.setDropCompleted(true);
            } else {
                event.setDropCompleted(false);
            }
            event.consume();
        }
    });
    /**
     * Start of the Drag an Drop from the assigned units List.
     */
    assignedUnitsList.setOnDragDetected(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            List<UniqueUnit> selected = new ArrayList<>();
            selected.addAll(assignedUnitsList.getSelectionModel().getSelectedItems());
            if (selected.isEmpty())
                return;
            Dragboard db = assignedUnitsList.startDragAndDrop(TransferMode.ANY);
            ClipboardContent content = new ClipboardContent();
            content.put(df, selected);
            db.setContent(content);
            L.info("DnD of {} Units started", selected.size());
            event.consume();
        }
    });
    /**
     * Handling the DragOver for only UniqueUnits with the right dataformat.
     */
    assignedUnitsList.setOnDragOver(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent event) {
            if (event.getGestureSource() != assignedUnitsList && event.getDragboard().hasContent(df)) {
                event.acceptTransferModes(TransferMode.ANY);
            }
            event.consume();
        }
    });
    /**
     * Handling the Dropped UniqueUnit and saving it.
     */
    assignedUnitsList.setOnDragDropped(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            if (db.hasContent(df)) {
                List<UniqueUnit> dragged = (List<UniqueUnit>) db.getContent(df);
                for (UniqueUnit draggedUnit : dragged) {
                    UnitCollection selectedCollection = unitCollectionList.getSelectionModel().getSelectedItem();
                    Optional.of(Dl.remote().lookup(UniqueUnitAgent.class).addToUnitCollection(new PicoUnit(draggedUnit.getId(), "RefurbishedId=" + draggedUnit.getRefurbishId()), selectedCollection.getId())).filter(r -> {
                        if (!r.hasSucceded())
                            event.setDropCompleted(false);
                        return Ui.failure().handle(r);
                    }).ifPresent(c -> {
                        assignedUnitsList.getItems().add(draggedUnit);
                        unassignedUnitsList.getItems().remove(draggedUnit);
                        event.setDropCompleted(true);
                    });
                }
                event.setDropCompleted(true);
            } else {
                event.setDropCompleted(false);
            }
            event.consume();
        }
    });
    /**
     * Handling the DragOver for only PicoProducts with the right dataformat.
     */
    productList.setOnDragOver(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent event) {
            if (event.getGestureSource() != productList && event.getDragboard().hasContent(ProductListController.PICO_PRODUCT_DATA_FORMAT)) {
                event.acceptTransferModes(TransferMode.ANY);
            }
            event.consume();
        }
    });
    /**
     * Handling the Dropped PicoProduct
     */
    productList.setOnDragDropped(new EventHandler<DragEvent>() {

        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasContent(ProductListController.PICO_PRODUCT_DATA_FORMAT)) {
                ArrayList<PicoProduct> products = (ArrayList<PicoProduct>) db.getContent(ProductListController.PICO_PRODUCT_DATA_FORMAT);
                productList.getItems().addAll(products.stream().filter(p -> !productList.getItems().contains(p)).collect(Collectors.toList()));
                success = true;
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });
}
Also used : EventHandler(javafx.event.EventHandler) Title(eu.ggnet.saft.api.ui.Title) java.util(java.util) Initializable(javafx.fxml.Initializable) ListView(javafx.scene.control.ListView) URL(java.net.URL) ListCell(javafx.scene.control.ListCell) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) MULTIPLE(javafx.scene.control.SelectionMode.MULTIPLE) Ui(eu.ggnet.saft.Ui) Dl(eu.ggnet.saft.Dl) FxController(eu.ggnet.saft.api.ui.FxController) StockApi(eu.ggnet.dwoss.stock.api.StockApi) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct) UniqueUnitAgent(eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent) javafx.scene.input(javafx.scene.input) Logger(org.slf4j.Logger) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) UnitCollection(eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection) Collectors(java.util.stream.Collectors) FXML(javafx.fxml.FXML) Guardian(eu.ggnet.saft.core.auth.Guardian) ActionEvent(javafx.event.ActionEvent) Reply(eu.ggnet.saft.api.Reply) Product(eu.ggnet.dwoss.uniqueunit.ee.entity.Product) ObservableValue(javafx.beans.value.ObservableValue) BorderPane(javafx.scene.layout.BorderPane) ChangeListener(javafx.beans.value.ChangeListener) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) UnitCollection(eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection) UniqueUnitAgent(eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent) PicoProduct(eu.ggnet.dwoss.uniqueunit.api.PicoProduct)

Aggregations

PicoProduct (eu.ggnet.dwoss.uniqueunit.api.PicoProduct)5 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)5 Ui (eu.ggnet.saft.Ui)3 Reply (eu.ggnet.saft.api.Reply)3 FxController (eu.ggnet.saft.api.ui.FxController)3 URL (java.net.URL)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 FXCollections (javafx.collections.FXCollections)3 ActionEvent (javafx.event.ActionEvent)3 FXML (javafx.fxml.FXML)3 Initializable (javafx.fxml.Initializable)3 MULTIPLE (javafx.scene.control.SelectionMode.MULTIPLE)3 javafx.scene.input (javafx.scene.input)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 StockApi (eu.ggnet.dwoss.stock.api.StockApi)2 PicoUnit (eu.ggnet.dwoss.uniqueunit.api.PicoUnit)2 UniqueUnitAgent (eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent)2 CategoryProduct (eu.ggnet.dwoss.uniqueunit.ee.entity.CategoryProduct)2