use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method requestPasswordReset.
@Override
public void requestPasswordReset(String userName, String userContextPath, MerchantStore store, Language language) {
Validate.notNull(userName, "Username cannot be empty");
Validate.notNull(userContextPath, "Return url cannot be empty");
try {
// get user by user name
User user = userService.getByUserName(userName, store.getCode());
if (user == null) {
throw new ResourceNotFoundException("User [" + userName + "] 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);
user.setCredentialsResetRequest(credsRequest);
userService.saveOrUpdate(user);
// reset password link
// this will build http | https ://domain/contextPath
String baseUrl = userContextPath;
if (!filePathUtils.isValidURL(baseUrl)) {
throw new ServiceRuntimeException("Request url [" + baseUrl + "] is invalid");
}
// need to add link to controller receiving user reset password
// request
String customerResetLink = new StringBuilder().append(baseUrl).append(Constants.SLASH).append(String.format(resetUserLink, store.getCode(), token)).toString();
resetPasswordRequest(user, customerResetLink, store, lamguageService.toLocale(language, store));
} catch (Exception e) {
throw new ServiceRuntimeException("Error while executing resetPassword request", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class CatalogFacadeImpl method getCatalog.
@Override
public ReadableCatalog getCatalog(Long id, MerchantStore store, Language language) {
Validate.notNull(id, "Catalog id cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Catalog catalog = catalogService.getById(id, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with id [" + id + "] not found"));
return readableCatalogMapper.convert(catalog, store, language);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class CatalogFacadeImpl method addCatalogEntry.
@Override
public ReadableCatalogCategoryEntry addCatalogEntry(PersistableCatalogCategoryEntry entry, MerchantStore store, Language language) {
Validate.notNull(entry, "PersistableCatalogEntry cannot be null");
Validate.notNull(entry.getCatalog(), "CatalogEntry.catalog cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Catalog catalog = catalogService.getByCode(entry.getCatalog(), store).orElseThrow(() -> new ResourceNotFoundException("catalog [" + entry.getCatalog() + "] not found"));
CatalogCategoryEntry catalogEntryModel = persistableCatalogEntryMapper.convert(entry, store, language);
catalogEntryService.add(catalogEntryModel, catalog);
return readableCatalogEntryMapper.convert(catalogEntryModel, store, language);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class CatalogFacadeImpl method getCatalog.
@Override
public ReadableCatalog getCatalog(String code, MerchantStore store, Language language) {
Validate.notNull(code, "Catalog code cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(language, "Language cannot be null");
Catalog catalog = catalogService.getByCode(code, store).orElseThrow(() -> new ResourceNotFoundException("Catalog with code [" + code + "] not found"));
return readableCatalogMapper.convert(catalog, store, language);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class CategoryFacadeImpl method getById.
private Category getById(MerchantStore store, Long id) throws Exception {
Validate.notNull(id, "category id must not be null");
Validate.notNull(store, "MerchantStore must not be null");
Category category = categoryService.getById(id, store.getId());
if (category == null) {
throw new ResourceNotFoundException("Category with id [" + id + "] not found");
}
if (category.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new UnauthorizedException("Unauthorized");
}
return category;
}
Aggregations