Search in sources :

Example 1 with DocumentType

use of eu.ggnet.dwoss.rules.DocumentType in project dwoss by gg-net.

the class PersistenceValidatorOperation method validateLogicTransaction.

/**
 * This Method Validate all LogicTransaction that will be given.
 * First it checks if all UUIds from the Document are in the Logictransaction.
 * Then check its in the opposite way.
 * <p/>
 * @param transactions
 * @param dossiers
 * @param m
 * @return
 */
private void validateLogicTransaction(List<Vm> vms, List<LogicTransaction> transactions, List<Dossier> dossiers, SubMonitor m) {
    Map<Long, Dossier> dossierMap = new HashMap<>();
    m.setWorkRemaining(transactions.size());
    for (Dossier dossier : dossiers) {
        dossierMap.put(dossier.getId(), dossier);
    }
    for (LogicTransaction logicTransaction : transactions) {
        m.worked(1, "Validate: LogicTransaction:" + logicTransaction.getId());
        Dossier dossier = dossierMap.get(logicTransaction.getDossierId());
        DocumentType type = getMostImportandDocument(dossierMap.get(logicTransaction.getDossierId())).getType();
        // TODO: Here you discard cases, not good.
        if (type != DocumentType.INVOICE && type != DocumentType.ORDER) {
            continue;
        }
        List<Integer> stockUuIds = toUniqueUnitIds(logicTransaction);
        if (!stockUuIds.containsAll(dossier.getRelevantUniqueUnitIds())) {
            error(vms, "Stock asynchron zu Dossier. LogicTransaction(id=" + logicTransaction.getId() + ", UniqueUnits=" + logicTransaction.getUnits() + ") ->" + "Dossier( id=" + dossier.getId() + ",customerId=" + dossier.getCustomerId() + ", relevant UniqueUnits=" + dossier.getRelevantUniqueUnitIds() + ")");
        }
        if (!dossier.getRelevantUniqueUnitIds().containsAll(stockUuIds)) {
            error(vms, "Dossier asynchron zu Stock." + "Dossier(id=" + dossier.getId() + ",customerId=" + dossier.getCustomerId() + ",relevant UniqueUnits=" + dossier.getRelevantUniqueUnitIds() + ") -> LogicTransaction(id=" + logicTransaction.getId() + ", UniqueUnits=" + logicTransaction.getUnits() + ")");
        }
        for (StockUnit stockUnit : logicTransaction.getUnits()) {
            Set<ConstraintViolation<StockUnit>> validateError = validator.validate(stockUnit);
            if (!validateError.isEmpty()) {
                error(vms, ConstraintViolationFormater.toSingleLine(validateError));
            }
        }
    }
    m.finish();
}
Also used : LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) DocumentType(eu.ggnet.dwoss.rules.DocumentType) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Example 2 with DocumentType

use of eu.ggnet.dwoss.rules.DocumentType in project dwoss by gg-net.

the class PersistenceValidatorOperation method validateRedTape.

// HINT: See validate in RedTapeUpdateWorkflow.
/**
 * This method checks given Dossiers.
 * It checks followed things:
 * - It is only one Document of every existing Type active but it must one Document active.
 * - Every Position from type UNIT have a existing UniqueUnit.
 * - It exist a SopoAuftrag to a Dossier. <---- TODO: It must a status of a Dossier where a SopoAuftrag exist, not Canceled ---->
 * - and a BothSide check if the Positions of a Dossier are in the SopoAuftrag and vice vesa.
 * <p/>
 * @param dossiers
 * @param units    Map&lt;uniqueUnitId, uniqueUnits&rt;
 * @param auftrags
 * @param m
 * @return
 */
private void validateRedTape(List<Vm> vms, List<Dossier> dossiers, Map<Integer, UniqueUnit> units, SubMonitor m) {
    m.setWorkRemaining(dossiers.size());
    m.start();
    for (Dossier dossier : dossiers) {
        m.worked(1, "Validate: Dossier:" + dossier.getId());
        Set<ConstraintViolation<Dossier>> validateError = validator.validate(dossier);
        if (!validateError.isEmpty()) {
            error(vms, ConstraintViolationFormater.toSingleLine(validateError));
            continue;
        }
        for (DocumentType type : DocumentType.values()) {
            Set<Document> documents = dossier.getDocuments();
            List<Document> existingDocumentWithType = new ArrayList<>();
            for (Document document : documents) {
                if (document.getType() == type)
                    existingDocumentWithType.add(document);
            }
            if (!existingDocumentWithType.isEmpty() && !dossier.getActiveDocuments(type).isEmpty() && dossier.getActiveDocuments(type).size() > 1)
                error(vms, "Dossier(id=" + dossier.getId() + ",customerId=" + dossier.getCustomerId() + "): Es ist mehr als ein Dokument vom Typ " + type.getName() + " ist active.");
        }
        for (Document document : dossier.getDocuments()) {
            for (Position position : document.getPositions(PositionType.UNIT).values()) {
                if (!units.containsKey(position.getUniqueUnitId())) {
                    error(vms, "Dossier(id=" + dossier.getId() + ",customerId=" + dossier.getCustomerId() + ") enhält Position(type=Unit,uniqueUnitId=" + position.getUniqueUnitId() + "): UniqueUnit existiert nicht.");
                }
            }
        }
        if (!dossier.getActiveDocuments(DocumentType.ORDER).isEmpty() && dossier.getActiveDocuments(DocumentType.ORDER).get(0).getConditions().contains(Document.Condition.CANCELED)) {
            continue;
        } else if (dossier.isClosed()) {
            continue;
        }
    }
    m.finish();
}
Also used : DocumentType(eu.ggnet.dwoss.rules.DocumentType)

Example 3 with DocumentType

use of eu.ggnet.dwoss.rules.DocumentType in project dwoss by gg-net.

the class SelectExistingReportViewTryout method main.

public static void main(String[] args) {
    ReportAgent rastub = new ReportAgent() {

        private int counter = 0;

        // <editor-fold defaultstate="collapsed" desc="Unused Methods">
        @Override
        public List<SimpleReportLine> findSimple(SearchParameter search, int firstResult, int maxResults) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<ReportLine> find(SearchParameter search, int firstResult, int maxResults) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public long count(SearchParameter search) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ViewReportResult prepareReport(ReportParameter p, boolean loadUnreported) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<ReportLine> findReportLinesByDocumentType(DocumentType type, Date from, Date till) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Report store(Report report, Collection<Storeable> storeables) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public ViewReportResult findReportResult(long reportId) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public List<ReportLine> findAllReportLinesReverse(int firstResult, int maxResults) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        @Override
        public Set<ReportLine> attachDanglingComplaints(TradeName type, Date till) {
            // 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) {
            // 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.");
        }

        @Override
        public boolean updateReportLineComment(int optLock, long reportId, String comment) {
            // To change body of generated methods, choose Tools | Templates.
            throw new UnsupportedOperationException("Not supported yet.");
        }

        // </editor-fold>
        @Override
        public Reply<String> updateReportName(Report.OptimisticKey key, String name) {
            System.out.println("Report Name updated with " + name + " calles");
            counter++;
            if ((counter % 2) != 0) {
                System.out.println("Counter=" + counter + " simulating Error");
                return Reply.failure("Counter=" + counter + " simulating Error");
            } else {
                System.out.println("Counter=" + counter + " simulating Success");
                return Reply.success(name);
            }
        }
    };
    Dl.remote().add(ReportAgent.class, rastub);
    UiCore.startSwing(() -> new JLabel("Main Applikation"));
    final Date today = new Date();
    final Date enddate = new Date();
    final Date startdate = new Date();
    final Set<TradeName> trades = new HashSet<>();
    trades.add(TradeName.HP);
    trades.add(TradeName.ACER);
    // build some sample Reports
    List<Report> allReports = new ArrayList();
    for (int i = 0; i < 8; i++) {
        for (TradeName traden : trades) {
            startdate.setYear(62 + i);
            long sum = today.getTime() + startdate.getTime();
            Date sumDate = new Date(sum);
            String name = "Report: " + i + "-" + traden + "-" + sumDate.toString();
            Report e = new Report(name, traden, sumDate, enddate);
            allReports.add(e);
        }
    }
    Ui.exec(() -> {
        Ui.build().fx().show(() -> allReports, () -> new SelectExistingReportView());
    });
}
Also used : ReportLine(eu.ggnet.dwoss.report.ee.entity.ReportLine) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) ReportParameter(eu.ggnet.dwoss.report.ee.ReportAgent.ReportParameter) ReportAgent(eu.ggnet.dwoss.report.ee.ReportAgent) SearchParameter(eu.ggnet.dwoss.report.ee.ReportAgent.SearchParameter) SimpleReportLine(eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine) SelectExistingReportView(eu.ggnet.dwoss.report.ui.cap.support.SelectExistingReportView) TradeName(eu.ggnet.dwoss.rules.TradeName) Report(eu.ggnet.dwoss.report.ee.entity.Report) DocumentType(eu.ggnet.dwoss.rules.DocumentType) JLabel(javax.swing.JLabel) LockModeType(javax.persistence.LockModeType)

Example 4 with DocumentType

use of eu.ggnet.dwoss.rules.DocumentType in project dwoss by gg-net.

the class RedTapeWorkflow method validate.

protected void validate(Document altered, Document previous) {
    // Check that the in db is correct
    Dossier dos = previous.getDossier();
    if (altered.getOptLock() != previous.getOptLock())
        throw new IllegalStateException("The Previous Document has a different optLock, so it was changed since the last read. Please try cancel, refresh the dossier and that the change.");
    if (previous.getConditions().contains(Document.Condition.CANCELED))
        throw new IllegalStateException("The Previous Document is canceled.\nAltered: " + altered + "\nPrevious: " + previous);
    for (DocumentType type : DocumentType.values()) {
        if (type == DocumentType.CREDIT_MEMO || type == DocumentType.COMPLAINT || type == DocumentType.ANNULATION_INVOICE)
            continue;
        if (dos.getActiveDocuments(type).size() > 1)
            throw new IllegalStateException("The Dossier(id=" + dos.getId() + ") has more than one active Document of Type " + type + "\n" + dos + "\n" + dos.getActiveDocuments(type));
    }
    if (!previous.isActive())
        throw new IllegalStateException("The Previous Document is not active.\nAltered: " + altered + "\nPrevious: " + previous);
    // TODO: Check, that the Type Change is allowed (e.g. from RETURNS to CAPITAL_ASSET obviously not
    if (altered.getType() != previous.getType())
        return;
    if (!previous.isClosed())
        return;
    // A Complaint is the only Document, that may be reported twice, so a reopening is possible.
    if (previous.getType() == DocumentType.COMPLAINT)
        return;
    // Now to the restrictive handling of closed documents.
    if (!dos.changesAllowed(altered.getDossier()))
        throw new IllegalStateException("The Dossier is clossed and supplied changes are not allowed." + "\nAltered: " + altered.getDossier() + "\nPrevious: " + dos);
    DocumentEquals documentEquals = new DocumentEquals().ignore(ID, ACTIVE, HISTORY, PREDECESSOR, DIRECTIVE, CONDITIONS, FLAGS, SETTLEMENTS).ignoreAddresses().igonrePositionOrder().ignorePositions(PositionType.COMMENT);
    if (!documentEquals.equals(previous, altered))
        throw new IllegalStateException("The Document is clossed and supplied changes are not allowed." + documentEquals.equalsMessage(previous, altered));
}
Also used : DocumentEquals(eu.ggnet.dwoss.redtape.ee.entity.util.DocumentEquals) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DocumentType(eu.ggnet.dwoss.rules.DocumentType)

Aggregations

DocumentType (eu.ggnet.dwoss.rules.DocumentType)4 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)1 DocumentEquals (eu.ggnet.dwoss.redtape.ee.entity.util.DocumentEquals)1 ReportAgent (eu.ggnet.dwoss.report.ee.ReportAgent)1 ReportParameter (eu.ggnet.dwoss.report.ee.ReportAgent.ReportParameter)1 SearchParameter (eu.ggnet.dwoss.report.ee.ReportAgent.SearchParameter)1 Report (eu.ggnet.dwoss.report.ee.entity.Report)1 ReportLine (eu.ggnet.dwoss.report.ee.entity.ReportLine)1 SimpleReportLine (eu.ggnet.dwoss.report.ee.entity.partial.SimpleReportLine)1 SelectExistingReportView (eu.ggnet.dwoss.report.ui.cap.support.SelectExistingReportView)1 TradeName (eu.ggnet.dwoss.rules.TradeName)1 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)1 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)1 LockModeType (javax.persistence.LockModeType)1 JLabel (javax.swing.JLabel)1