use of com.salesmanager.core.model.common.Criteria in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method listByCriteria.
@Override
public ReadableUserList listByCriteria(UserCriteria criteria, int page, int count, Language language) {
try {
ReadableUserList readableUserList = new ReadableUserList();
// filtering by userName is not in this implementation
Page<User> userList = null;
Optional<String> storeCode = Optional.ofNullable(criteria.getStoreCode());
if (storeCode.isPresent()) {
// get store
MerchantStore store = merchantStoreService.getByCode(storeCode.get());
if (store != null && (store.isRetailer() != null)) {
if (store.isRetailer().booleanValue()) {
// get group stores
List<MerchantStore> stores = merchantStoreService.findAllStoreNames(store.getCode());
List<Integer> intList = stores.stream().map(s -> s.getId()).collect(Collectors.toList());
criteria.setStoreIds(intList);
// search over store list
criteria.setStoreCode(null);
}
}
}
userList = userService.listByCriteria(criteria, page, count);
List<ReadableUser> readableUsers = new ArrayList<ReadableUser>();
if (userList != null) {
readableUsers = userList.getContent().stream().map(user -> convertUserToReadableUser(language, user)).collect(Collectors.toList());
readableUserList.setRecordsTotal(userList.getTotalElements());
readableUserList.setTotalPages(userList.getTotalPages());
readableUserList.setNumber(userList.getSize());
readableUserList.setRecordsFiltered(userList.getSize());
}
readableUserList.setData(readableUsers);
return readableUserList;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot get users by criteria user", e);
}
}
Aggregations