Search in sources :

Example 96 with ResourceNotFoundException

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

the class UserFacadeImpl method requestPasswordReset.

@Override
public void requestPasswordReset(String userName, String userContextPath, MerchantStore store, Language language) {
    Validate.notNull(userName, "Username cannot be empty");
    Validate.notNull(userContextPath, "Return url cannot be empty");
    try {
        // get user by user name
        User user = userService.getByUserName(userName, store.getCode());
        if (user == null) {
            throw new ResourceNotFoundException("User [" + userName + "] 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);
        user.setCredentialsResetRequest(credsRequest);
        userService.saveOrUpdate(user);
        // reset password link
        // this will build http | https ://domain/contextPath
        String baseUrl = userContextPath;
        if (!filePathUtils.isValidURL(baseUrl)) {
            throw new ServiceRuntimeException("Request url [" + baseUrl + "] is invalid");
        }
        // need to add link to controller receiving user reset password
        // request
        String customerResetLink = new StringBuilder().append(baseUrl).append(Constants.SLASH).append(String.format(resetUserLink, store.getCode(), token)).toString();
        resetPasswordRequest(user, customerResetLink, store, lamguageService.toLocale(language, store));
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while executing resetPassword request", e);
    }
}
Also used : ReadableUser(com.salesmanager.shop.model.user.ReadableUser) User(com.salesmanager.core.model.user.User) PersistableUser(com.salesmanager.shop.model.user.PersistableUser) 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) 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) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 97 with ResourceNotFoundException

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

the class CatalogFacadeImpl method getCatalog.

@Override
public ReadableCatalog getCatalog(Long id, MerchantStore store, Language language) {
    Validate.notNull(id, "Catalog id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Catalog catalog = catalogService.getById(id, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + id + "] not found"));
    return readableCatalogMapper.convert(catalog, store, language);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 98 with ResourceNotFoundException

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

the class CatalogFacadeImpl method addCatalogEntry.

@Override
public ReadableCatalogCategoryEntry addCatalogEntry(PersistableCatalogCategoryEntry entry, MerchantStore store, Language language) {
    Validate.notNull(entry, "PersistableCatalogEntry cannot be null");
    Validate.notNull(entry.getCatalog(), "CatalogEntry.catalog cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Catalog catalog = catalogService.getByCode(entry.getCatalog(), store).orElseThrow(() -> new ResourceNotFoundException("catalog [" + entry.getCatalog() + "] not found"));
    CatalogCategoryEntry catalogEntryModel = persistableCatalogEntryMapper.convert(entry, store, language);
    catalogEntryService.add(catalogEntryModel, catalog);
    return readableCatalogEntryMapper.convert(catalogEntryModel, store, language);
}
Also used : PersistableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.PersistableCatalogCategoryEntry) ReadableCatalogCategoryEntry(com.salesmanager.shop.model.catalog.catalog.ReadableCatalogCategoryEntry) CatalogCategoryEntry(com.salesmanager.core.model.catalog.catalog.CatalogCategoryEntry) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 99 with ResourceNotFoundException

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

the class CatalogFacadeImpl method getCatalog.

@Override
public ReadableCatalog getCatalog(String code, MerchantStore store, Language language) {
    Validate.notNull(code, "Catalog code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(language, "Language cannot be null");
    Catalog catalog = catalogService.getByCode(code, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with code [" + code + "] not found"));
    return readableCatalogMapper.convert(catalog, store, language);
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) Catalog(com.salesmanager.core.model.catalog.catalog.Catalog) PersistableCatalog(com.salesmanager.shop.model.catalog.catalog.PersistableCatalog)

Example 100 with ResourceNotFoundException

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

the class CategoryFacadeImpl method getById.

private Category getById(MerchantStore store, Long id) throws Exception {
    Validate.notNull(id, "category id must not be null");
    Validate.notNull(store, "MerchantStore must not be null");
    Category category = categoryService.getById(id, store.getId());
    if (category == null) {
        throw new ResourceNotFoundException("Category with id [" + id + "] not found");
    }
    if (category.getMerchantStore().getId().intValue() != store.getId().intValue()) {
        throw new UnauthorizedException("Unauthorized");
    }
    return category;
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory) PersistableCategory(com.salesmanager.shop.model.catalog.category.PersistableCategory) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

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