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