Search in sources :

Example 1 with ReadableMerchantStoreList

use of com.salesmanager.shop.model.store.ReadableMerchantStoreList in project shopizer by shopizer-ecommerce.

the class StoreFacadeImpl method getMerchantStoresByCriteria.

private ReadableMerchantStoreList getMerchantStoresByCriteria(MerchantStoreCriteria criteria, Language language) {
    try {
        GenericEntityList<MerchantStore> stores = Optional.ofNullable(merchantStoreService.getByCriteria(criteria)).orElseThrow(() -> new ResourceNotFoundException("Criteria did not match any store"));
        ReadableMerchantStoreList storeList = new ReadableMerchantStoreList();
        storeList.setData((List<ReadableMerchantStore>) stores.getList().stream().map(s -> convertMerchantStoreToReadableMerchantStore(language, s)).collect(Collectors.toList()));
        storeList.setTotalPages(stores.getTotalPages());
        storeList.setRecordsTotal(stores.getTotalCount());
        storeList.setNumber(stores.getList().size());
        return storeList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : MerchantConfigEntity(com.salesmanager.shop.model.store.MerchantConfigEntity) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) PersistableMerchantStorePopulator(com.salesmanager.shop.populator.store.PersistableMerchantStorePopulator) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ReadableBrand(com.salesmanager.shop.model.store.ReadableBrand) CollectionUtils(org.apache.commons.collections4.CollectionUtils) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ZoneService(com.salesmanager.core.business.services.reference.zone.ZoneService) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) PersistableBrand(com.salesmanager.shop.model.store.PersistableBrand) MerchantStoreCriteria(com.salesmanager.core.model.merchant.MerchantStoreCriteria) HttpServletRequest(javax.servlet.http.HttpServletRequest) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) GenericEntityList(com.salesmanager.core.model.common.GenericEntityList) ReadableMerchantStorePopulator(com.salesmanager.shop.populator.store.ReadableMerchantStorePopulator) MerchantStoreService(com.salesmanager.core.business.services.merchant.MerchantStoreService) MeasureUnit(com.salesmanager.core.constants.MeasureUnit) CountryService(com.salesmanager.core.business.services.reference.country.CountryService) Logger(org.slf4j.Logger) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ImageFilePath(com.salesmanager.shop.utils.ImageFilePath) Page(org.springframework.data.domain.Page) InputContentFile(com.salesmanager.core.model.content.InputContentFile) Collectors(java.util.stream.Collectors) MerchantConfigurationService(com.salesmanager.core.business.services.system.MerchantConfigurationService) ContentService(com.salesmanager.core.business.services.content.ContentService) List(java.util.List) ReadableImage(com.salesmanager.shop.model.content.ReadableImage) Validate(org.apache.commons.lang3.Validate) MerchantConfiguration(com.salesmanager.core.model.system.MerchantConfiguration) LanguageUtils(com.salesmanager.shop.utils.LanguageUtils) MerchantConfigurationType(com.salesmanager.core.model.system.MerchantConfigurationType) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) Optional(java.util.Optional) ConversionException(com.salesmanager.core.business.exception.ConversionException) Collections(java.util.Collections) StringUtils(org.drools.core.util.StringUtils) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with ReadableMerchantStoreList

use of com.salesmanager.shop.model.store.ReadableMerchantStoreList in project shopizer by shopizer-ecommerce.

the class StoreFacadeImpl method getChildStores.

@Override
public ReadableMerchantStoreList getChildStores(Language language, String code, int page, int count) {
    try {
        // first check if store is retailer
        MerchantStore retailer = this.getByCode(code);
        if (retailer == null) {
            throw new ResourceNotFoundException("Merchant [" + code + "] not found");
        }
        if (retailer.isRetailer() == null || !retailer.isRetailer().booleanValue()) {
            throw new ResourceNotFoundException("Merchant [" + code + "] not a retailer");
        }
        Page<MerchantStore> children = merchantStoreService.listChildren(code, page, count);
        List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
        ReadableMerchantStoreList readableList = new ReadableMerchantStoreList();
        if (!CollectionUtils.isEmpty(children.getContent())) {
            for (MerchantStore store : children) readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
        }
        readableList.setData(readableStores);
        readableList.setRecordsFiltered(children.getSize());
        readableList.setTotalPages(children.getTotalPages());
        readableList.setRecordsTotal(children.getTotalElements());
        readableList.setNumber(children.getNumber());
        return readableList;
    /*			List<MerchantStore> children = merchantStoreService.listChildren(code);
			List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
			if (!CollectionUtils.isEmpty(children)) {
				for (MerchantStore store : children)
					readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
			}
			return readableStores;*/
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ArrayList(java.util.ArrayList) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 3 with ReadableMerchantStoreList

use of com.salesmanager.shop.model.store.ReadableMerchantStoreList in project shopizer by shopizer-ecommerce.

the class MerchantStoreApi method get.

@ResponseStatus(HttpStatus.OK)
@GetMapping(value = { "/private/stores" }, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(httpMethod = "GET", value = "Get list of stores. Returns all retailers and stores. If superadmin everything is returned, else only retailer and child stores.", notes = "", response = ReadableMerchantStore.class)
@ApiImplicitParams({ @ApiImplicitParam(name = "lang", dataType = "String", defaultValue = "en") })
public ReadableMerchantStoreList get(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count, HttpServletRequest request) {
    String authenticatedUser = userFacade.authenticatedUser();
    if (authenticatedUser == null) {
        throw new UnauthorizedException();
    }
    // requires superadmin, admin and admin retail to see all
    userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()));
    MerchantStoreCriteria criteria = createMerchantStoreCriteria(request);
    if (userFacade.userInRoles(authenticatedUser, Arrays.asList(Constants.GROUP_SUPERADMIN))) {
        criteria.setStoreCode(null);
    } else {
        criteria.setStoreCode(merchantStore.getCode());
    }
    // return storeFacade.findAll(criteria, language, page, count);
    ReadableMerchantStoreList readable = storeFacade.findAll(criteria, language, page, count);
    return readable;
}
Also used : ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) MerchantStoreCriteria(com.salesmanager.core.model.merchant.MerchantStoreCriteria) 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 4 with ReadableMerchantStoreList

use of com.salesmanager.shop.model.store.ReadableMerchantStoreList in project shopizer by shopizer-ecommerce.

the class StoreFacadeImpl method findAll.

@Override
public ReadableMerchantStoreList findAll(MerchantStoreCriteria criteria, Language language, int page, int count) {
    try {
        Page<MerchantStore> stores = null;
        List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
        ReadableMerchantStoreList readableList = new ReadableMerchantStoreList();
        Optional<String> code = Optional.ofNullable(criteria.getStoreCode());
        Optional<String> name = Optional.ofNullable(criteria.getName());
        if (code.isPresent()) {
            stores = merchantStoreService.listByGroup(name, code.get(), page, count);
        } else {
            if (criteria.isRetailers()) {
                stores = merchantStoreService.listAllRetailers(name, page, count);
            } else {
                stores = merchantStoreService.listAll(name, page, count);
            }
        }
        if (!CollectionUtils.isEmpty(stores.getContent())) {
            for (MerchantStore store : stores) readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
        }
        readableList.setData(readableStores);
        readableList.setRecordsTotal(stores.getTotalElements());
        readableList.setTotalPages(stores.getTotalPages());
        readableList.setNumber(stores.getSize());
        readableList.setRecordsFiltered(stores.getSize());
        return readableList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while finding all merchant", e);
    }
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ArrayList(java.util.ArrayList) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 5 with ReadableMerchantStoreList

use of com.salesmanager.shop.model.store.ReadableMerchantStoreList in project shopizer by shopizer-ecommerce.

the class MerchantStoreApi method list.

/**
 * List of store names
 * @param merchantStore
 * @param request
 * @return
 */
@ResponseStatus(HttpStatus.OK)
@GetMapping(value = { "/private/stores/names" }, produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(httpMethod = "GET", value = "Get list of store names. Returns all retailers and stores", notes = "", response = ReadableMerchantStore.class)
public List<ReadableMerchantStore> list(@ApiIgnore MerchantStore merchantStore, @ApiIgnore Language language, @RequestParam(value = "page", required = false, defaultValue = "0") Integer page, @RequestParam(value = "count", required = false, defaultValue = "10") Integer count, HttpServletRequest request) {
    String authenticatedUser = userFacade.authenticatedUser();
    if (authenticatedUser == null) {
        throw new UnauthorizedException();
    }
    // requires superadmin, admin and admin retail to see all
    userFacade.authorizedGroup(authenticatedUser, Stream.of(Constants.GROUP_SUPERADMIN, Constants.GROUP_ADMIN, Constants.GROUP_ADMIN_RETAIL).collect(Collectors.toList()));
    MerchantStoreCriteria criteria = createMerchantStoreCriteria(request);
    if (userFacade.userInRoles(authenticatedUser, Arrays.asList(Constants.GROUP_SUPERADMIN))) {
        criteria.setStoreCode(null);
    } else {
        criteria.setStoreCode(merchantStore.getCode());
    }
    ReadableMerchantStoreList list = storeFacade.findAll(criteria, language, page, count);
    return list.getData();
}
Also used : ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) MerchantStoreCriteria(com.salesmanager.core.model.merchant.MerchantStoreCriteria) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ReadableMerchantStoreList (com.salesmanager.shop.model.store.ReadableMerchantStoreList)5 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 MerchantStoreCriteria (com.salesmanager.core.model.merchant.MerchantStoreCriteria)3 PersistableMerchantStore (com.salesmanager.shop.model.store.PersistableMerchantStore)3 ReadableMerchantStore (com.salesmanager.shop.model.store.ReadableMerchantStore)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ArrayList (java.util.ArrayList)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ContentService (com.salesmanager.core.business.services.content.ContentService)1 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)1 CountryService (com.salesmanager.core.business.services.reference.country.CountryService)1 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 ZoneService (com.salesmanager.core.business.services.reference.zone.ZoneService)1 MerchantConfigurationService (com.salesmanager.core.business.services.system.MerchantConfigurationService)1 MeasureUnit (com.salesmanager.core.constants.MeasureUnit)1 GenericEntityList (com.salesmanager.core.model.common.GenericEntityList)1