Search in sources :

Example 46 with ServiceRuntimeException

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);
    }
}
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 47 with ServiceRuntimeException

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);
    }
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 48 with ServiceRuntimeException

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);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) Content(com.salesmanager.core.model.content.Content) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 49 with ServiceRuntimeException

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);
    }
}
Also used : Content(com.salesmanager.core.model.content.Content) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConstraintException(com.salesmanager.shop.store.api.exception.ConstraintException) IOException(java.io.IOException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 50 with ServiceRuntimeException

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);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) Content(com.salesmanager.core.model.content.Content) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)146 ServiceException (com.salesmanager.core.business.exception.ServiceException)123 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)100 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)37 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)31 List (java.util.List)31 Collectors (java.util.stream.Collectors)31 Language (com.salesmanager.core.model.reference.language.Language)30 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)27 ArrayList (java.util.ArrayList)27 ConversionException (com.salesmanager.core.business.exception.ConversionException)26 Autowired (org.springframework.beans.factory.annotation.Autowired)21 Service (org.springframework.stereotype.Service)20 Optional (java.util.Optional)19 Product (com.salesmanager.core.model.catalog.product.Product)17 IOException (java.io.IOException)17 Logger (org.slf4j.Logger)17 LoggerFactory (org.slf4j.LoggerFactory)17 Inject (javax.inject.Inject)16 Page (org.springframework.data.domain.Page)16