use of com.salesmanager.core.model.user.UserCriteria in project shopizer by shopizer-ecommerce.
the class UserApi method list.
@ResponseStatus(HttpStatus.OK)
@GetMapping(value = { "/private/users" }, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(httpMethod = "GET", value = "Get list of user", notes = "", response = ReadableUserList.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "store", dataType = "String", defaultValue = "DEFAULT"), @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableUserList list(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "20") Integer count, @RequestParam(value = "emailAddress", required = false) String emailAddress) {
String authenticatedUser = userFacade.authenticatedUser();
if (authenticatedUser == null) {
throw new UnauthorizedException();
}
UserCriteria criteria = new UserCriteria();
if (!StringUtils.isBlank(emailAddress)) {
criteria.setAdminEmail(emailAddress);
}
criteria.setStoreCode(merchantStore.getCode());
if (!userFacade.userInRoles(authenticatedUser, Arrays.asList(Constants.GROUP_SUPERADMIN))) {
if (!userFacade.authorizedStore(authenticatedUser, merchantStore.getCode())) {
throw new UnauthorizedException("Operation unauthorized for user [" + authenticatedUser + "] and store [" + merchantStore + "]");
}
}
userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()));
return userFacade.listByCriteria(criteria, page, count, language);
}
use of com.salesmanager.core.model.user.UserCriteria 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