Search in sources :

Example 1 with UserCriteria

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);
}
Also used : UserCriteria(com.salesmanager.core.model.user.UserCriteria) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with UserCriteria

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);
    }
}
Also used : PermissionService(com.salesmanager.core.business.services.user.PermissionService) Date(java.util.Date) EmailConstants(com.salesmanager.shop.constants.EmailConstants) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ReadableUser(com.salesmanager.shop.model.user.ReadableUser) ServiceException(com.salesmanager.core.business.exception.ServiceException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) Locale(java.util.Locale) Map(java.util.Map) GenericEntityList(com.salesmanager.core.model.common.GenericEntityList) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) MerchantStoreService(com.salesmanager.core.business.services.merchant.MerchantStoreService) ReadableGroup(com.salesmanager.shop.model.security.ReadableGroup) Set(java.util.Set) ReadableUserList(com.salesmanager.shop.model.user.ReadableUserList) ReadableUserPopulator(com.salesmanager.shop.populator.user.ReadableUserPopulator) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) List(java.util.List) PersistableGroup(com.salesmanager.shop.model.security.PersistableGroup) CollectionUtils(org.springframework.util.CollectionUtils) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Optional(java.util.Optional) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Authentication(org.springframework.security.core.Authentication) EmailService(com.salesmanager.core.business.services.system.EmailService) Async(org.springframework.scheduling.annotation.Async) Email(com.salesmanager.core.business.modules.email.Email) Group(com.salesmanager.core.model.user.Group) Constants(com.salesmanager.shop.constants.Constants) DateUtil(com.salesmanager.shop.utils.DateUtil) CredentialsReset(com.salesmanager.core.model.common.CredentialsReset) ReadablePermission(com.salesmanager.shop.model.security.ReadablePermission) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) Permission(com.salesmanager.core.model.user.Permission) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) LabelUtils(com.salesmanager.shop.utils.LabelUtils) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) EmailUtils(com.salesmanager.shop.utils.EmailUtils) UserPassword(com.salesmanager.shop.model.user.UserPassword) User(com.salesmanager.core.model.user.User) Criteria(com.salesmanager.core.model.common.Criteria) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) Validate(org.jsoup.helper.Validate) Logger(org.slf4j.Logger) UserFacade(com.salesmanager.shop.store.controller.user.facade.UserFacade) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) UserService(com.salesmanager.core.business.services.user.UserService) PasswordEncoder(org.springframework.security.crypto.password.PasswordEncoder) PersistableUserPopulator(com.salesmanager.shop.populator.user.PersistableUserPopulator) GenericRuntimeException(com.salesmanager.shop.store.api.exception.GenericRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) FilePathUtils(com.salesmanager.shop.utils.FilePathUtils) UserCriteria(com.salesmanager.core.model.user.UserCriteria) SecurityFacade(com.salesmanager.shop.store.controller.security.facade.SecurityFacade) ReadableUser(com.salesmanager.shop.model.user.ReadableUser) User(com.salesmanager.core.model.user.User) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) ArrayList(java.util.ArrayList) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ReadableUser(com.salesmanager.shop.model.user.ReadableUser) ServiceException(com.salesmanager.core.business.exception.ServiceException) ReadableUserList(com.salesmanager.shop.model.user.ReadableUserList) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore)

Aggregations

UserCriteria (com.salesmanager.core.model.user.UserCriteria)2 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Email (com.salesmanager.core.business.modules.email.Email)1 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)1 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 EmailService (com.salesmanager.core.business.services.system.EmailService)1 PermissionService (com.salesmanager.core.business.services.user.PermissionService)1 UserService (com.salesmanager.core.business.services.user.UserService)1 CredentialsReset (com.salesmanager.core.model.common.CredentialsReset)1 Criteria (com.salesmanager.core.model.common.Criteria)1 GenericEntityList (com.salesmanager.core.model.common.GenericEntityList)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 Group (com.salesmanager.core.model.user.Group)1 Permission (com.salesmanager.core.model.user.Permission)1 User (com.salesmanager.core.model.user.User)1 Constants (com.salesmanager.shop.constants.Constants)1 EmailConstants (com.salesmanager.shop.constants.EmailConstants)1