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());
}
Aggregations