Search in sources :

Example 71 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class UniqueUnitGenerator method makeUniqueUnit.

/**
 * Generates a random Unit, based on the Product and from the contractor.
 * <p/>
 * @param product    the product as basis, if null ignored.
 * @param contractor the contractor, if null randomly selected.
 * @return the generated unit.
 */
private UniqueUnit makeUniqueUnit(TradeName contractor, ProductGroup group, Product product) {
    if (contractor == null)
        throw new RuntimeException("As the Contractor is Mandator specific, it must not be null, even for generated Units.");
    String serial = (product == null ? RandomStringUtils.randomAlphanumeric(22).toUpperCase() : product.getPartNo().replaceAll("\\.", "") + RandomStringUtils.randomAlphanumeric(12).toUpperCase());
    if (group == null && product != null)
        group = product.getGroup();
    UniqueUnit uu = new UniqueUnit();
    uu.addHistory("Generated by makeUniqueUnit(contractor=" + contractor + ", group=" + group + ", product=" + product + ")");
    // Not perfect, but works.
    Integer refurbisId = CONTRACTOR_REFURBISHIDS.get(contractor);
    if (refurbisId == null)
        refurbisId = 123456;
    else
        refurbisId++;
    CONTRACTOR_REFURBISHIDS.put(contractor, refurbisId);
    uu.setIdentifier(UniqueUnit.Identifier.REFURBISHED_ID, refurbisId.toString());
    uu.setIdentifier(UniqueUnit.Identifier.SERIAL, serial);
    uu.setContractor(contractor);
    // Random Date, may 3 years in the past.
    uu.setMfgDate(DateUtils.addDays(new Date(), -1 * R.nextInt(1000)));
    uu.setCondition(UniqueUnit.Condition.values()[R.nextInt(UniqueUnit.Condition.values().length)]);
    uu.setEquipments(randomSet(group == null ? UniqueUnit.Equipment.values() : UniqueUnit.Equipment.getEquipments(group).toArray(new UniqueUnit.Equipment[0])));
    uu.setComments(randomSet(UniqueUnit.StaticComment.values()));
    uu.setInternalComments(randomSet(UniqueUnit.StaticInternalComment.values()));
    if ((Math.random() * 100) > 75) {
        uu.setWarranty(WARRANTY_TILL_DATE);
        uu.setWarrentyValid(new Date((long) (System.currentTimeMillis() + Math.random() * 21600000000L)));
    }
    return uu;
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)

Example 72 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class UniqueUnitEao method find.

/**
 * Returns a list of UniqueUnits which match the search string.
 *
 * @param search the search string, may start or end with '*' as wildcard, may not be null
 * @param start  the start of the result
 * @param limit  the limit of the result
 * @return a list of UniqueUnits which match the search string.
 */
// TODO: Remove Copypast
public List<UniqueUnit> find(String search, int start, int limit) {
    List<UniqueUnit> result = Collections.EMPTY_LIST;
    if (search == null)
        return result;
    // TODO: Replace native Query
    Query query = em.createNativeQuery("SELECT a.id FROM UniqueUnit as a join UniqueUnit_identifiers as b on a.id = b.UniqueUnit_id where b.identifiers like :search");
    query.setParameter("search", search.replaceAll("\\*", "%"));
    query.setFirstResult(start);
    query.setMaxResults(limit);
    List<Integer> ids = (List<Integer>) query.getResultList();
    return findByIds(ids);
}
Also used : BigInteger(java.math.BigInteger) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) JPAQuery(com.mysema.query.jpa.impl.JPAQuery)

Example 73 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class UniqueUnitEao method findByPartialIdentifier.

/**
 * Returns a list of UniqueUnits which match the search string.
 *
 * @param type   the type, if null an empty list is returned
 * @param search the search string, may start or end with '*' as wildcard, may not be null
 * @return a list of UniqueUnits which match the search string.
 */
public List<UniqueUnit> findByPartialIdentifier(UniqueUnit.Identifier type, String search) {
    List<UniqueUnit> result = Collections.EMPTY_LIST;
    if (type == null)
        return result;
    if (search == null)
        return result;
    // TODO: Replace native Query
    Query query = em.createNativeQuery("SELECT a.id FROM UniqueUnit as a join UniqueUnit_identifiers as b on a.id = b.UniqueUnit_id where b.identifiers_KEY = :type and b.identifiers like :search");
    query.setParameter("type", type.ordinal());
    query.setParameter("search", search.replaceAll("\\*", "%"));
    List<Integer> ids = (List<Integer>) query.getResultList();
    return findByIds(ids);
}
Also used : BigInteger(java.math.BigInteger) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) JPAQuery(com.mysema.query.jpa.impl.JPAQuery)

Example 74 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class AssignmentController method unassignUnit.

@FXML
private void unassignUnit(ActionEvent event) {
    List<UniqueUnit> selected = assignedUnitsList.getSelectionModel().getSelectedItems();
    if (!selected.isEmpty()) {
        for (UniqueUnit uu : selected) {
            Optional.of(Dl.remote().lookup(UniqueUnitAgent.class).unsetUnitCollection(new PicoUnit(uu.getId(), "RefurbishedId=" + uu.getRefurbishId()))).filter(r -> {
                return Ui.failure().handle(r);
            }).ifPresent(c -> {
                unassignedUnitsList.getItems().add(uu);
                assignedUnitsList.getItems().remove(uu);
            });
        }
        unassignedUnitsList.getSelectionModel().clearSelection();
    }
}
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) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) FXML(javafx.fxml.FXML)

Example 75 with UniqueUnit

use of eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit in project dwoss by gg-net.

the class AssignmentController method assignUnit.

@FXML
private void assignUnit(ActionEvent event) {
    List<UniqueUnit> selected = unassignedUnitsList.getSelectionModel().getSelectedItems();
    UnitCollection selectedCollection = unitCollectionList.getSelectionModel().getSelectedItem();
    if (!selected.isEmpty()) {
        for (UniqueUnit uu : selected) {
            Dl.remote().lookup(UniqueUnitAgent.class).addToUnitCollection(new PicoUnit(uu.getId(), "RefurbishedId=" + uu.getRefurbishId()), selectedCollection.getId());
            assignedUnitsList.getItems().add(uu);
            unassignedUnitsList.getItems().remove(uu);
        }
        unassignedUnitsList.getSelectionModel().clearSelection();
    }
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) UnitCollection(eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection) PicoUnit(eu.ggnet.dwoss.uniqueunit.api.PicoUnit) UniqueUnitAgent(eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent) FXML(javafx.fxml.FXML)

Aggregations

UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)88 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)38 Product (eu.ggnet.dwoss.uniqueunit.ee.entity.Product)31 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)27 Test (org.junit.Test)21 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)20 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)16 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)13 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)8 StockTransaction (eu.ggnet.dwoss.stock.ee.entity.StockTransaction)8 UnitCollection (eu.ggnet.dwoss.uniqueunit.ee.entity.UnitCollection)7 java.util (java.util)7 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)6 ProductSpec (eu.ggnet.dwoss.spec.ee.entity.ProductSpec)6 Stock (eu.ggnet.dwoss.stock.ee.entity.Stock)6 UniqueUnitAgent (eu.ggnet.dwoss.uniqueunit.ee.UniqueUnitAgent)6 FileJacket (eu.ggnet.dwoss.util.FileJacket)6 DocumentType (eu.ggnet.dwoss.rules.DocumentType)5 Collectors (java.util.stream.Collectors)5