use of eu.ggnet.dwoss.customer.ee.entity.Communication.Type in project dwoss by gg-net.
the class CustomerTestUtil method testGetViolationMessageSimpleConsumer.
@Test
public void testGetViolationMessageSimpleConsumer() {
Customer simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getCompanies().add(makeValidCompany());
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with company is not valid").isNotNull();
simpleConsumer.getCompanies().clear();
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with contact and without company is valid").isNull();
simpleConsumer.getContacts().clear();
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer without contact is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getAddressLabels().remove(simpleConsumer.getAddressLabels().stream().filter(label -> label.getType() == AddressType.INVOICE).findAny().get());
assertThat(simpleConsumer.getViolationMessage()).as("Removal of any AddressLabel of type INVOICE from SimpleConsumer is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getAddressLabels().add(new AddressLabel(null, simpleConsumer.getContacts().get(0), simpleConsumer.getContacts().get(0).getAddresses().get(0), INVOICE));
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with two addressLabels of type INVOICE is invalid").isNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getAddressLabels().add(new AddressLabel(null, simpleConsumer.getContacts().get(0), simpleConsumer.getContacts().get(0).getAddresses().get(0), SHIPPING));
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with two AddressLabels of unequal types is valid").isNull();
simpleConsumer.getAddressLabels().add(new AddressLabel(null, simpleConsumer.getContacts().get(0), simpleConsumer.getContacts().get(0).getAddresses().get(0), SHIPPING));
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with three AddressLabels is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getContacts().clear();
Contact invalidContact = new Contact(Sex.MALE, true, null, "invalid", "");
assertThat(invalidContact.getViolationMessage()).as("Contact without lastName is invalid").isNotNull();
simpleConsumer.getContacts().add(invalidContact);
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with invalid contact is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getContacts().get(0).getAddresses().clear();
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer without Address is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
simpleConsumer.getContacts().get(0).getCommunications().clear();
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer without communications is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
Communication invalidEmailCommunication = new Communication(Type.EMAIL, false);
simpleConsumer.getContacts().get(0).getCommunications().clear();
simpleConsumer.getContacts().get(0).getCommunications().add(invalidEmailCommunication);
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with invalid Communication is invalid").isNotNull();
simpleConsumer = makeValidSimpleConsumer();
Address invalidAddress = new Address();
invalidAddress.setIsoCountry(Locale.GERMANY);
invalidAddress.setCity("city");
invalidAddress.setStreet("street");
invalidAddress.setZipCode("");
assertThat(invalidAddress.getViolationMessage()).as("Invalid Address is invalid").isNotNull();
simpleConsumer.getContacts().get(0).getAddresses().clear();
simpleConsumer.getContacts().get(0).getAddresses().add(invalidAddress);
assertThat(simpleConsumer.getViolationMessage()).as("SimpleConsumer with invalid Address is invalid").isNotNull();
}
use of eu.ggnet.dwoss.customer.ee.entity.Communication.Type in project dwoss by gg-net.
the class ConverterUtil method mergeFromOld.
/**
* Merges the old customer to a supplied new customer instance.
* The new customer has all information of the old customer set to the first contact.
* A Company may be added if the old.firma is not blank.
* This Method also assumes, that there is exactly one Mandator used in creation with its defaults.
* <p>
* @param old old customer
* @param customer
* @param mandatorMatchCode the mandatorMatchCode
* @param defaults the defaults as filter for specific mandator data.
* @return new customer.
*/
public static Customer mergeFromOld(OldCustomer old, Customer customer, String mandatorMatchCode, DefaultCustomerSalesdata defaults) {
customer.setComment(old.getAnmerkung());
customer.getFlags().clear();
for (CustomerFlag customerFlag : old.getFlags()) {
customer.getFlags().add(customerFlag);
}
customer.getAdditionalCustomerIds().clear();
customer.getAdditionalCustomerIds().putAll(old.getAdditionalCustomerIds());
customer.setSource(old.getSource());
customer.setKeyAccounter(old.getKeyAccounter());
if (customer.getContacts().isEmpty())
customer.getContacts().add(new Contact());
Contact contact = customer.getContacts().get(0);
contact.setFirstName(old.getVorname() == null ? "" : old.getVorname());
contact.setLastName(old.getNachname() == null ? "" : old.getNachname());
if (old.getTitel() != null) {
switch(old.getTitel()) {
case "Herr":
contact.setSex(MALE);
break;
case "Frau":
contact.setSex(FEMALE);
break;
default:
}
}
contact.setPrefered(true);
if (!StringUtils.isBlank(old.getFirma()) || !customer.getCompanies().isEmpty()) {
if (customer.getCompanies().isEmpty())
customer.getCompanies().add(new Company());
Company company = customer.getCompanies().get(0);
company.setName(old.getFirma());
company.setLedger(old.getLedger());
company.setTaxId(old.getTaxId());
company.setPrefered(true);
}
for (Type t : EnumSet.of(EMAIL, FAX, PHONE, MOBILE)) {
if (!StringUtils.isBlank(get(old, t)) || contact.prefered(t) != null) {
if (contact.prefered(t) == null)
contact.getCommunications().add(new Communication(t, true));
contact.prefered(t).setIdentifier(get(old, t));
}
}
if (!StringUtils.isBlank(old.getREAdresse()) || contact.prefered(INVOICE) != null) {
if (contact.prefered(INVOICE) == null)
contact.getAddresses().add(new Address(INVOICE));
Address rad = contact.prefered(INVOICE);
rad.setStreet(old.getREAdresse());
rad.setCity(old.getREOrt() == null ? "" : old.getREOrt());
rad.setZipCode(old.getREPlz() == null ? "" : old.getREPlz());
}
if (!StringUtils.isBlank(old.getLIAdresse()) || contact.prefered(SHIPPING) != null) {
if (contact.prefered(SHIPPING) == null)
contact.getAddresses().add(new Address(SHIPPING));
Address sad = contact.prefered(SHIPPING);
sad.setStreet(old.getLIAdresse());
sad.setCity(old.getLIOrt() == null ? "" : old.getLIOrt());
sad.setZipCode(old.getLIPlz() == null ? "" : old.getLIPlz());
}
MandatorMetadata m = customer.getMandatorMetadata(mandatorMatchCode);
if (m == null)
m = new MandatorMetadata();
m.setMandatorMatchcode(mandatorMatchCode);
m.clearSalesChannels();
if (!old.getAllowedSalesChannels().equals(defaults.getAllowedSalesChannels())) {
for (SalesChannel salesChannel : old.getAllowedSalesChannels()) {
m.add(salesChannel);
}
}
if (old.getPaymentCondition() == defaults.getPaymentCondition())
m.setPaymentCondition(null);
else
m.setPaymentCondition(old.getPaymentCondition());
if (old.getPaymentMethod() == defaults.getPaymentMethod())
m.setPaymentMethod(null);
else
m.setPaymentMethod(old.getPaymentMethod());
if (old.getShippingCondition() == defaults.getShippingCondition())
m.setShippingCondition(null);
else
m.setShippingCondition(old.getShippingCondition());
if (customer.getMandatorMetadata(mandatorMatchCode) == null && m.isSet())
customer.getMandatorMetadata().add(m);
return customer;
}
use of eu.ggnet.dwoss.customer.ee.entity.Communication.Type in project dwoss by gg-net.
the class CompanyUpdateController method initialize.
/**
* Initializes the controller class.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
// button behavior
delAddressButton.disableProperty().bind(addressListView.getSelectionModel().selectedIndexProperty().lessThan(0));
delComButton.disableProperty().bind(communicationTableView.getSelectionModel().selectedIndexProperty().lessThan(0));
delContactButton.disableProperty().bind(contactListView.getSelectionModel().selectedIndexProperty().lessThan(0));
// get overwriten in accept()
companyNameTextField.setText("");
addressListView.setItems(addressList);
// enable the save and "saveAndClose" button only on filled TextFields
saveButton.disableProperty().bind(Bindings.createBooleanBinding(() -> companyNameTextField.getText().trim().isEmpty(), companyNameTextField.textProperty()).or(addressListView.getSelectionModel().selectedIndexProperty().lessThan(0)));
saveAndCloseButton.disableProperty().bind(Bindings.createBooleanBinding(() -> companyNameTextField.getText().trim().isEmpty(), companyNameTextField.textProperty()).or(addressListView.getSelectionModel().selectedIndexProperty().lessThan(0)));
// Address HORIZONTAL CellFactory
addressListView.setCellFactory((ListView<Address> p) -> {
ListCell<Address> cell = new ListCell<Address>() {
@Override
protected void updateItem(Address item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
setText("");
} else {
VBox anschriftbox = new VBox();
Label street = new Label(item.getStreet());
Label zipCode = new Label(item.getZipCode());
Label city = new Label(item.getCity());
HBox postBox = new HBox();
postBox.getChildren().addAll(zipCode, city);
postBox.setSpacing(2.0);
Label country = new Label(new Locale("", item.getIsoCountry()).getDisplayCountry());
anschriftbox.getChildren().addAll(street, postBox, country);
anschriftbox.setSpacing(2.0);
setText(null);
setGraphic(anschriftbox);
}
}
};
return cell;
});
addressListView.setOrientation(Orientation.HORIZONTAL);
// adding a CellFactory for every Colum
typeColumn.setCellValueFactory(new PropertyValueFactory<>("type"));
typeColumn.setCellFactory(column -> {
return new TableCell<Communication, Type>() {
@Override
protected void updateItem(Type item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
} else {
setText(item.name());
setStyle("-fx-font-weight: bold");
}
}
};
});
idColumn.setCellValueFactory(new PropertyValueFactory<>("identifier"));
idColumn.setCellFactory(column -> {
return new TableCell<Communication, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
} else {
setText(item);
setStyle("");
}
}
};
});
prefColumn.setCellValueFactory(new PropertyValueFactory<>("prefered"));
prefColumn.setCellFactory(column -> {
return new TableCell<Communication, Boolean>() {
@Override
protected void updateItem(Boolean item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
setGraphic(null);
} else {
HBox checkHBox = new HBox();
RadioButton prefRadioButton = new RadioButton();
prefRadioButton.setSelected(item);
prefRadioButton.setToggleGroup(prefGroup);
checkHBox.getChildren().add(prefRadioButton);
checkHBox.setAlignment(Pos.CENTER);
setText("");
setGraphic(checkHBox);
}
}
};
});
// Contact CellFactory
contactListView.setCellFactory((ListView<Contact> p) -> {
ListCell<Contact> cell = new ListCell<Contact>() {
@Override
protected void updateItem(Contact item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
setText("");
} else {
String anrede = "";
if (item.getSex() == Sex.FEMALE) {
anrede = "Frau ";
}
if (item.getSex() == Sex.MALE) {
anrede = "Herr ";
}
setText(anrede + item.toFullName());
}
}
};
return cell;
});
// force the ledger field to be numeric only, becuase the ledger get saved as an int
ledgerTextField.textFormatterProperty().set(new TextFormatter<>(new IntegerStringConverter(), 0, change -> {
String newText = change.getControlNewText();
if (Pattern.compile("-?((\\d*))").matcher(newText).matches()) {
return change;
} else {
return null;
}
}));
}
use of eu.ggnet.dwoss.customer.ee.entity.Communication.Type in project dwoss by gg-net.
the class ContactUpdateController method initialize.
/**
* Initializes the controller class.
*
* @param url
* @param rb
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
// button behavior
delAddressButton.disableProperty().bind(addressListView.getSelectionModel().selectedIndexProperty().lessThan(0));
delComButton.disableProperty().bind(communicationTableView.getSelectionModel().selectedIndexProperty().lessThan(0));
// get overwriten in accept()
lastNameTextField.setText("");
// enable the save and "saveAndClose" button only on filled TextFields
saveButton.disableProperty().bind(Bindings.createBooleanBinding(() -> lastNameTextField.getText().trim().isEmpty(), lastNameTextField.textProperty()));
saveAndCloseButton.disableProperty().bind(Bindings.createBooleanBinding(() -> lastNameTextField.getText().trim().isEmpty(), lastNameTextField.textProperty()));
// fill the UI with default values
genderBox.setConverter(new StringConverter<Sex>() {
@Override
public Sex fromString(String string) {
throw new UnsupportedOperationException("Invalid operation for Convert a String into a Sex.");
}
@Override
public String toString(Sex myClassinstance) {
return myClassinstance.getSign();
}
});
genderBox.getItems().addAll(Contact.Sex.values());
// Address HORIZONTAL CellFactory
addressListView.setCellFactory((ListView<Address> p) -> {
ListCell<Address> cell = new ListCell<Address>() {
@Override
protected void updateItem(Address item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setGraphic(null);
setText("");
} else {
VBox anschriftbox = new VBox();
Label street = new Label(item.getStreet());
Label zipCode = new Label(item.getZipCode());
Label city = new Label(item.getCity());
HBox postBox = new HBox();
postBox.getChildren().addAll(zipCode, city);
postBox.setSpacing(2.0);
Label country = new Label(new Locale("", item.getIsoCountry()).getDisplayCountry());
anschriftbox.getChildren().addAll(street, postBox, country);
anschriftbox.setSpacing(2.0);
setText(null);
setGraphic(anschriftbox);
}
}
};
return cell;
});
addressListView.setOrientation(Orientation.HORIZONTAL);
// adding a CellFactory for every Colum
typeColumn.setCellValueFactory(new PropertyValueFactory<>("type"));
typeColumn.setCellFactory(column -> {
return new TableCell<Communication, Type>() {
@Override
protected void updateItem(Type item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
} else {
setText(item.name());
setStyle("-fx-font-weight: bold");
}
}
};
});
idColumn.setCellValueFactory(new PropertyValueFactory<>("identifier"));
idColumn.setCellFactory(column -> {
return new TableCell<Communication, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
} else {
setText(item);
setStyle("");
}
}
};
});
prefColumn.setCellValueFactory(new PropertyValueFactory<>("preferred"));
prefColumn.setCellFactory(column -> {
return new TableCell<Communication, Boolean>() {
@Override
protected void updateItem(Boolean item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(null);
setGraphic(null);
} else {
HBox checkHBox = new HBox();
RadioButton prefRadioButton = new RadioButton();
prefRadioButton.setSelected(item);
prefRadioButton.setToggleGroup(prefGroup);
checkHBox.getChildren().add(prefRadioButton);
checkHBox.setAlignment(Pos.CENTER);
setText("");
setGraphic(checkHBox);
}
}
};
});
// fill the listViews
addressListView.setItems(addressList);
communicationTableView.setItems(communicationsList);
communicationTableView.getColumns().addAll(typeColumn, idColumn, prefColumn);
}
Aggregations