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