Search in sources :

Example 1 with DocumentEquals

use of eu.ggnet.dwoss.redtape.ee.entity.util.DocumentEquals 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

Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)1 DocumentEquals (eu.ggnet.dwoss.redtape.ee.entity.util.DocumentEquals)1 DocumentType (eu.ggnet.dwoss.rules.DocumentType)1