Search in sources :

Example 91 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxClass.

@Override
public ReadableTaxClass taxClass(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "TaxClass code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxClass model = taxClassService.getByCode(code, store);
        if (model == null) {
            throw new ResourceNotFoundException("TaxClass not found [" + code + "] for store [" + store.getCode() + "]");
        }
        if (model != null) {
            if (!model.getMerchantStore().getCode().equals(store.getCode())) {
                throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot get tax class [" + code + "]");
            }
        }
        return readableTaxClassMapper.convert(model, store, language);
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxClass [" + code + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxClass [" + code + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 92 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method taxRateByCode.

// get by code
private TaxRate taxRateByCode(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "TaxRate code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxRate model = taxRateService.getByCode(code, store);
        if (model == null) {
            throw new ResourceNotFoundException("TaxRate not found [" + code + "] for store [" + store.getCode() + "]");
        }
        if (model != null) {
            if (!model.getMerchantStore().getCode().equals(store.getCode())) {
                throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot get tax rate [" + code + "]");
            }
        }
        return model;
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxRate [" + code + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxRate [" + code + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 93 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method updateTaxClass.

@Override
public void updateTaxClass(Long id, PersistableTaxClass taxClass, MerchantStore store, Language language) {
    Validate.notNull(taxClass, "TaxClass cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxClass model = taxClassService.getById(id);
        if (model == null) {
            throw new ResourceNotFoundException("TaxClass not found [" + id + "] for store [" + store.getCode() + "]");
        } else {
            if (!model.getMerchantStore().getCode().equals(store.getCode())) {
                throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot update tax class [" + taxClass.getCode() + "]");
            }
        }
        model = persistableTaxClassMapper.convert(taxClass, store, language);
        taxClassService.saveOrUpdate(model);
    } catch (ServiceException e) {
        LOGGER.error("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) TaxClass(com.salesmanager.core.model.tax.taxclass.TaxClass) ReadableTaxClass(com.salesmanager.shop.model.tax.ReadableTaxClass) PersistableTaxClass(com.salesmanager.shop.model.tax.PersistableTaxClass) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 94 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class UserFacadeImpl method findById.

@Override
public ReadableUser findById(Long id, MerchantStore store, Language lang) {
    Validate.notNull(store, "MerchantStore cannot be null");
    User user = userService.getById(id, store);
    if (user == null) {
        throw new ResourceNotFoundException("User [" + id + "] not found");
    }
    return convertUserToReadableUser(lang, user);
}
Also used : ReadableUser(com.salesmanager.shop.model.user.ReadableUser) User(com.salesmanager.core.model.user.User) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 95 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.

the class UserFacadeImpl method verifyUserLink.

private User verifyUserLink(String token, String store) {
    User user = null;
    try {
        user = userService.getByPasswordResetToken(store, token);
        if (user == null) {
            throw new ResourceNotFoundException("Customer not fount for store [" + store + "] and token [" + token + "]");
        }
    } catch (Exception e) {
        throw new ServiceRuntimeException("Cannot verify customer token", e);
    }
    Date tokenExpiry = user.getCredentialsResetRequest().getCredentialsRequestExpiry();
    if (tokenExpiry == null) {
        throw new GenericRuntimeException("No expiry date configured for token [" + token + "]");
    }
    if (!DateUtil.dateBeforeEqualsDate(new Date(), tokenExpiry)) {
        throw new GenericRuntimeException("Ttoken [" + token + "] has expired");
    }
    return user;
}
Also used : ReadableUser(com.salesmanager.shop.model.user.ReadableUser) User(com.salesmanager.core.model.user.User) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) GenericRuntimeException(com.salesmanager.shop.store.api.exception.GenericRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) GenericRuntimeException(com.salesmanager.shop.store.api.exception.GenericRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) Date(java.util.Date) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)108 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)77 ServiceException (com.salesmanager.core.business.exception.ServiceException)62 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)22 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)22 Product (com.salesmanager.core.model.catalog.product.Product)21 Language (com.salesmanager.core.model.reference.language.Language)19 List (java.util.List)19 Collectors (java.util.stream.Collectors)19 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)17 ArrayList (java.util.ArrayList)17 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)16 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)15 Autowired (org.springframework.beans.factory.annotation.Autowired)15 ConversionException (com.salesmanager.core.business.exception.ConversionException)13 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)13 Inject (javax.inject.Inject)12 Optional (java.util.Optional)11 Service (org.springframework.stereotype.Service)11 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)11