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;
}
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);
});
});
}
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();
}
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);
}
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();
}
});
}
Aggregations