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");
}
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations