Search in sources :

Example 86 with ResourceNotFoundException

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

the class CustomerFacadeImpl method verifyCustomerLink.

private Customer verifyCustomerLink(String token, String store) {
    Customer customer = null;
    try {
        customer = customerService.getByPasswordResetToken(store, token);
        if (customer == 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 = customer.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 customer;
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) GenericRuntimeException(com.salesmanager.shop.store.api.exception.GenericRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) GenericRuntimeException(com.salesmanager.shop.store.api.exception.GenericRuntimeException) Date(java.util.Date) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 87 with ResourceNotFoundException

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

the class ManufacturerFacadeImpl method getManufacturer.

@Override
public ReadableManufacturer getManufacturer(Long id, MerchantStore store, Language language) throws Exception {
    Manufacturer manufacturer = manufacturerService.getById(id);
    if (manufacturer == null) {
        throw new ResourceNotFoundException("Manufacturer [" + id + "] not found");
    }
    if (manufacturer.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Manufacturer [" + id + "] not found for store [" + store.getId() + "]");
    }
    ReadableManufacturer readableManufacturer = new ReadableManufacturer();
    ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
    readableManufacturer = populator.populate(manufacturer, readableManufacturer, store, language);
    return readableManufacturer;
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 88 with ResourceNotFoundException

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

the class ManufacturerFacadeImpl method saveOrUpdateManufacturer.

@Override
public void saveOrUpdateManufacturer(PersistableManufacturer manufacturer, MerchantStore store, Language language) throws Exception {
    PersistableManufacturerPopulator populator = new PersistableManufacturerPopulator();
    populator.setLanguageService(languageService);
    Manufacturer manuf = new Manufacturer();
    if (manufacturer.getId() != null && manufacturer.getId().longValue() > 0) {
        manuf = manufacturerService.getById(manufacturer.getId());
        if (manuf == null) {
            throw new ResourceNotFoundException("Manufacturer with id [" + manufacturer.getId() + "] not found");
        }
        if (manuf.getMerchantStore().getId().intValue() != store.getId().intValue()) {
            throw new ResourceNotFoundException("Manufacturer with id [" + manufacturer.getId() + "] not found for store [" + store.getId() + "]");
        }
    }
    populator.populate(manufacturer, manuf, store, language);
    manufacturerService.saveOrUpdate(manuf);
    manufacturer.setId(manuf.getId());
}
Also used : PersistableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Example 89 with ResourceNotFoundException

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

the class ShoppingCartFacadeImpl method get.

// facade
@Override
public ReadableShoppingCart get(Optional<String> cart, Long customerId, MerchantStore store, Language language) {
    Validate.notNull(customerId, "Customer id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    try {
        // lookup customer
        Customer customer = customerService.getById(customerId);
        if (customer == null) {
            throw new ResourceNotFoundException("No Customer found for id [" + customerId + "]");
        }
        ShoppingCart cartModel = shoppingCartService.getShoppingCart(customer);
        if (cart.isPresent()) {
            cartModel = customerFacade.mergeCart(customer, cart.get(), store, language);
        }
        if (cartModel == null) {
            return null;
        }
        ReadableShoppingCart readableCart = shoppingCartFacade.readableCart(cartModel, store, language);
        return readableCart;
    } catch (Exception e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) Customer(com.salesmanager.core.model.customer.Customer) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 90 with ResourceNotFoundException

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

the class TaxFacadeImpl method deleteTaxClass.

@Override
public void deleteTaxClass(Long id, MerchantStore store, Language language) {
    Validate.notNull(id, "TaxClass id 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 delete tax class [" + id + "]");
            }
        }
        taxClassService.delete(model);
    } catch (ServiceException e) {
        LOGGER.error("Error while getting taxClasse [" + id + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while getting taxClasse [" + id + "] 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)

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