use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxClass.
@Override
public ReadableTaxClass taxClass(String code, MerchantStore store, Language language) {
Validate.notNull(code, "TaxClass code cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
TaxClass model = taxClassService.getByCode(code, store);
if (model == null) {
throw new ResourceNotFoundException("TaxClass not found [" + code + "] for store [" + store.getCode() + "]");
}
if (model != null) {
if (!model.getMerchantStore().getCode().equals(store.getCode())) {
throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot get tax class [" + code + "]");
}
}
return readableTaxClassMapper.convert(model, store, language);
} catch (ServiceException e) {
LOGGER.error("Error while getting taxClass [" + code + "] for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxClass [" + code + "] for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method taxRateByCode.
// get by code
private TaxRate taxRateByCode(String code, MerchantStore store, Language language) {
Validate.notNull(code, "TaxRate code cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
TaxRate model = taxRateService.getByCode(code, store);
if (model == null) {
throw new ResourceNotFoundException("TaxRate not found [" + code + "] for store [" + store.getCode() + "]");
}
if (model != null) {
if (!model.getMerchantStore().getCode().equals(store.getCode())) {
throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot get tax rate [" + code + "]");
}
}
return model;
} catch (ServiceException e) {
LOGGER.error("Error while getting taxRate [" + code + "] for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while getting taxRate [" + code + "] for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class TaxFacadeImpl method updateTaxClass.
@Override
public void updateTaxClass(Long id, PersistableTaxClass taxClass, MerchantStore store, Language language) {
Validate.notNull(taxClass, "TaxClass cannot be null");
Validate.notNull(store, "MerchantStore cannot be null");
Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
try {
TaxClass model = taxClassService.getById(id);
if (model == null) {
throw new ResourceNotFoundException("TaxClass not found [" + id + "] for store [" + store.getCode() + "]");
} else {
if (!model.getMerchantStore().getCode().equals(store.getCode())) {
throw new UnauthorizedException("MerchantStore [" + store.getCode() + "] cannot update tax class [" + taxClass.getCode() + "]");
}
}
model = persistableTaxClassMapper.convert(taxClass, store, language);
taxClassService.saveOrUpdate(model);
} catch (ServiceException e) {
LOGGER.error("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
throw new ServiceRuntimeException("Error while saving taxClass [" + taxClass.getCode() + "] for store [" + store.getCode() + "]", e);
}
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method findById.
@Override
public ReadableUser findById(Long id, MerchantStore store, Language lang) {
Validate.notNull(store, "MerchantStore cannot be null");
User user = userService.getById(id, store);
if (user == null) {
throw new ResourceNotFoundException("User [" + id + "] not found");
}
return convertUserToReadableUser(lang, user);
}
use of com.salesmanager.shop.store.api.exception.ResourceNotFoundException in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method verifyUserLink.
private User verifyUserLink(String token, String store) {
User user = null;
try {
user = userService.getByPasswordResetToken(store, token);
if (user == null) {
throw new ResourceNotFoundException("Customer not fount for store [" + store + "] and token [" + token + "]");
}
} catch (Exception e) {
throw new ServiceRuntimeException("Cannot verify customer token", e);
}
Date tokenExpiry = user.getCredentialsResetRequest().getCredentialsRequestExpiry();
if (tokenExpiry == null) {
throw new GenericRuntimeException("No expiry date configured for token [" + token + "]");
}
if (!DateUtil.dateBeforeEqualsDate(new Date(), tokenExpiry)) {
throw new GenericRuntimeException("Ttoken [" + token + "] has expired");
}
return user;
}
Aggregations