Search in sources :

Example 6 with AddressEmo

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();
}
Also used : AddressEmo(eu.ggnet.dwoss.redtape.ee.emo.AddressEmo) Address(eu.ggnet.dwoss.redtape.ee.entity.Address) Test(org.junit.Test)

Example 7 with AddressEmo

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());
        }
    }
}
Also used : AddressEmo(eu.ggnet.dwoss.redtape.ee.emo.AddressEmo) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) CustomerDocument(eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument)

Example 8 with AddressEmo

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);
}
Also used : AddressEmo(eu.ggnet.dwoss.redtape.ee.emo.AddressEmo)

Example 9 with AddressEmo

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

AddressEmo (eu.ggnet.dwoss.redtape.ee.emo.AddressEmo)9 Test (org.junit.Test)4 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)3 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)3 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)3 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)3 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 DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)1 Address (eu.ggnet.dwoss.redtape.ee.entity.Address)1 Directive (eu.ggnet.dwoss.redtape.ee.entity.Document.Directive)1 DossierFormater (eu.ggnet.dwoss.redtape.ee.format.DossierFormater)1 CustomerDocument (eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument)1 eu.ggnet.dwoss.rules (eu.ggnet.dwoss.rules)1 CustomerFlag (eu.ggnet.dwoss.rules.CustomerFlag)1 BLOCK (eu.ggnet.dwoss.rules.DocumentType.BLOCK)1