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