Search in sources :

Example 36 with ResourceNotFoundException

use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException 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)

Example 37 with ResourceNotFoundException

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

the class CustomerFacadeImpl method requestPasswordReset.

@Override
public void requestPasswordReset(String customerName, String customerContextPath, MerchantStore store, Language language) {
    try {
        // get customer by user name
        Customer customer = customerService.getByNick(customerName, store.getId());
        if (customer == null) {
            throw new ResourceNotFoundException("Customer [" + customerName + "] not found for store [" + store.getCode() + "]");
        }
        // generates unique token
        String token = UUID.randomUUID().toString();
        Date expiry = DateUtil.addDaysToCurrentDate(2);
        CredentialsReset credsRequest = new CredentialsReset();
        credsRequest.setCredentialsRequest(token);
        credsRequest.setCredentialsRequestExpiry(expiry);
        customer.setCredentialsResetRequest(credsRequest);
        customerService.saveOrUpdate(customer);
        // reset password link
        // this will build http | https ://domain/contextPath
        String baseUrl = filePathUtils.buildBaseUrl(customerContextPath, store);
        // need to add link to controller receiving user reset password
        // request
        String customerResetLink = new StringBuilder().append(baseUrl).append(String.format(resetCustomerLink, store.getCode(), token)).toString();
        resetPasswordRequest(customer, customerResetLink, store, lamguageService.toLocale(language, store));
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while executing resetPassword request", e);
    }
/**
 * User sends username (unique in the system)
 *
 * UserNameEntity will be the following { userName: "test@test.com" }
 *
 * The system retrieves user using userName (username is unique) if user
 * exists, system sends an email with reset password link
 *
 * How to retrieve a User from userName
 *
 * userFacade.findByUserName
 *
 * How to send an email
 *
 * How to generate a token
 *
 * Generate random token
 *
 * Calculate token expiration date
 *
 * Now + 48 hours
 *
 * Update User in the database with token
 *
 * Send reset token email
 */
}
Also used : Customer(com.salesmanager.core.model.customer.Customer) CredentialsReset(com.salesmanager.core.model.common.CredentialsReset) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Date(java.util.Date) 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) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 38 with ResourceNotFoundException

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

the class ManufacturerFacadeImpl method getByProductInCategory.

@Override
public List<ReadableManufacturer> getByProductInCategory(MerchantStore store, Language language, Long categoryId) {
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Validate.notNull(categoryId, "Category id cannot be null");
    Category category = categoryService.getById(categoryId, store.getId());
    if (category == null) {
        throw new ResourceNotFoundException("Category with id [" + categoryId + "] not found");
    }
    if (category.getMerchantStore().getId().longValue() != store.getId().longValue()) {
        throw new UnauthorizedException("Merchant [" + store.getCode() + "] not authorized");
    }
    try {
        List<Manufacturer> manufacturers = manufacturerService.listByProductsInCategory(store, category, language);
        List<ReadableManufacturer> manufacturersList = manufacturers.stream().sorted(new Comparator<Manufacturer>() {

            @Override
            public int compare(final Manufacturer object1, final Manufacturer object2) {
                return object1.getCode().compareTo(object2.getCode());
            }
        }).map(manuf -> readableManufacturerConverter.convert(manuf, store, language)).collect(Collectors.toList());
        return manufacturersList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException(e);
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) LanguageService(com.salesmanager.core.business.services.reference.language.LanguageService) ArrayList(java.util.ArrayList) ServiceException(com.salesmanager.core.business.exception.ServiceException) Inject(javax.inject.Inject) Language(com.salesmanager.core.model.reference.language.Language) ListCriteria(com.salesmanager.shop.model.entity.ListCriteria) PersistableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.PersistableManufacturerPopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Service(org.springframework.stereotype.Service) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) CategoryService(com.salesmanager.core.business.services.catalog.category.CategoryService) ManufacturerService(com.salesmanager.core.business.services.catalog.product.manufacturer.ManufacturerService) Mapper(com.salesmanager.shop.mapper.Mapper) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturerList(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturerList) Validate(org.jsoup.helper.Validate) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) Category(com.salesmanager.core.model.catalog.category.Category) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) List(java.util.List) ManufacturerFacade(com.salesmanager.shop.store.controller.manufacturer.facade.ManufacturerFacade) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) Comparator(java.util.Comparator) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Category(com.salesmanager.core.model.catalog.category.Category) ServiceException(com.salesmanager.core.business.exception.ServiceException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) 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) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 39 with ResourceNotFoundException

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

the class ShippingFacadeImpl method getShippingOrigin.

@Override
public ReadableAddress getShippingOrigin(MerchantStore store) {
    ShippingOrigin o = shippingOriginService.getByStore(store);
    if (o == null) {
        throw new ResourceNotFoundException("Shipping origin does not exists for store [" + store.getCode() + "]");
    }
    ReadableAddress address = new ReadableAddress();
    address.setAddress(o.getAddress());
    address.setActive(o.isActive());
    address.setCity(o.getCity());
    address.setPostalCode(o.getPostalCode());
    if (o.getCountry() != null) {
        address.setCountry(o.getCountry().getIsoCode());
    }
    Zone z = o.getZone();
    if (z != null) {
        address.setStateProvince(z.getCode());
    } else {
        address.setStateProvince(o.getState());
    }
    return address;
}
Also used : Zone(com.salesmanager.core.model.reference.zone.Zone) ReadableAddress(com.salesmanager.shop.model.references.ReadableAddress) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ShippingOrigin(com.salesmanager.core.model.shipping.ShippingOrigin)

Example 40 with ResourceNotFoundException

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

the class ShoppingCartFacadeImpl method addToCart.

@Override
public ReadableShoppingCart addToCart(PersistableShoppingCartItem item, MerchantStore store, Language language) {
    Validate.notNull(item, "PersistableShoppingCartItem cannot be null");
    // if cart does not exist create a new one
    ShoppingCart cartModel = new ShoppingCart();
    cartModel.setMerchantStore(store);
    cartModel.setShoppingCartCode(uniqueShoppingCartCode());
    if (!StringUtils.isBlank(item.getPromoCode())) {
        cartModel.setPromoCode(item.getPromoCode());
        cartModel.setPromoAdded(new Date());
    }
    try {
        return readableShoppingCart(cartModel, item, store, language);
    } catch (Exception e) {
        if (e instanceof ResourceNotFoundException) {
            throw (ResourceNotFoundException) e;
        } else {
            throw new ServiceRuntimeException(e);
        }
    }
}
Also used : ShoppingCart(com.salesmanager.core.model.shoppingcart.ShoppingCart) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) Date(java.util.Date) LocalDate(java.time.LocalDate) NoResultException(javax.persistence.NoResultException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) CartModificationException(com.salesmanager.shop.model.shoppingcart.CartModificationException) 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