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