use of eu.ggnet.dwoss.util.UserInfoException in project dwoss by gg-net.
the class CreateSimpleActionTryout method tryout.
@Test
public void tryout() throws InterruptedException {
JPanel p = new JPanel();
JButton b = new JButton("Press to close");
b.setPreferredSize(new Dimension(200, 50));
CountDownLatch l = new CountDownLatch(1);
b.addActionListener(e -> {
l.countDown();
});
p.add(new JButton(new CreateSimpleAction()));
p.add(b);
Dl.remote().add(StockAgent.class, new StockAgent() {
@Override
public <T> List<T> findAll(Class<T> entityClass) {
if (entityClass.equals(Stock.class))
return (List<T>) Arrays.asList(new Stock(0, "Rotes Lager"), new Stock(1, "Blaues Lager"));
return null;
}
@Override
public List<StockUnit> findStockUnitsByRefurbishIdEager(List<String> refurbishIds) {
if (refurbishIds.contains("1")) {
Stock s = new Stock(0, "Lager1");
StockUnit s1 = new StockUnit("1", "Gerät Eins", 1);
s1.setStock(s);
return Arrays.asList(s1);
}
return Collections.EMPTY_LIST;
}
// <editor-fold defaultstate="collapsed" desc="Unused Methodes">
@Override
public StockUnit findStockUnitByUniqueUnitIdEager(Integer uniqueUnitId) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public StockUnit findStockUnitByRefurbishIdEager(String refurbishId) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public List<StockTransaction> findStockTransactionEager(StockTransactionType type, StockTransactionStatusType statusType, int start, int amount) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T persist(T t) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T merge(T t) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> void delete(T t) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public StockTransaction findOrCreateRollInTransaction(int stockId, String userName, String comment) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> long count(Class<T> entityClass) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> List<T> findAll(Class<T> entityClass, int start, int amount) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> List<T> findAllEager(Class<T> entityClass) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> List<T> findAllEager(Class<T> entityClass, int start, int amount) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T findById(Class<T> entityClass, Object id) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T findById(Class<T> entityClass, Object id, LockModeType lockModeType) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T findByIdEager(Class<T> entityClass, Object id) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public <T> T findByIdEager(Class<T> entityClass, Object id, LockModeType lockModeType) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
Dl.remote().add(StockTransactionProcessor.class, new StockTransactionProcessor() {
@Override
public SortedMap<Integer, String> perpareTransfer(List<StockUnit> stockUnits, int destinationStockId, String arranger, String comment) throws UserInfoException {
SortedMap<Integer, String> r = new TreeMap<>();
r.put(1, "1");
return r;
}
// <editor-fold defaultstate="collapsed" desc="Unused Methodes">
@Override
public List<Integer> rollIn(List<StockTransaction> detachtedTransactions, String arranger) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void cancel(StockTransaction transaction, String arranger, String comment) throws UserInfoException {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void commission(List<StockTransaction> transactions, String picker, String deliverer) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void receive(List<StockTransaction> transactions, String deliverer, String reciever) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void removeFromPreparedTransaction(String refurbishId, String arranger, String comment) throws UserInfoException {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
});
Guardian guardianMock = mock(Guardian.class);
given(guardianMock.getUsername()).willAnswer(i -> "Testuser");
Dl.local().add(Guardian.class, guardianMock);
UiCore.startSwing(() -> p);
l.await();
}
use of eu.ggnet.dwoss.util.UserInfoException in project dwoss by gg-net.
the class RedTapeCloserOperationIT method testDayClosing.
/**
* Tests if something gets closed and if the appropriated stock units are gone.
* <p>
* @throws UserInfoException
*/
@Test
public void testDayClosing() throws UserInfoException {
assertFalse(customerGenerator.makeCustomers(10).isEmpty());
receiptCustomers = customerGenerator.makeReceiptCustomers(ACER);
systemCustomers = customerGenerator.makeSpecialCustomers(BLOCK);
assertFalse(systemCustomers == null);
assertFalse(receiptCustomers == null);
assertFalse(receiptGenerator.makeUniqueUnits(200, true, true).isEmpty());
assertFalse(redTapeGenerator.makeSalesDossiers(30).isEmpty());
// dossier ids from created blockers
List<Long> blockerIds = buildBlocker().stream().mapToLong(d -> d.getId()).boxed().collect(Collectors.toList());
assertThat(stockAgent.findAllEager(StockTransaction.class).stream().map(StockTransaction::getPositions).flatMap(Collection::stream).anyMatch(t -> t.getStockUnit() != null)).overridingErrorMessage("Their exist a StockTransaction, which is not complete (blocking a stockUnit), impossible!").isFalse();
long stockUnits = stockAgent.count(StockUnit.class);
assertThat(stockUnits).isPositive();
List<LogicTransaction> allLts = stockAgent.findAllEager(LogicTransaction.class);
assertThat(allLts.size()).overridingErrorMessage("No LogicTransactions exist, impossible!").isPositive();
redTapeCloser.executeManual("Junit");
List<Dossier> blockerDossiers = new ArrayList<>();
for (Long blockerId : blockerIds) {
blockerDossiers.add(redTapeAgent.findByIdEager(Dossier.class, blockerId));
}
assertEquals("More/Less Blockers than expected passed closing", 3, blockerDossiers.stream().filter(d -> d.isClosed()).collect(Collectors.toList()).size());
warnIfStockSizeDidNotChange(stockUnits);
List<Dossier> allDossiers = redTapeAgent.findAllEager(Dossier.class);
for (Dossier dos : allDossiers) {
if (dos.isClosed()) {
for (Document doc : dos.getActiveDocuments()) {
// These are just ignored.
if (doc.containsAny(CANCELED))
continue;
for (Integer uuId : doc.getPositionsUniqueUnitIds()) {
StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(uuId);
assertNull("There is a StockUnit for a closed Dossier (doc.id= " + doc.getId() + "):\n" + dos.toMultiLine() + "\n\n" + su + "\n\n" + "Original LTS: " + allLts.stream().filter(x -> x.getUnits().contains(su)).findAny().orElse(null), su);
}
}
} else {
for (Integer uuId : dos.getRelevantUniqueUnitIds()) {
StockUnit su = stockAgent.findStockUnitByUniqueUnitIdEager(uuId);
assertNotNull("There is no StockUnit for an open Dossier\n" + dos, su);
}
}
}
long reportSize = reportAgent.count(ReportLine.class);
assertFalse(reportSize == 0);
redTapeCloser.executeManual("Junit");
assertEquals("Second call should not add anything new", reportSize, reportAgent.count(ReportLine.class));
}
use of eu.ggnet.dwoss.util.UserInfoException in project dwoss by gg-net.
the class RedTapeOperationComplaintIT method testCreditMemo.
@Test
public void testCreditMemo() throws UserInfoException {
long customerId = customerGenerator.makeCustomer();
List<UniqueUnit> units = receiptGenerator.makeUniqueUnits(2, true, true);
UniqueUnit uu1 = units.get(0);
UniqueUnit uu2 = units.get(1);
Dossier dos = redTapeOperation.create(customerId, true, "Me");
Document doc = dos.getActiveDocuments(DocumentType.ORDER).get(0);
assertThat(doc).overridingErrorMessage("Expected active document Order, got null. Dossier: " + dos.toMultiLine()).isNotNull();
// Create Positions
Position p1 = NaivBuilderUtil.unit(uu1);
Position p2 = NaivBuilderUtil.unit(uu2);
doc.append(p1);
doc.append(p2);
// add units to LogicTransaction
unitOverseer.lockStockUnit(dos.getId(), uu1.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
unitOverseer.lockStockUnit(dos.getId(), uu2.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID));
doc = redTapeOperation.update(doc, null, "JUnit");
doc.add(Document.Condition.PAID);
doc.add(Document.Condition.PICKED_UP);
doc.setType(DocumentType.INVOICE);
doc = redTapeOperation.update(doc, null, "JUnit");
LogicTransaction lt = supportBean.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must exists", lt);
assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
assertEquals("Document should have exactly two possitions", 2, doc.getPositions().size());
doc.setType(DocumentType.COMPLAINT);
doc.setDirective(Document.Directive.WAIT_FOR_COMPLAINT_COMPLETION);
doc.removeAt(p2.getId());
assertEquals("Document should have exactly one possitions", 1, doc.getPositions().size());
doc = redTapeOperation.update(doc, null, "JUnit Test");
lt = supportBean.findByDossierId(doc.getDossier().getId());
assertNotNull("A LogicTrasaction must still exists", lt);
assertEquals("The Size of the LogicTransaction", 2, lt.getUnits().size());
Arrays.asList(uu1.getId(), uu2.getId());
assertTrue("Should contain the same UniqueUnitIds", lt.getUnits().stream().map(su -> su.getUniqueUnitId()).collect(Collectors.toSet()).containsAll(Arrays.asList(uu1.getId(), uu2.getId())));
doc.add(Document.Condition.REJECTED);
redTapeOperation.update(doc, null, "JUnit Test");
}
use of eu.ggnet.dwoss.util.UserInfoException in project dwoss by gg-net.
the class TableToExcelExporter method export.
/**
* Export a JTable view to a temporary .xls file.
* Supported cell renderer:<ol>
* </ol>
* <p/>
* @param table
* @param fileName
* @return
* @throws de.dw.util.UserInfoException
*/
public static FileJacket export(JTable table, String fileName) throws UserInfoException {
int visibleRowCount = table.getRowCount();
if (visibleRowCount < 1)
throw new UserInfoException("Die Tabelle enthält keine Daten.");
int columnCount = table.getColumnCount();
TableModel model = table.getModel();
List<Object[]> rows = new ArrayList<>();
for (int i = 0; i < visibleRowCount; i++) {
Object[] row = new Object[columnCount + 1];
for (int j = 0; j < columnCount; j++) {
// convert value of table to specified value
Object value = model.getValueAt(table.convertRowIndexToModel(i), table.convertColumnIndexToModel(j));
if (value instanceof Date) {
row[j] = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Locale.GERMANY).format(value);
continue;
}
// check for enums with getNote() or getName() via PojoUtil reflection
if (value instanceof Enum) {
try {
row[j] = PojoUtil.getValue("note", value);
continue;
} catch (RuntimeException e) {
try {
row[j] = PojoUtil.getValue("name", value);
continue;
} catch (RuntimeException ex) {
}
}
}
row[j] = value;
}
rows.add(row);
}
STable sTable = new STable();
for (int i = 0; i < columnCount; i++) {
int width = table.getColumnModel().getColumn(i).getWidth();
sTable.add(new STableColumn(table.getColumnName(i), width / 5));
}
sTable.setModel(new STableModelList(rows));
CCalcDocument cdoc = new TempCalcDocument(fileName);
cdoc.add(new CSheet("Sheet1", sTable));
File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
return new FileJacket(fileName, ".xls", file);
}
use of eu.ggnet.dwoss.util.UserInfoException in project dwoss by gg-net.
the class ResolveRepaymentController method handleResolveButtonAction.
@FXML
public void handleResolveButtonAction() {
if (sopoField.getText().isEmpty()) {
sopoField.setText(" IDENTIFIER EINGEBEN!!!!!");
return;
}
resolveButton.setDisable(true);
ForkJoinPool.commonPool().execute(() -> {
try {
ResolveResult result = Dl.remote().lookup(ResolveRepayment.class).resolveUnit(sopoField.getText(), contractor, Dl.local().lookup(Guardian.class).getUsername(), commentField.getText());
Ui.build(sopoField).alert().title("Repayment resolved").message("Gutschrift gegenüber " + contractor.getName() + " aufgelöst").nl("Stock: " + result.stockMessage).nl("RedTape: " + result.redTapeMessage).nl("Report: " + result.reportMessage).show(AlertType.INFO);
reset();
} catch (UserInfoException ex) {
Ui.handle(ex);
} finally {
reset();
}
});
}
Aggregations