use of eu.ggnet.dwoss.rules.CustomerFlag in project dwoss by gg-net.
the class CustomerServiceBean method updateCustomerFlags.
@Override
public void updateCustomerFlags(long customerId, Set<CustomerFlag> flags) {
Customer customer = customerEao.findById(customerId);
customer.getFlags().clear();
for (CustomerFlag customerFlag : flags) {
customer.getFlags().add(customerFlag);
}
}
use of eu.ggnet.dwoss.rules.CustomerFlag 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.rules.CustomerFlag in project dwoss by gg-net.
the class CustomerEnhanceController method buildFlagBox.
/**
* Build up a ListView with CheckBoxes for the Set of CunstomerFlags
*/
private void buildFlagBox() {
// transform a Set to a ObservableList of CustomerFlag
List<CustomerFlag> templist = new ArrayList<>();
flagsSet.forEach(f -> templist.add(f));
ObservableList<CustomerFlag> allFlagsFromTheCustomer = FXCollections.observableArrayList(templist);
// fill with all posibile flags
ObservableList<CustomerFlag> observableArrayListOfAllFlags = FXCollections.observableArrayList(CustomerFlag.values());
ObservableList<CustomerFlagWithSelect> listForTheView = FXCollections.observableArrayList();
// fill the CustomerFlagWithSelect List
observableArrayListOfAllFlags.stream().map((ovall) -> {
CustomerFlagWithSelect cfs = new CustomerFlagWithSelect(ovall);
if (allFlagsFromTheCustomer.contains(ovall)) {
cfs.setSelected(true);
}
return cfs;
}).forEachOrdered((cfs) -> {
listForTheView.add(cfs);
});
listForTheView.forEach(flag -> flag.selectedProperty().addListener((observable, wasSelected, isSelected) -> {
if (isSelected) {
outputFlagslist.add(flag.getFlag());
}
}));
ListView<CustomerFlagWithSelect> checklist = new ListView<>();
checklist.setItems(listForTheView);
checklist.setMinWidth(150.0);
checklist.setCellFactory(CheckBoxListCell.forListView(CustomerFlagWithSelect::selectedProperty, new StringConverter<CustomerFlagWithSelect>() {
@Override
public String toString(CustomerFlagWithSelect object) {
return object.getFlag().getName();
}
@Override
public CustomerFlagWithSelect fromString(String string) {
return null;
}
}));
Label flagLable = new Label("Flags: ");
flagVBox.getChildren().addAll(flagLable, checklist);
}
use of eu.ggnet.dwoss.rules.CustomerFlag in project dwoss by gg-net.
the class ConverterUtil method convert.
/**
* Converts a customer to old customer.
* <p>
* @param c the customer
* @param mandatorMatchCode the mandator matchcode
* @param defaults the defaults
* @return the converted old customer
*/
public static OldCustomer convert(Customer c, String mandatorMatchCode, DefaultCustomerSalesdata defaults) {
OldCustomer old = new OldCustomer();
old.setId((int) c.getId());
old.setAnmerkung(c.getComment());
for (CustomerFlag flag : c.getFlags()) {
old.addFlag(flag);
}
old.getAdditionalCustomerIds().putAll(c.getAdditionalCustomerIds());
old.setKeyAccounter(c.getKeyAccounter());
old.setSource(c.getSource());
if (!c.getCompanies().isEmpty()) {
Company company = c.getCompanies().get(0);
old.setFirma(company.getName());
old.setLedger(company.getLedger());
old.setTaxId(company.getTaxId());
}
if (!c.getContacts().isEmpty()) {
Contact contact = c.getContacts().get(0);
old.setVorname(contact.getFirstName());
old.setNachname(contact.getLastName());
if (contact.getSex() != null)
switch(contact.getSex()) {
case MALE:
old.setTitel("Herr");
break;
case FEMALE:
old.setTitel("Frau");
break;
}
for (Communication com : contact.getCommunications()) {
set(old, com.getType(), com.getIdentifier());
}
for (Address address : contact.getAddresses()) {
switch(address.getPreferedType()) {
case INVOICE:
old.setREAdresse(address.getStreet());
old.setREOrt(address.getCity());
old.setREPlz(address.getZipCode());
break;
case SHIPPING:
old.setLIAdresse(address.getStreet());
old.setLIOrt(address.getCity());
old.setLIPlz(address.getZipCode());
break;
}
}
}
MandatorMetadata.MergedView metadata = new MandatorMetadata.MergedView(c.getMandatorMetadata(mandatorMatchCode), defaults);
old.setAllowedSalesChannels(new HashSet<>(metadata.getAllowedSalesChannels()));
old.setPaymentCondition(metadata.getPaymentCondition());
old.setPaymentMethod(metadata.getPaymentMethod());
old.setShippingCondition(metadata.getShippingCondition());
return old;
}
Aggregations