throw new UserNotFoundException("Customer on the policy is not registered.");
}
calculateScoreForUser(user);
if (user.getScore() <= 0) {
throw new PurchaseException("Customer is not eligible for policy.");
}
int newQuote = calculateQuoteForPolicy(policy);
if (newQuote != policy.getQuote()) {
throw new InvalidInputValueException("Quota on the policy is not correct.");
}
if (policy.getPropertyName() == null || policy.getPropertyName().equals("")) {
throw new MissingInputValueException("Policy must include property name.");
}
if (policy.getPropertyValue() <= 0) {
throw new InvalidInputValueException(
"Policy must include valid property value.");
}
if (policy.getDeductibles() < 0) {
throw new InvalidInputValueException("Deductibles can't be negative.");
}
if (policy.getStartDate() != null) {
throw new PurchaseException("New policy can't include start date.");
}
if (policy.getEndDate() != null) {
throw new PurchaseException("New policy can't include end date.");
}
// compensate agent
try {
sendPurchaseMessage(policy);