Search in sources :

Example 1 with Directive

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

the class RedTapeCreateDossierWorkflow method execute.

/**
 * Executes the Workflow.
 *
 * @param customerId
 * @param dispatch
 * @param arranger
 * @return the Dossier.
 */
public Dossier execute(long customerId, boolean dispatch, String arranger) {
    DocumentType type = DocumentType.ORDER;
    CustomerMetaData customer = customerService.asCustomerMetaData(customerId);
    L.debug("Found Customer: {}", customer);
    if (customer.getFlags().contains(SYSTEM_CUSTOMER)) {
        type = specialSystemCustomers.get(customerId).orElse(BLOCK);
        L.debug("CustomerId {} is SystemCustomer, using DocumentType: {}, source {}", customerId, type, specialSystemCustomers);
    }
    PaymentMethod paymentMethod = selectPaymentMethod(dispatch, customer);
    Directive directive = primeDirective(type, paymentMethod, customer.getFlags(), dispatch);
    return createDossier(customerId, dispatch, type, paymentMethod, directive, arranger);
}
Also used : CustomerMetaData(eu.ggnet.dwoss.customer.opi.CustomerMetaData) Directive(eu.ggnet.dwoss.redtape.ee.entity.Document.Directive)

Example 2 with Directive

use of eu.ggnet.dwoss.redtape.ee.entity.Document.Directive 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

CustomerMetaData (eu.ggnet.dwoss.customer.opi.CustomerMetaData)2 Directive (eu.ggnet.dwoss.redtape.ee.entity.Document.Directive)2 AddressServiceBean (eu.ggnet.dwoss.customer.ee.AddressServiceBean)1 CustomerServiceBean (eu.ggnet.dwoss.customer.ee.CustomerServiceBean)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 AddressEmo (eu.ggnet.dwoss.redtape.ee.emo.AddressEmo)1 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)1 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)1 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)1 DossierFormater (eu.ggnet.dwoss.redtape.ee.format.DossierFormater)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 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 Set (java.util.Set)1 Stateless (javax.ejb.Stateless)1 Inject (javax.inject.Inject)1