use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException 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.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class StoreFacadeImpl method getMerchantStoreNames.
@Override
public List<ReadableMerchantStore> getMerchantStoreNames(MerchantStoreCriteria criteria) {
Validate.notNull(criteria, "MerchantStoreCriteria must not be null");
try {
List<ReadableMerchantStore> stores = null;
Optional<String> code = Optional.ofNullable(criteria.getStoreCode());
// TODO Pageable
if (code.isPresent()) {
stores = merchantStoreService.findAllStoreNames(code.get()).stream().map(s -> convertStoreName(s)).collect(Collectors.toList());
} else {
stores = merchantStoreService.findAllStoreNames().stream().map(s -> convertStoreName(s)).collect(Collectors.toList());
}
return stores;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while getting store name", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method getContent.
@Override
public ReadableContentFull getContent(String code, MerchantStore store, Language language) {
Validate.notNull(store, "MerchantStore not null");
Validate.notNull(code, "Content code must not be null");
try {
Content content = contentService.getByCode(code, store);
if (content == null) {
throw new ResourceNotFoundException("No content found with code [" + code + "] for store [" + store.getCode() + "]");
}
return this.convertContentToReadableContentFull(store, language, content);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting content [" + code + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method saveContentPage.
@Override
public Long saveContentPage(PersistableContentPage page, MerchantStore merchantStore, Language language) {
Validate.notNull(page);
Validate.notNull(page.getCode(), "Content code must not be null");
Validate.notNull(merchantStore);
try {
Content content = null;
content = contentService.getByCode(page.getCode(), merchantStore);
if (content != null) {
throw new ConstraintException("Page with code [" + page.getCode() + "] already exist for store [" + merchantStore.getCode() + "]");
}
content = convertContentPageToContent(merchantStore, content, page);
contentService.saveOrUpdate(content);
return content.getId();
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method delete.
@Override
public void delete(MerchantStore store, Long id) {
Validate.notNull(store, "MerchantStore not null");
Validate.notNull(id, "Content id must not be null");
// select content first
Content content = contentService.getById(id);
if (content != null) {
if (content.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("No content found with id [" + id + "] for store [" + store.getCode() + "]");
}
}
try {
contentService.delete(content);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while deleting content " + e.getMessage(), e);
}
}
Aggregations