use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method create.
@Override
public ReadableUser create(PersistableUser user, MerchantStore store) {
Validate.notNull(store, "MerchantStore must not be null");
Validate.notNull(user, "User must not be null");
Validate.notNull(user.getUserName(), "Username must not be null");
try {
// check if user exists
User tempUser = userService.getByUserName(user.getUserName(), store.getCode());
if (tempUser != null) {
throw new ServiceRuntimeException("User [" + user.getUserName() + "] already exists for store [" + store.getCode() + "]");
}
/**
* validate password
*/
if (!securityFacade.matchRawPasswords(user.getPassword(), user.getRepeatPassword())) {
throw new ServiceRuntimeException("Passwords dos not match, make sure password and repeat password are equals");
}
/**
* Validate new password
*/
if (!securityFacade.validateUserPassword(user.getPassword())) {
throw new ServiceRuntimeException("New password does not apply to format policy");
}
String newPasswordEncoded = securityFacade.encodePassword(user.getPassword());
User userModel = new User();
userModel = converPersistabletUserToUser(store, languageService.defaultLanguage(), userModel, user);
if (CollectionUtils.isEmpty(userModel.getGroups())) {
throw new ServiceRuntimeException("No valid group groups associated with user " + user.getUserName());
}
userModel.setAdminPassword(newPasswordEncoded);
userService.saveOrUpdate(userModel);
// now build returned object
User createdUser = userService.getById(userModel.getId());
return convertUserToReadableUser(createdUser.getDefaultLanguage(), createdUser);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot create user " + user.getUserName() + " for store " + store.getCode(), e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class PaymentConfigurationFacadeImpl method configuration.
@Override
public ReadableConfiguration configuration(String module, MerchantStore store) {
try {
ReadableConfiguration config = null;
List<PaymentMethod> methods = paymentService.getAcceptedPaymentMethods(store);
Optional<ReadableConfiguration> configuration = methods.stream().filter(m -> module.equals(m.getModule().getCode())).map(m -> this.configuration(m.getInformations(), store)).findFirst();
if (configuration.isPresent()) {
config = configuration.get();
}
return config;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting payment configuration [" + module + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class PaymentConfigurationFacadeImpl method configurations.
@Override
public List<ReadableConfiguration> configurations(MerchantStore store) {
try {
List<PaymentMethod> methods = paymentService.getAcceptedPaymentMethods(store);
List<ReadableConfiguration> configurations = methods.stream().map(m -> configuration(m.getInformations(), store)).collect(Collectors.toList());
return configurations;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while getting payment configurations", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class ProductCommonFacadeImpl method deleteProduct.
@Override
public void deleteProduct(Long id, MerchantStore store) {
Validate.notNull(id, "Product id cannot be null");
Validate.notNull(store, "store cannot be null");
Product p = productService.getById(id);
if (p == null) {
throw new ResourceNotFoundException("Product with id [" + id + " not found");
}
if (p.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ResourceNotFoundException("Product with id [" + id + " not found for store [" + store.getCode() + "]");
}
try {
productService.delete(p);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Error while deleting ptoduct with id [" + id + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ServiceRuntimeException in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method delete.
@Override
public void delete(Long id, String merchant) {
Validate.notNull(id, "User id cannot be null");
try {
User user = userService.findByStore(id, merchant);
if (user == null) {
throw new ServiceRuntimeException("Cannot find user [" + id + "]");
}
// cannot delete superadmin
if (user.getGroups().contains(Constants.GROUP_SUPERADMIN)) {
throw new ServiceRuntimeException("Cannot delete superadmin user [" + id + "]");
}
userService.delete(user);
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot find user [" + id + "]", e);
}
}
Aggregations