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;
}
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;
}
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;
}
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));
}
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;
}
Aggregations