Search in sources :

Example 1 with SimpleCustomer

use of eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer in project dwoss by gg-net.

the class CustomerSimpleTest method testToSimpleBusiness.

@Test
public void testToSimpleBusiness() {
    Customer makeValidSimpleBusiness = makeValidSimpleBusiness();
    makeValidSimpleBusiness.getCompanies().get(0).getCommunications().clear();
    assertThat(makeValidSimpleBusiness.isSimple()).as("still simplecustomer").isTrue();
    Contact makeValidContact = makeValidContact();
    makeValidContact.getCommunications().clear();
    makeValidContact.getCommunications().add(makeValidCommunication());
    makeValidContact.getCommunications().add(makeValidCommunicationMobile());
    makeValidContact.getCommunications().add(makeValidCommunicationLandline());
    assertThat(makeValidContact.getViolationMessage()).as("valid contact").isNull();
    makeValidSimpleBusiness.getCompanies().get(0).getContacts().clear();
    makeValidSimpleBusiness.getCompanies().get(0).getContacts().add(makeValidContact);
    assertThat(makeValidSimpleBusiness.isSimple()).as("still simplecustomer").isTrue();
    assertThat(makeValidSimpleBusiness.toSimple().isPresent()).as("to simple").isTrue();
    SimpleCustomer simpleConsumerCustomer = makeValidSimpleBusiness.toSimple().get();
    assertThat(simpleConsumerCustomer.getTitle()).as("title").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getTitle());
    assertThat(simpleConsumerCustomer.getFirstName()).as("firstname").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getFirstName());
    assertThat(simpleConsumerCustomer.getLastName()).as("lastname").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getLastName());
    assertThat(simpleConsumerCustomer.getSex()).as("sex").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getSex());
    // did Companys have a Address this Address have to match the Address on Contact
    if (!makeValidSimpleBusiness.getCompanies().get(0).getAddresses().isEmpty()) {
        assertThat(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getAddresses().get(0).getStreet()).as("address of contact have to be the same as on Address Street").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getAddresses().get(0).getStreet());
        assertThat(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getAddresses().get(0).getCity()).as("address of contact have to be the same as on Address City").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getAddresses().get(0).getCity());
        assertThat(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getAddresses().get(0).getZipCode()).as("address of contact have to be the same as on Address zipcode").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getAddresses().get(0).getZipCode());
        assertThat(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getAddresses().get(0).getIsoCountry()).as("address of contact have to be the same as on Address iso country").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getAddresses().get(0).getIsoCountry());
        assertThat(simpleConsumerCustomer.getStreet()).as("street").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getAddresses().get(0).getStreet());
        assertThat(simpleConsumerCustomer.getZipCode()).as("zipcode").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getAddresses().get(0).getZipCode());
        assertThat(simpleConsumerCustomer.getCity()).as("city").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getAddresses().get(0).getCity());
        assertThat(simpleConsumerCustomer.getIsoCountry()).as("isoCountry").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getAddresses().get(0).getIsoCountry());
    } else {
        assertThat(simpleConsumerCustomer.getStreet()).as("street").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getAddresses().get(0).getStreet());
        assertThat(simpleConsumerCustomer.getZipCode()).as("zipcode").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getAddresses().get(0).getZipCode());
        assertThat(simpleConsumerCustomer.getCity()).as("city").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getAddresses().get(0).getCity());
        assertThat(simpleConsumerCustomer.getIsoCountry()).as("isoCountry").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getAddresses().get(0).getIsoCountry());
    }
    assertThat(simpleConsumerCustomer.getMobilePhone()).as("mobilePhone").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == MOBILE).map(Communication::getIdentifier).findFirst().get());
    assertThat(simpleConsumerCustomer.getLandlinePhone()).as("landlinePhone").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == PHONE).map(Communication::getIdentifier).findFirst().get());
    assertThat(simpleConsumerCustomer.getEmail()).as("email").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == EMAIL).map(Communication::getIdentifier).findFirst().get());
    assertThat(simpleConsumerCustomer.getSource()).as("source").isEqualTo(makeValidSimpleBusiness.getSource());
    assertThat(simpleConsumerCustomer.getComment()).as("comment").isEqualTo(makeValidSimpleBusiness.getComment());
    assertThat(simpleConsumerCustomer.getCompanyName()).as("companyName").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getName());
    assertThat(simpleConsumerCustomer.getTaxId()).as("taxId").isEqualTo(makeValidSimpleBusiness.getCompanies().get(0).getTaxId());
}
Also used : SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) Test(org.junit.Test)

Example 2 with SimpleCustomer

use of eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer in project dwoss by gg-net.

the class Customer method toSimple.

/**
 * Converts the customer to a SimpleCustomer if possible.
 * <p>
 * The customer has to be Simple({@link #isSimple()}) or else an empty optional is returned.
 * For an optional of a SimpleCustomer the customer has to be either a consumer({@link #isConsumer()}) or a business customer({@link #isBusiness()}).
 *
 * @throws RuntimeException if the customer {@link #isSimple()} but neither a consumer({@link #isConsumer()}) or a business customer({@link #isBusiness()}).
 * @return an optional of the simple customer.
 */
public Optional<SimpleCustomer> toSimple() {
    if (!isSimple())
        return Optional.empty();
    if (isConsumer()) {
        SimpleCustomer sc = new SimpleCustomer();
        sc.setId(id);
        sc.setTitle(contacts.get(0).getTitle());
        sc.setFirstName(contacts.get(0).getFirstName());
        sc.setLastName(contacts.get(0).getLastName());
        sc.setStreet(contacts.get(0).getAddresses().get(0).getStreet());
        sc.setZipCode(contacts.get(0).getAddresses().get(0).getZipCode());
        sc.setCity(contacts.get(0).getAddresses().get(0).getCity());
        sc.setIsoCountry(contacts.get(0).getAddresses().get(0).getIsoCountry());
        sc.setMobilePhone(contacts.get(0).getCommunications().stream().filter(c -> c.getType() == MOBILE).map(Communication::getIdentifier).findFirst().orElse(null));
        sc.setLandlinePhone(contacts.get(0).getCommunications().stream().filter(c -> c.getType() == PHONE).map(Communication::getIdentifier).findFirst().orElse(null));
        sc.setEmail(contacts.get(0).getCommunications().stream().filter(c -> c.getType() == EMAIL).map(Communication::getIdentifier).findFirst().orElse(null));
        sc.setSex(contacts.get(0).getSex());
        sc.setSource(source);
        sc.setComment(comment);
        return Optional.of(sc);
    }
    if (isBusiness()) {
        SimpleCustomer sc = new SimpleCustomer();
        sc.setId(id);
        sc.setTitle(companies.get(0).getContacts().get(0).getTitle());
        sc.setFirstName(companies.get(0).getContacts().get(0).getFirstName());
        sc.setLastName(companies.get(0).getContacts().get(0).getLastName());
        sc.setSex(companies.get(0).getContacts().get(0).getSex());
        // if the Company have a Contact use this Address
        if (!companies.get(0).getContacts().get(0).getAddresses().isEmpty()) {
            sc.setStreet(companies.get(0).getContacts().get(0).getAddresses().get(0).getStreet());
            sc.setZipCode(companies.get(0).getContacts().get(0).getAddresses().get(0).getZipCode());
            sc.setCity(companies.get(0).getContacts().get(0).getAddresses().get(0).getCity());
            sc.setIsoCountry(companies.get(0).getContacts().get(0).getAddresses().get(0).getIsoCountry());
        } else {
            sc.setStreet(companies.get(0).getAddresses().get(0).getStreet());
            sc.setZipCode(companies.get(0).getAddresses().get(0).getZipCode());
            sc.setCity(companies.get(0).getAddresses().get(0).getCity());
            sc.setIsoCountry(companies.get(0).getAddresses().get(0).getIsoCountry());
        }
        // fist check the Contact for the needed Communications than use the Communications on the Company
        if (!companies.get(0).getContacts().get(0).getCommunications().isEmpty()) {
            sc.setMobilePhone(companies.get(0).getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == MOBILE).map(Communication::getIdentifier).findFirst().orElse(null));
            sc.setLandlinePhone(companies.get(0).getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == PHONE).map(Communication::getIdentifier).findFirst().orElse(null));
            sc.setEmail(companies.get(0).getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == EMAIL).map(Communication::getIdentifier).findFirst().orElse(null));
        }
        if (sc.getMobilePhone() == null) {
            sc.setMobilePhone(companies.get(0).getCommunications().stream().filter(c -> c.getType() == MOBILE).map(Communication::getIdentifier).findFirst().orElse(null));
        }
        if (sc.getLandlinePhone() == null) {
            sc.setLandlinePhone(companies.get(0).getCommunications().stream().filter(c -> c.getType() == PHONE).map(Communication::getIdentifier).findFirst().orElse(null));
        }
        if (sc.getEmail() == null) {
            sc.setEmail(companies.get(0).getCommunications().stream().filter(c -> c.getType() == EMAIL).map(Communication::getIdentifier).findFirst().orElse(null));
        }
        sc.setSource(source);
        sc.setComment(comment);
        sc.setCompanyName(companies.get(0).getName());
        sc.setTaxId(companies.get(0).getTaxId());
        return Optional.of(sc);
    }
    throw new RuntimeException("is Simple, but neither consumer nor bussiness. Invaid");
}
Also used : SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer)

Example 3 with SimpleCustomer

use of eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer in project dwoss by gg-net.

the class CustomerSimpleController method saveAndCloseButtonHandling.

@FXML
private void saveAndCloseButtonHandling() {
    try {
        SimpleCustomer simpleCustomer = getSimpleCustomer();
        result = new CustomerContinue(getSimpleCustomer(), false);
        Ui.closeWindowOf(kid);
    } catch (IllegalStateException e) {
        Alert alert = new Alert(javafx.scene.control.Alert.AlertType.ERROR, e.getMessage(), OK);
        alert.show();
    }
}
Also used : SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) CustomerContinue(eu.ggnet.dwoss.customer.ui.neo.CustomerSimpleController.CustomerContinue) FXML(javafx.fxml.FXML)

Example 4 with SimpleCustomer

use of eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer in project dwoss by gg-net.

the class CustomerAgentStub method store.

@Override
public Reply<Customer> store(SimpleCustomer simpleCustomer) {
    L.info("Input form Stubs: " + simpleCustomer.toString());
    // convert the SimpleCustomer to a Customer
    boolean bussines = !StringUtils.isBlank(simpleCustomer.getCompanyName());
    Customer c = new Customer();
    Contact cont = new Contact();
    cont.setFirstName(simpleCustomer.getFirstName());
    cont.setLastName(simpleCustomer.getLastName());
    cont.setSex(simpleCustomer.getSex());
    cont.setTitle(simpleCustomer.getTitle());
    // Contact with only one Address
    Address a = new Address();
    a.setCity(simpleCustomer.getCity());
    a.setIsoCountry(new Locale(simpleCustomer.getIsoCountry().toLowerCase(), simpleCustomer.getIsoCountry().toUpperCase()));
    a.setStreet(simpleCustomer.getStreet());
    a.setZipCode(simpleCustomer.getZipCode());
    cont.getAddresses().add(a);
    // one Communication form eatch type email, phone, mobile allowed
    if (simpleCustomer.getEmail() != null) {
        cont.getCommunications().add(new Communication(Type.EMAIL, simpleCustomer.getEmail()));
    }
    if (simpleCustomer.getLandlinePhone() != null) {
        cont.getCommunications().add(new Communication(Type.PHONE, simpleCustomer.getLandlinePhone()));
    }
    if (simpleCustomer.getMobilePhone() != null) {
        cont.getCommunications().add(new Communication(Type.MOBILE, simpleCustomer.getMobilePhone()));
    }
    AddressLabel al;
    if (bussines) {
        Company comp = new Company();
        comp.setName(simpleCustomer.getCompanyName());
        comp.setTaxId(simpleCustomer.getTaxId());
        // The Address of the Company Contact has to match the Company Address
        comp.getAddresses().add(a);
        comp.getContacts().add(cont);
        // build AddressLabel
        al = new AddressLabel(comp, comp.getContacts().get(0), a, AddressType.INVOICE);
        c.getCompanies().add(comp);
    } else {
        c.getContacts().add(cont);
        al = new AddressLabel(null, cont, a, AddressType.INVOICE);
    }
    c.getAddressLabels().add(al);
    c.setSource(simpleCustomer.getSource());
    if (!c.isValid())
        return Reply.failure(c.getViolationMessage());
    return Reply.success(c);
}
Also used : SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)

Example 5 with SimpleCustomer

use of eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer in project dwoss by gg-net.

the class CustomerSimpleController method saveAndEnhanceUIButtonHandling.

@FXML
private void saveAndEnhanceUIButtonHandling() {
    try {
        SimpleCustomer simpleCustomer = getSimpleCustomer();
        result = new CustomerContinue(getSimpleCustomer(), true);
        Ui.closeWindowOf(kid);
    } catch (IllegalStateException e) {
        Alert alert = new Alert(javafx.scene.control.Alert.AlertType.ERROR, e.getMessage(), OK);
        alert.show();
    }
}
Also used : SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) CustomerContinue(eu.ggnet.dwoss.customer.ui.neo.CustomerSimpleController.CustomerContinue) FXML(javafx.fxml.FXML)

Aggregations

SimpleCustomer (eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer)8 AddressLabel (eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)2 PicoCustomer (eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer)2 CustomerContinue (eu.ggnet.dwoss.customer.ui.neo.CustomerSimpleController.CustomerContinue)2 FXML (javafx.fxml.FXML)2 Test (org.junit.Test)2 Communication (eu.ggnet.dwoss.customer.ee.entity.Communication)1