use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ContentFacadeImpl method delete.
@Override
public void delete(MerchantStore store, Long id) {
Validate.notNull(store, "MerchantStore not null");
Validate.notNull(id, "Content id must not be null");
// select content first
Content content = contentService.getById(id);
if (content != null) {
if (content.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("No content found with id [" + id + "] for store [" + store.getCode() + "]");
}
}
try {
contentService.delete(content);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Exception while deleting content " + e.getMessage(), e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException 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.ResourceNotFoundException 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.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ShippingFacadeImpl method getShippingOrigin.
@Override
public ReadableAddress getShippingOrigin(MerchantStore store) {
ShippingOrigin o = shippingOriginService.getByStore(store);
if (o == null) {
throw new ResourceNotFoundException("Shipping origin does not exists for store [" + store.getCode() + "]");
}
ReadableAddress address = new ReadableAddress();
address.setAddress(o.getAddress());
address.setActive(o.isActive());
address.setCity(o.getCity());
address.setPostalCode(o.getPostalCode());
if (o.getCountry() != null) {
address.setCountry(o.getCountry().getIsoCode());
}
Zone z = o.getZone();
if (z != null) {
address.setStateProvince(z.getCode());
} else {
address.setStateProvince(o.getState());
}
return address;
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class ShoppingCartFacadeImpl method addToCart.
@Override
public ReadableShoppingCart addToCart(PersistableShoppingCartItem item, MerchantStore store, Language language) {
Validate.notNull(item, "PersistableShoppingCartItem cannot be null");
// if cart does not exist create a new one
ShoppingCart cartModel = new ShoppingCart();
cartModel.setMerchantStore(store);
cartModel.setShoppingCartCode(uniqueShoppingCartCode());
if (!StringUtils.isBlank(item.getPromoCode())) {
cartModel.setPromoCode(item.getPromoCode());
cartModel.setPromoAdded(new Date());
}
try {
return readableShoppingCart(cartModel, item, store, language);
} catch (Exception e) {
if (e instanceof ResourceNotFoundException) {
throw (ResourceNotFoundException) e;
} else {
throw new ServiceRuntimeException(e);
}
}
}
Aggregations