use of eu.ggnet.dwoss.redtape.ee.emo.AddressEmo in project dwoss by gg-net.
the class AddressEmoIT method testRequest.
@Test
public void testRequest() throws Exception {
utx.begin();
em.joinTransaction();
Address a1 = new Address("abcd");
Address a2 = new Address("efgh");
em.persist(a1);
em.persist(a2);
utx.commit();
utx.begin();
em.joinTransaction();
AddressEmo adEmo = new AddressEmo(em);
Address a3 = adEmo.request(a2.getDescription());
Address a4 = adEmo.request("ijkl");
assertTrue(a3.getDescription().equals(a2.getDescription()));
assertEquals(a4.getDescription(), "ijkl");
utx.commit();
}
use of eu.ggnet.dwoss.redtape.ee.emo.AddressEmo in project dwoss by gg-net.
the class RedTapeWorkerOperation method updateAllDocumentAdresses.
/**
* Changes the {@link Address} of all active {@link Document} of {@link DocumentType#ORDER} and no Invoices or CreditMemos found from every {@link Dossier}
* containing a specific customer id.
* <p/>
* If one of the addresses does not exist, it will be created.
* <p/>
* @param addressChange
*/
@Override
public void updateAllDocumentAdresses(AddressChange addressChange) {
AddressEmo addressEmo = new AddressEmo(redTapeEm);
Address address = addressEmo.request(addressService.defaultAddressLabel(addressChange.getCustomerId(), addressChange.getType()));
redTapeEm.detach(address);
List<Dossier> dossiers = new DossierEao(redTapeEm).findByCustomerId(addressChange.getCustomerId());
for (Dossier dossier : dossiers) {
if (!dossier.getActiveDocuments(DocumentType.INVOICE).isEmpty())
continue;
for (Document document : new HashSet<>(dossier.getActiveDocuments(DocumentType.ORDER))) {
if (document.getConditions().contains(Document.Condition.CANCELED))
continue;
// May be fetchEager
redTapeEm.detach(document);
if (addressChange.getType() == AddressType.INVOICE)
document.setInvoiceAddress(address);
if (addressChange.getType() == AddressType.SHIPPING)
document.setShippingAddress(address);
redTapeEm.flush();
redTapeEm.clear();
internalUpdate(document, null, addressChange.getArranger());
}
}
}
use of eu.ggnet.dwoss.redtape.ee.emo.AddressEmo in project dwoss by gg-net.
the class RedTapeWorkerOperation method requestAdressesByCustomer.
/**
* Gives a pair of {@link Address}es based on the Customer.
* <p/>
* If no Address could be found, new persisted enteties are created.
* <p/>
*/
@Override
public Addresses requestAdressesByCustomer(long customerId) {
AddressEmo addressEmo = new AddressEmo(redTapeEm);
Address invoice = addressEmo.request(addressService.defaultAddressLabel(customerId, AddressType.INVOICE));
Address shipping = addressEmo.request(addressService.defaultAddressLabel(customerId, AddressType.SHIPPING));
return new Addresses(invoice, shipping);
}
use of eu.ggnet.dwoss.redtape.ee.emo.AddressEmo 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