use of eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer in project dwoss by gg-net.
the class CustomerSimpleController method getSimpleCustomer.
private SimpleCustomer getSimpleCustomer() throws IllegalStateException {
SimpleCustomer sc = new SimpleCustomer();
sc.setTitle(titleTextField.getText());
sc.setFirstName(firstNameTextField.getText());
sc.setLastName(lastNameTextField.getText());
sc.setStreet(streetTextField.getText());
sc.setZipCode(zipcodeTextField.getText());
sc.setCity(cityTextField.getText());
sc.setIsoCountry(countryTextField.getText());
if (StringUtils.isNotBlank(mobileTextField.getText())) {
Communication communication = new Communication(Type.MOBILE, mobileTextField.getText());
if (communication.getViolationMessage() != null)
throw new IllegalStateException(communication.getViolationMessage());
sc.setMobilePhone(mobileTextField.getText());
}
if (StringUtils.isNotBlank(landLineTextField.getText())) {
Communication communication = new Communication(Type.PHONE, landLineTextField.getText());
if (communication.getViolationMessage() != null)
throw new IllegalStateException(communication.getViolationMessage());
sc.setLandlinePhone(landLineTextField.getText());
}
if (StringUtils.isNotBlank(emailTextField.getText())) {
Communication communication = new Communication(Type.EMAIL, emailTextField.getText());
if (communication.getViolationMessage() != null)
throw new IllegalStateException(communication.getViolationMessage());
sc.setEmail(emailTextField.getText());
}
sc.setSex(genderChoiseBox.getSelectionModel().getSelectedItem());
sc.setSource(sourceChoiseBox.getSelectionModel().getSelectedItem());
sc.setCompanyName(companyNameTextField.getText());
sc.setTaxId(ustIdTextField.getText());
sc.setComment(commentTextArea.getText());
return sc;
}
use of eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer in project dwoss by gg-net.
the class CustomerSimpleTest method testToSimpleConsumer.
@Test
public void testToSimpleConsumer() {
Customer makeValidSimpleConsumer = makeValidSimpleConsumer();
makeValidSimpleConsumer.getContacts().get(0).getCommunications().clear();
makeValidSimpleConsumer.getContacts().get(0).getCommunications().add(makeValidCommunication());
makeValidSimpleConsumer.getContacts().get(0).getCommunications().add(makeValidCommunicationMobile());
makeValidSimpleConsumer.getContacts().get(0).getCommunications().add(makeValidCommunicationLandline());
assertThat(makeValidSimpleConsumer.isSimple()).as("still simplecustomer").isTrue();
SimpleCustomer simpleConsumerCustomer = makeValidSimpleConsumer.toSimple().get();
assertThat(simpleConsumerCustomer.getTitle()).as("title").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getTitle());
assertThat(simpleConsumerCustomer.getFirstName()).as("firstname").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getFirstName());
assertThat(simpleConsumerCustomer.getLastName()).as("lastname").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getLastName());
assertThat(simpleConsumerCustomer.getStreet()).as("street").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getAddresses().get(0).getStreet());
assertThat(simpleConsumerCustomer.getZipCode()).as("zipcode").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getAddresses().get(0).getZipCode());
assertThat(simpleConsumerCustomer.getCity()).as("city").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getAddresses().get(0).getCity());
assertThat(simpleConsumerCustomer.getIsoCountry()).as("isoCountry").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getAddresses().get(0).getIsoCountry());
assertThat(simpleConsumerCustomer.getMobilePhone()).as("mobilePhone").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == MOBILE).map(Communication::getIdentifier).findFirst().get());
assertThat(simpleConsumerCustomer.getLandlinePhone()).as("landlinePhone").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == PHONE).map(Communication::getIdentifier).findFirst().get());
assertThat(simpleConsumerCustomer.getEmail()).as("email").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getCommunications().stream().filter(c -> c.getType() == EMAIL).map(Communication::getIdentifier).findFirst().get());
assertThat(simpleConsumerCustomer.getSex()).as("sex").isEqualTo(makeValidSimpleConsumer.getContacts().get(0).getSex());
assertThat(simpleConsumerCustomer.getSource()).as("source").isEqualTo(makeValidSimpleConsumer.getSource());
assertThat(simpleConsumerCustomer.getComment()).as("comment").isEqualTo(makeValidSimpleConsumer.getComment());
assertThat(simpleConsumerCustomer.getCompanyName()).as("companyName").isEqualTo(null);
assertThat(simpleConsumerCustomer.getTaxId()).as("taxId").isEqualTo(null);
}
use of eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer in project dwoss by gg-net.
the class CustomerAgentBean method store.
@Override
public Reply<Customer> store(SimpleCustomer simpleCustomer) {
L.warn("Simulating Store : " + 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 (!StringUtils.isBlank(simpleCustomer.getEmail()))
cont.getCommunications().add(new Communication(Type.EMAIL, simpleCustomer.getEmail()));
if (!StringUtils.isBlank(simpleCustomer.getLandlinePhone()))
cont.getCommunications().add(new Communication(Type.PHONE, simpleCustomer.getLandlinePhone()));
if (!StringUtils.isBlank(simpleCustomer.getMobilePhone()))
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);
}
Aggregations