Search in sources :

Example 1 with Type

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();
}
Also used : Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) Arrays(java.util.Arrays) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) eu.ggnet.dwoss.customer.ee.entity(eu.ggnet.dwoss.customer.ee.entity) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Sex(eu.ggnet.dwoss.customer.ee.entity.Contact.Sex) Test(org.junit.Test) AddressType(eu.ggnet.dwoss.rules.AddressType) CustomerTestUtil(eu.ggnet.dwoss.customer.test.CustomerTestUtil) StringUtils(org.apache.commons.lang3.StringUtils) CustomerFlag(eu.ggnet.dwoss.rules.CustomerFlag) INVOICE(eu.ggnet.dwoss.rules.AddressType.INVOICE) GERMANY(java.util.Locale.GERMANY) Locale(java.util.Locale) SHIPPING(eu.ggnet.dwoss.rules.AddressType.SHIPPING) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) Test(org.junit.Test)

Example 2 with Type

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;
}
Also used : SalesChannel(eu.ggnet.dwoss.rules.SalesChannel) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) CustomerFlag(eu.ggnet.dwoss.rules.CustomerFlag)

Example 3 with Type

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;
        }
    }));
}
Also used : Locale(java.util.Locale) Pos(javafx.geometry.Pos) Initializable(javafx.fxml.Initializable) IntegerStringConverter(javafx.util.converter.IntegerStringConverter) javafx.scene.control(javafx.scene.control) URL(java.net.URL) Sex(eu.ggnet.dwoss.customer.ee.entity.Contact.Sex) FXCollections(javafx.collections.FXCollections) VBox(javafx.scene.layout.VBox) Ui(eu.ggnet.saft.Ui) Bindings(javafx.beans.binding.Bindings) AlertType(eu.ggnet.saft.core.ui.AlertType) ResourceBundle(java.util.ResourceBundle) Locale(java.util.Locale) WINDOW_MODAL(javafx.stage.Modality.WINDOW_MODAL) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) eu.ggnet.dwoss.customer.ee.entity(eu.ggnet.dwoss.customer.ee.entity) eu.ggnet.saft.api.ui(eu.ggnet.saft.api.ui) Consumer(java.util.function.Consumer) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Pattern(java.util.regex.Pattern) ObservableList(javafx.collections.ObservableList) HBox(javafx.scene.layout.HBox) IntegerStringConverter(javafx.util.converter.IntegerStringConverter) AlertType(eu.ggnet.saft.core.ui.AlertType) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) VBox(javafx.scene.layout.VBox)

Example 4 with Type

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);
}
Also used : Locale(java.util.Locale) HBox(javafx.scene.layout.HBox) Sex(eu.ggnet.dwoss.customer.ee.entity.Contact.Sex) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) AlertType(eu.ggnet.saft.core.ui.AlertType) VBox(javafx.scene.layout.VBox)

Aggregations

Type (eu.ggnet.dwoss.customer.ee.entity.Communication.Type)4 Sex (eu.ggnet.dwoss.customer.ee.entity.Contact.Sex)3 Locale (java.util.Locale)3 eu.ggnet.dwoss.customer.ee.entity (eu.ggnet.dwoss.customer.ee.entity)2 CustomerFlag (eu.ggnet.dwoss.rules.CustomerFlag)2 AlertType (eu.ggnet.saft.core.ui.AlertType)2 HBox (javafx.scene.layout.HBox)2 VBox (javafx.scene.layout.VBox)2 AddressLabel (eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)1 CustomerTestUtil (eu.ggnet.dwoss.customer.test.CustomerTestUtil)1 AddressType (eu.ggnet.dwoss.rules.AddressType)1 INVOICE (eu.ggnet.dwoss.rules.AddressType.INVOICE)1 SHIPPING (eu.ggnet.dwoss.rules.AddressType.SHIPPING)1 SalesChannel (eu.ggnet.dwoss.rules.SalesChannel)1 Ui (eu.ggnet.saft.Ui)1 eu.ggnet.saft.api.ui (eu.ggnet.saft.api.ui)1 URL (java.net.URL)1 Arrays (java.util.Arrays)1 GERMANY (java.util.Locale.GERMANY)1 ResourceBundle (java.util.ResourceBundle)1