Search in sources :

Example 81 with ServiceRuntimeException

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

the class CustomerFacadeImpl method updateAddress.

@Override
public void updateAddress(PersistableCustomer customer, MerchantStore store) {
    if (customer.getBilling() != null) {
        Validate.notNull(customer.getBilling(), "Billing address can not be null");
        Validate.notNull(customer.getBilling().getAddress(), "Billing address can not be null");
        Validate.notNull(customer.getBilling().getCity(), "Billing city can not be null");
        Validate.notNull(customer.getBilling().getPostalCode(), "Billing postal code can not be null");
        Validate.notNull(customer.getBilling().getCountry(), "Billing country can not be null");
    }
    if (customer.getDelivery() == null) {
        customer.setDelivery(customer.getBilling());
    } else {
        if (StringUtils.isBlank(customer.getDelivery().getAddress())) {
            customer.getDelivery().setAddress(customer.getBilling().getAddress());
        }
        if (StringUtils.isBlank(customer.getDelivery().getCity())) {
            customer.getDelivery().setAddress(customer.getBilling().getCity());
        }
        if (StringUtils.isBlank(customer.getDelivery().getPostalCode())) {
            customer.getDelivery().setAddress(customer.getBilling().getPostalCode());
        }
        if (StringUtils.isBlank(customer.getDelivery().getCountryCode())) {
            customer.getDelivery().setAddress(customer.getDelivery().getCountryCode());
        }
    }
    try {
        // update billing
        if (customer.getBilling() != null) {
            customer.getBilling().setBillingAddress(true);
            updateAddress(customer.getId(), store, customer.getBilling(), store.getDefaultLanguage());
        }
        // update delivery
        if (customer.getDelivery() != null) {
            customer.getDelivery().setBillingAddress(false);
            updateAddress(customer.getId(), store, customer.getDelivery(), store.getDefaultLanguage());
        }
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while updating customer address");
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 82 with ServiceRuntimeException

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

the class CustomerFacadeImpl method resetPassword.

@Override
public void resetPassword(Customer customer, MerchantStore store, Language language) {
    String password = new String(UUID.generateRandomBytes());
    String encodedPassword = passwordEncoder.encode(password);
    customer.setPassword(encodedPassword);
    try {
        customerService.saveOrUpdate(customer);
    } catch (Exception e) {
        throw new ServiceRuntimeException(e);
    }
    Locale locale = languageService.toLocale(language, store);
    try {
        // creation of a user, send an email
        String[] storeEmail = { store.getStoreEmailAddress() };
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(imageUtils.getContextPath(), store, messages, locale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", locale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, customer.getBilling().getFirstName());
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_LASTNAME, customer.getBilling().getLastName());
        templateTokens.put(EmailConstants.EMAIL_RESET_PASSWORD_TXT, messages.getMessage("email.customer.resetpassword.text", locale));
        templateTokens.put(EmailConstants.EMAIL_CONTACT_OWNER, messages.getMessage("email.contactowner", storeEmail, locale));
        templateTokens.put(EmailConstants.EMAIL_PASSWORD_LABEL, messages.getMessage("label.generic.password", locale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_PASSWORD, password);
        Email email = new Email();
        email.setFrom(store.getStorename());
        email.setFromEmail(store.getStoreEmailAddress());
        email.setSubject(messages.getMessage("label.generic.changepassword", locale));
        email.setTo(customer.getEmailAddress());
        email.setTemplateName(RESET_PASSWORD_TPL);
        email.setTemplateTokens(templateTokens);
        emailService.sendHtmlEmail(store, email);
    } catch (Exception e) {
        LOG.error("Cannot send email to customer", e);
    }
}
Also used : Locale(java.util.Locale) Email(com.salesmanager.core.business.modules.email.Email) ServiceException(com.salesmanager.core.business.exception.ServiceException) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 83 with ServiceRuntimeException

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

the class CustomerFacadeImpl method updateCustomerReview.

@Override
public PersistableCustomerReview updateCustomerReview(Long id, Long reviewId, PersistableCustomerReview review, MerchantStore store, Language language) {
    CustomerReview customerReview = getCustomerReviewById(reviewId);
    if (!customerReview.getReviewedCustomer().getId().equals(id)) {
        throw new ResourceNotFoundException("Customer review with id " + reviewId + " does not exist for this customer");
    }
    // rating maximum 5
    if (review.getRating() > Constants.MAX_REVIEW_RATING_SCORE) {
        throw new ServiceRuntimeException("Maximum rating score is " + Constants.MAX_REVIEW_RATING_SCORE);
    }
    review.setReviewedCustomer(id);
    return review;
}
Also used : ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ReadableCustomerReview(com.salesmanager.shop.model.customer.ReadableCustomerReview) CustomerReview(com.salesmanager.core.model.customer.review.CustomerReview) PersistableCustomerReview(com.salesmanager.shop.model.customer.PersistableCustomerReview) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 84 with ServiceRuntimeException

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

the class SecurityFacadeImpl method getPermissions.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public List<ReadablePermission> getPermissions(List<String> groups) {
    List<Group> userGroups = null;
    try {
        userGroups = groupService.listGroupByNames(groups);
        List<Integer> ids = new ArrayList<Integer>();
        for (Group g : userGroups) {
            ids.add(g.getId());
        }
        PermissionCriteria criteria = new PermissionCriteria();
        criteria.setGroupIds(new HashSet(ids));
        PermissionList permissions = permissionService.listByCriteria(criteria);
        throw new ServiceRuntimeException("Not implemented");
    } catch (ServiceException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : PermissionCriteria(com.salesmanager.core.model.user.PermissionCriteria) Group(com.salesmanager.core.model.user.Group) ServiceException(com.salesmanager.core.business.exception.ServiceException) PermissionList(com.salesmanager.core.model.user.PermissionList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 85 with ServiceRuntimeException

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

the class ShippingFacadeImpl method saveExpeditionConfiguration.

@Override
public void saveExpeditionConfiguration(ExpeditionConfiguration expedition, MerchantStore store) {
    Validate.notNull(expedition, "ExpeditionConfiguration cannot be null");
    try {
        // get original configuration
        ShippingConfiguration config = getDbConfig(store);
        config.setTaxOnShipping(expedition.isTaxOnShipping());
        config.setShippingType(expedition.isIternationalShipping() ? ShippingType.INTERNATIONAL : ShippingType.NATIONAL);
        this.saveShippingConfiguration(config, store);
        shippingService.setSupportedCountries(store, expedition.getShipToCountry());
    } catch (ServiceException e) {
        LOGGER.error("Error while getting expedition configuration", e);
        throw new ServiceRuntimeException("Error while getting Expedition configuration for store[" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) ShippingConfiguration(com.salesmanager.core.model.shipping.ShippingConfiguration) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

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