Search in sources :

Example 21 with DocumentEao

use of eu.ggnet.dwoss.redtape.ee.eao.DocumentEao in project dwoss by gg-net.

the class RedTapeUpdateRepaymentWorkflow method execute.

/**
 * Executes the Workflow.
 *
 * @param alteredDocument
 * @param destinationId
 * @param aranger
 * @return the updated Document.
 */
public Document execute(Document alteredDocument, Integer destinationId, String aranger) {
    // TODO: don't do this in stateless, works for now.
    this.arranger = aranger;
    Document previousDoc = new DocumentEao(redTapeEm).findById(alteredDocument.getId(), LockModeType.PESSIMISTIC_WRITE);
    validate(alteredDocument, previousDoc, destinationId);
    if (alteredDocument.equalsContent(previousDoc))
        return alteredDocument;
    L.info("Workflow on {} by {}", DocumentFormater.toSimpleLine(alteredDocument), arranger);
    Document newDocument = refreshAndPrepare(alteredDocument, previousDoc);
    if (alteredDocument.getType() != previousDoc.getType()) {
        // A Complaint is now complete.
        if (previousDoc.getType() == DocumentType.COMPLAINT)
            previousDoc.setDirective(Document.Directive.NONE);
        generateIdentifier(newDocument);
    }
    if (!alteredDocument.isStillExactlyBriefed(previousDoc))
        newDocument.remove(Document.Flag.CUSTOMER_EXACTLY_BRIEFED);
    newDocument.setHistory(new DocumentHistory(arranger, "Update durch " + getClass().getSimpleName()));
    redTapeEm.persist(newDocument);
    // Writing new document an gennerating the id;
    redTapeEm.flush();
    L.debug("Returning {} with {}", newDocument, newDocument.getDossier());
    validateAfter(newDocument.getDossier());
    // Is this a first time change
    if (alteredDocument.getType() == previousDoc.getType())
        return newDocument;
    // Is it a full CreditMemo on a Unit
    if (!alteredDocument.containsPositionType(PositionType.UNIT))
        return newDocument;
    List<StockUnit> stockUnits = optionalRemoveFromLogicTransaction(newDocument);
    List<StockUnit> stockUnits2 = rollInMissingStockUnits(newDocument.getDossier().getIdentifier(), newDocument.getPositions(PositionType.UNIT).values(), destinationId);
    optionalTransferToDestination(stockUnits, destinationId);
    Map<TradeName, List<Position>> contractorPositions = mapPositionsToContrator(newDocument.getPositions(PositionType.UNIT).values());
    for (TradeName contractor : contractorPositions.keySet()) {
        Document mirror = createMirrorDossier(repaymentCustomers.get(contractor).get()).getActiveDocuments().get(0);
        updateMirrorPositions(newDocument.getDossier().getIdentifier(), mirror, contractorPositions.get(contractor));
        equilibrateLogicTransaction(mirror);
    }
    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) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit)

Aggregations

DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)21 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)14 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)7 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)6 FileJacket (eu.ggnet.dwoss.util.FileJacket)6 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)5 File (java.io.File)5 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)4 Test (org.junit.Test)4 CBorder (eu.ggnet.lucidcalc.CBorder)3 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)3 CFormat (eu.ggnet.lucidcalc.CFormat)3 CSheet (eu.ggnet.lucidcalc.CSheet)3 STable (eu.ggnet.lucidcalc.STable)3 STableColumn (eu.ggnet.lucidcalc.STableColumn)3 STableModelList (eu.ggnet.lucidcalc.STableModelList)3 TempCalcDocument (eu.ggnet.lucidcalc.TempCalcDocument)3 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)2 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)2 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)2