Search in sources :

Example 1 with SearchField

use of eu.ggnet.dwoss.customer.ee.entity.Customer.SearchField in project dwoss by gg-net.

the class CustomerAgentStub method search.

/**
 * this methoes drops NPE like hell because many fields of the genaratet customer get checkt
 *
 * @param search
 * @param customerFields
 * @param start
 * @param limit
 * @return
 */
@Override
public List<PicoCustomer> search(String search, Set<SearchField> customerFields, int start, int limit) {
    L.info("SearchString {},{},start={},limit={}", search, customerFields.size(), start, limit);
    try {
        Thread.sleep(200L, SLOW);
    } catch (InterruptedException ex) {
        L.error("InterruptedException get throw");
    }
    if (start >= CUSTOMERS.size())
        return Collections.emptyList();
    if (limit >= CUSTOMERS.size())
        limit = CUSTOMERS.size();
    List<Customer> result = CUSTOMERS.subList(start, limit + start);
    List<Customer> tempList = new ArrayList<>();
    if (customerFields.contains(SearchField.LASTNAME)) {
        result.forEach(c -> {
            c.getContacts().stream().filter((contact) -> (contact.getLastName().contains(search))).forEachOrdered((sa) -> {
                tempList.add(c);
            });
        });
        result.addAll(tempList);
    }
    if (customerFields.contains(SearchField.FIRSTNAME)) {
        result.forEach((customer) -> {
            customer.getContacts().stream().filter((cont) -> (cont.getFirstName().contains(search))).forEachOrdered((_item) -> {
                tempList.add(customer);
            });
        });
    }
    if (customerFields.contains(SearchField.ID)) {
        if (search.matches("\\d*")) {
            result.stream().filter((customer) -> (customer.getId() == Long.parseLong(search))).forEachOrdered((customer) -> {
                tempList.add(customer);
            });
            result.addAll(tempList);
        }
    }
    if (customerFields.contains(SearchField.COMPANY)) {
        result.forEach((customer) -> {
            customer.getCompanies().stream().filter((com) -> (com.getName().contains(search))).forEachOrdered((_item) -> {
                tempList.add(customer);
            });
        });
        result.addAll(tempList);
    }
    if (customerFields.contains(SearchField.ADDRESS)) {
        for (Customer customer : result) {
            customer.getContacts().forEach((contact) -> {
                contact.getAddresses().stream().map((addr) -> {
                    if (addr.getStreet().contains(search)) {
                        tempList.add(customer);
                    }
                    return addr;
                }).map((addr) -> {
                    if (addr.getCity().contains(search)) {
                        tempList.add(customer);
                    }
                    return addr;
                }).filter((addr) -> (addr.getZipCode().contains(search))).forEachOrdered((_item) -> {
                    tempList.add(customer);
                });
            });
            result.addAll(tempList);
        }
    }
    L.info("Returning {}", result);
    return result.stream().map(Customer::toPico).collect(Collectors.toList());
}
Also used : CustomerGenerator(eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGenerator) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) java.util(java.util) Logger(org.slf4j.Logger) AddressLabel(eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel) SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) eu.ggnet.dwoss.customer.ee.entity(eu.ggnet.dwoss.customer.ee.entity) LoggerFactory(org.slf4j.LoggerFactory) AddressType(eu.ggnet.dwoss.rules.AddressType) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer) SearchField(eu.ggnet.dwoss.customer.ee.entity.Customer.SearchField) Reply(eu.ggnet.saft.api.Reply) LockModeType(javax.persistence.LockModeType) CustomerAgent(eu.ggnet.dwoss.customer.ee.CustomerAgent) SimpleCustomer(eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer) PicoCustomer(eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer)

Aggregations

CustomerAgent (eu.ggnet.dwoss.customer.ee.CustomerAgent)1 CustomerGenerator (eu.ggnet.dwoss.customer.ee.assist.gen.CustomerGenerator)1 eu.ggnet.dwoss.customer.ee.entity (eu.ggnet.dwoss.customer.ee.entity)1 Type (eu.ggnet.dwoss.customer.ee.entity.Communication.Type)1 SearchField (eu.ggnet.dwoss.customer.ee.entity.Customer.SearchField)1 SimpleCustomer (eu.ggnet.dwoss.customer.ee.entity.dto.SimpleCustomer)1 AddressLabel (eu.ggnet.dwoss.customer.ee.entity.projection.AddressLabel)1 PicoCustomer (eu.ggnet.dwoss.customer.ee.entity.projection.PicoCustomer)1 AddressType (eu.ggnet.dwoss.rules.AddressType)1 Reply (eu.ggnet.saft.api.Reply)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 LockModeType (javax.persistence.LockModeType)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1