Search in sources :

Example 1 with MerchantStoreCriteria

use of com.salesmanager.core.model.merchant.MerchantStoreCriteria 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 MerchantStoreCriteria

use of com.salesmanager.core.model.merchant.MerchantStoreCriteria 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 3 with MerchantStoreCriteria

use of com.salesmanager.core.model.merchant.MerchantStoreCriteria 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)

Example 4 with MerchantStoreCriteria

use of com.salesmanager.core.model.merchant.MerchantStoreCriteria in project shopizer by shopizer-ecommerce.

the class ServiceRequestCriteriaBuilderUtils method buildRequest.

/**
 * deprecated *
 */
public static Criteria buildRequest(Map<String, String> mappingFields, HttpServletRequest request) {
    /**
     * Works assuming datatable sends query data
     */
    MerchantStoreCriteria criteria = new MerchantStoreCriteria();
    String searchParam = request.getParameter("search[value]");
    String orderColums = request.getParameter("order[0][column]");
    if (!StringUtils.isBlank(orderColums)) {
        String columnName = request.getParameter("columns[" + orderColums + "][data]");
        String overwriteField = columnName;
        if (mappingFields != null && mappingFields.get(columnName) != null) {
            overwriteField = mappingFields.get(columnName);
        }
        criteria.setCriteriaOrderByField(overwriteField);
        criteria.setOrderBy(CriteriaOrderBy.valueOf(request.getParameter("order[0][dir]").toUpperCase()));
    }
    String storeName = request.getParameter("storeName");
    criteria.setName(storeName);
    String retailers = request.getParameter("retailers");
    String stores = request.getParameter("stores");
    try {
        boolean retail = Boolean.valueOf(retailers);
        boolean sto = Boolean.valueOf(stores);
        criteria.setRetailers(retail);
        criteria.setStores(sto);
    } catch (Exception e) {
        LOGGER.error("Error parsing boolean values", e);
    }
    criteria.setSearch(searchParam);
    return criteria;
}
Also used : MerchantStoreCriteria(com.salesmanager.core.model.merchant.MerchantStoreCriteria) RestApiException(com.salesmanager.shop.store.api.exception.RestApiException)

Aggregations

MerchantStoreCriteria (com.salesmanager.core.model.merchant.MerchantStoreCriteria)4 ReadableMerchantStoreList (com.salesmanager.shop.model.store.ReadableMerchantStoreList)3 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ServiceException (com.salesmanager.core.business.exception.ServiceException)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 InputContentFile (com.salesmanager.core.model.content.InputContentFile)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 MerchantConfiguration (com.salesmanager.core.model.system.MerchantConfiguration)1 MerchantConfigurationType (com.salesmanager.core.model.system.MerchantConfigurationType)1 ReadableImage (com.salesmanager.shop.model.content.ReadableImage)1