Search in sources :

Example 6 with DocumentHistory

use of eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory in project dwoss by gg-net.

the class RedTapeUpdateComplaintWorkflow method execute.

/**
 * Executes the Workflow and returns a Document.
 *
 * @return a Document.
 */
@Override
public Document execute() {
    Document previous = new DocumentEao(redTapeEm).findById(altered.getId(), LockModeType.PESSIMISTIC_WRITE);
    if (altered.equalsContent(previous))
        return altered;
    L.info("Workflow on {} by {}", DocumentFormater.toSimpleLine(altered), arranger);
    validate(altered, previous);
    if (altered.getType() == previous.getType())
        validateChangeAllowed(altered, previous);
    Document newDocument = refreshAndPrepare(altered, previous);
    newDocument.setHistory(new DocumentHistory(arranger, "Update durch " + this.getClass().getSimpleName()));
    redTapeEm.persist(newDocument);
    // Writing new document an gennerating the id;
    redTapeEm.flush();
    L.debug("Returning {} with {}", newDocument, newDocument.getDossier());
    return newDocument;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Example 7 with DocumentHistory

use of eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory in project dwoss by gg-net.

the class RedTapeUpdateInvoiceWorkflow method execute.

@Override
public Document execute() {
    Document previous = new DocumentEao(redTapeEm).findById(altered.getId(), LockModeType.PESSIMISTIC_WRITE);
    if (altered.equalsContent(previous))
        return altered;
    L.info("Workflow on {} by {}", DocumentFormater.toSimpleLine(altered), arranger);
    validate(altered, previous);
    Document newDocument = refreshAndPrepare(altered, previous);
    if (!newDocument.isClosed()) {
        equilibrateLogicTransaction(newDocument);
        if (altered.getType() != previous.getType()) {
            // Allwasy set in the previos Order
            previous.setDirective(Document.Directive.NONE);
            generateIdentifier(newDocument);
        }
    }
    if (!altered.isStillExactlyBriefed(previous))
        newDocument.remove(Flag.CUSTOMER_EXACTLY_BRIEFED);
    newDocument.setHistory(new DocumentHistory(arranger, "Update durch " + this.getClass().getSimpleName()));
    redTapeEm.persist(newDocument);
    // Writing new document an gennerating the id;
    redTapeEm.flush();
    L.debug("Returning {} with {}", newDocument, newDocument.getDossier());
    validateAfter(newDocument.getDossier());
    return newDocument;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Example 8 with DocumentHistory

use of eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory in project dwoss by gg-net.

the class RedTapeWorkflow method refreshAndPrepare.

/**
 * Clones the new Document from the altered Document, sets all detached Entities and updates the active status.
 * <p>
 * @param alteredDetachedDocument
 * @param previousDocument
 * @return
 */
protected Document refreshAndPrepare(Document alteredDetachedDocument, Document previousDocument) {
    // Partiall Clone our next Document
    Document newDocument = alteredDetachedDocument.partialClone();
    // Replace detached entities
    AddressEao addEao = new AddressEao(redTapeEm);
    Address invoiceAddress = addEao.findById(alteredDetachedDocument.getInvoiceAddress().getId());
    Address shippingAddress = addEao.findById(alteredDetachedDocument.getShippingAddress().getId());
    newDocument.setInvoiceAddress(invoiceAddress);
    newDocument.setShippingAddress(shippingAddress);
    newDocument.setHistory(new DocumentHistory(arranger, "Update durch Workflow"));
    // Set automatic Information
    newDocument.setDossier(previousDocument.getDossier());
    newDocument.setPredecessor(previousDocument);
    newDocument.setActive(true);
    if (previousDocument.getType() == newDocument.getType()) {
        previousDocument.setActive(false);
        // A Complaint gets reopend on condition change.
        if (newDocument.getType() == DocumentType.COMPLAINT && !previousDocument.getConditions().equals(newDocument.getConditions())) {
            newDocument.setClosed(false);
            newDocument.getDossier().setClosed(false);
        }
    } else {
        // On Document Type Change, the dossier gets reopened and some cleanup is happening.
        newDocument.getDossier().setClosed(false);
        newDocument.setClosed(false);
        newDocument.setIdentifier(null);
        newDocument.setActual(new Date());
        newDocument.remove(Document.Flag.CUSTOMER_BRIEFED);
        newDocument.remove(Document.Flag.CUSTOMER_EXACTLY_BRIEFED);
    }
    L.debug("Prepared {}", newDocument);
    return newDocument;
}
Also used : Address(eu.ggnet.dwoss.redtape.ee.entity.Address) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) Date(java.util.Date) AddressEao(eu.ggnet.dwoss.redtape.ee.eao.AddressEao)

Example 9 with DocumentHistory

use of eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory in project dwoss by gg-net.

the class DocumentExactlyBriefedTest method testChangesWithNoImpact.

@Test
public void testChangesWithNoImpact() {
    assertTrue("Documents difference must not invalidate exactly briefed:\n" + doc1 + "\n" + doc2, doc1.isStillExactlyBriefed(doc2));
    doc1.setActive(!doc2.isActive());
    assertTrue("Active change must not invalidate exactly briefed:\n" + doc1 + "\n" + doc2, doc1.isStillExactlyBriefed(doc2));
    doc1.setHistory(new DocumentHistory("Junit", "Test"));
    assertTrue("History change must not invalidate exactly briefed:\n" + doc1 + "\n" + doc2, doc1.isStillExactlyBriefed(doc2));
    doc1.setPredecessor(doc2);
    assertTrue("Predecessor change must not invalidate exactly briefed:\n" + doc1 + "\n" + doc2, doc1.isStillExactlyBriefed(doc2));
    doc1.setClosed(true);
    assertFalse("Documents must have different Flags", doc1.isClosed() == doc2.isClosed());
    assertTrue("Flag change must not invalidate exactly briefed:\n" + doc1 + "\n" + doc2, doc1.isStillExactlyBriefed(doc2));
    doc1.add(Document.Condition.CONFIRMED);
    assertFalse("Documents must have different Conditions", doc1.getConditions().equals(doc2.getConditions()));
    assertTrue("Condition change must not invalidate exactly briefed:\n" + doc1 + "\n" + doc2, doc1.isStillExactlyBriefed(doc2));
    doc1.setDirective(Document.Directive.PREPARE_SHIPPING);
    assertFalse("Documents must have different Directives", doc1.getDirective().equals(doc2.getDirective()));
    assertTrue("Directive change must not invalidate exactly briefed:\n" + doc1 + "\n" + doc2, doc1.isStillExactlyBriefed(doc2));
    doc1.setIdentifier("Ein Identifier");
    assertTrue("Identifier change must not invalidate exactly briefed:\n" + doc1 + "\n" + doc2, doc1.isStillExactlyBriefed(doc2));
}
Also used : DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)

Example 10 with DocumentHistory

use of eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory in project dwoss by gg-net.

the class RedTapeCreateDossierWorkflow method createDossier.

/**
 * Creates the Dossier.
 *
 * @param customer the customer
 * @return the Dossier.
 */
Dossier createDossier(long customerId, boolean dispatch, DocumentType type, PaymentMethod paymentMethod, Directive directive, String arranger) {
    if (specialSystemCustomers.get(customerId).map(x -> x != type).orElse(false)) {
        throw new IllegalStateException(type + " is not allowed for Customer " + customerId);
    }
    Dossier dos = new Dossier();
    dos.setPaymentMethod(paymentMethod);
    dos.setDispatch(dispatch);
    dos.setCustomerId(customerId);
    Document doc = new Document();
    doc.setType(type);
    doc.setActive(true);
    doc.setDirective(directive);
    doc.setHistory(new DocumentHistory(arranger, "Automatische Erstellung eines leeren Dokuments"));
    AddressEmo adEmo = new AddressEmo(redTapeEm);
    doc.setInvoiceAddress(adEmo.request(addressService.defaultAddressLabel(customerId, AddressType.INVOICE)));
    doc.setShippingAddress(adEmo.request(addressService.defaultAddressLabel(customerId, AddressType.SHIPPING)));
    dos.add(doc);
    redTapeEm.persist(dos);
    // Make sure the dos.id is generated an stored in the database.
    redTapeEm.flush();
    dos.setIdentifier(mandator.getDossierPrefix() + _00000_.format(dos.getId()));
    // Force store Identifier
    redTapeEm.flush();
    L.info("Created {} by {}", DossierFormater.toSimpleLine(dos), arranger);
    return dos;
}
Also used : AddressEmo(eu.ggnet.dwoss.redtape.ee.emo.AddressEmo) Stateless(javax.ejb.Stateless) CustomerServiceBean(eu.ggnet.dwoss.customer.ee.CustomerServiceBean) Logger(org.slf4j.Logger) CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) DecimalFormat(java.text.DecimalFormat) LoggerFactory(org.slf4j.LoggerFactory) BLOCK(eu.ggnet.dwoss.rules.DocumentType.BLOCK) Set(java.util.Set) eu.ggnet.dwoss.rules(eu.ggnet.dwoss.rules) SpecialSystemCustomers(eu.ggnet.dwoss.mandator.api.value.SpecialSystemCustomers) EntityManager(javax.persistence.EntityManager) Mandator(eu.ggnet.dwoss.mandator.api.value.Mandator) NumberFormat(java.text.NumberFormat) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) CustomerFlag(eu.ggnet.dwoss.rules.CustomerFlag) Inject(javax.inject.Inject) Directive(eu.ggnet.dwoss.redtape.ee.entity.Document.Directive) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) RedTapes(eu.ggnet.dwoss.redtape.ee.assist.RedTapes) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DossierFormater(eu.ggnet.dwoss.redtape.ee.format.DossierFormater) AddressServiceBean(eu.ggnet.dwoss.customer.ee.AddressServiceBean) AddressEmo(eu.ggnet.dwoss.redtape.ee.emo.AddressEmo) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DocumentHistory(eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Aggregations

DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)14 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)13 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)6 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)6 Address (eu.ggnet.dwoss.redtape.ee.entity.Address)4 Test (org.junit.Test)4 AddressEmo (eu.ggnet.dwoss.redtape.ee.emo.AddressEmo)3 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)2 Date (java.util.Date)2 JasperPrint (net.sf.jasperreports.engine.JasperPrint)2 Logger (org.slf4j.Logger)2 AddressServiceBean (eu.ggnet.dwoss.customer.ee.AddressServiceBean)1 CustomerServiceBean (eu.ggnet.dwoss.customer.ee.CustomerServiceBean)1 CustomerMetaData (eu.ggnet.dwoss.customer.opi.CustomerMetaData)1 Mandator (eu.ggnet.dwoss.mandator.api.value.Mandator)1 SpecialSystemCustomers (eu.ggnet.dwoss.mandator.api.value.SpecialSystemCustomers)1 RedTapes (eu.ggnet.dwoss.redtape.ee.assist.RedTapes)1 AddressEao (eu.ggnet.dwoss.redtape.ee.eao.AddressEao)1 PositionEao (eu.ggnet.dwoss.redtape.ee.eao.PositionEao)1 Directive (eu.ggnet.dwoss.redtape.ee.entity.Document.Directive)1