Search in sources :

Example 51 with ServiceRuntimeException

use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException 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 52 with ServiceRuntimeException

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

the class ProductItemsFacadeImpl method deleteGroup.

@Override
public void deleteGroup(String group, MerchantStore store) {
    Validate.notNull(group, "Group cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    try {
        productRelationshipService.deleteGroup(store, group);
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Cannor delete product group", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 53 with ServiceRuntimeException

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

the class ProductItemsFacadeImpl method addItemToGroup.

@Override
public ReadableProductList addItemToGroup(Product product, String group, MerchantStore store, Language language) {
    Validate.notNull(product, "Product must not be null");
    Validate.notNull(group, "group must not be null");
    // check if product is already in group
    List<ProductRelationship> existList = null;
    try {
        existList = productRelationshipService.getByGroup(store, group).stream().filter(prod -> prod.getRelatedProduct() != null && (product.getId().longValue() == prod.getRelatedProduct().getId())).collect(Collectors.toList());
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("ExceptionWhile getting product group [" + group + "]", e);
    }
    if (existList.size() > 0) {
        throw new OperationNotAllowedException("Product with id [" + product.getId() + "] is already in the group");
    }
    ProductRelationship relationship = new ProductRelationship();
    relationship.setActive(true);
    relationship.setCode(group);
    relationship.setStore(store);
    relationship.setRelatedProduct(product);
    try {
        productRelationshipService.saveOrUpdate(relationship);
        return listItemsByGroup(group, store, language);
    } catch (Exception e) {
        throw new ServiceRuntimeException("ExceptionWhile getting product group [" + group + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ProductRelationship(com.salesmanager.core.model.catalog.product.relationship.ProductRelationship) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 54 with ServiceRuntimeException

use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException 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 55 with ServiceRuntimeException

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

the class CustomerFacadeImpl method update.

@Override
public PersistableCustomer update(PersistableCustomer customer, MerchantStore store) {
    if (customer.getId() == null || customer.getId() == 0) {
        throw new ServiceRuntimeException("Can't update a customer with null id");
    }
    Customer cust = customerService.getById(customer.getId());
    try {
        customerPopulator.populate(customer, cust, store, store.getDefaultLanguage());
    } catch (ConversionException e) {
        throw new ConversionRuntimeException(e);
    }
    String password = customer.getPassword();
    if (StringUtils.isBlank(password)) {
        password = new String(UUID.generateRandomBytes());
        customer.setPassword(password);
    }
    saveCustomer(cust);
    customer.setId(cust.getId());
    return customer;
}
Also used : ConversionException(com.salesmanager.core.business.exception.ConversionException) ReadableCustomer(com.salesmanager.shop.model.customer.ReadableCustomer) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException)

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