Search in sources :

Example 1 with Criteria

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

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 UserCriteria (com.salesmanager.core.model.user.UserCriteria)1 Constants (com.salesmanager.shop.constants.Constants)1 EmailConstants (com.salesmanager.shop.constants.EmailConstants)1 PersistableGroup (com.salesmanager.shop.model.security.PersistableGroup)1