From f120b3d36cc6dbab97acc0020ddb9e03e35766cd Mon Sep 17 00:00:00 2001 From: "mark.j.leonard" Date: Wed, 13 Mar 2019 18:09:51 +0000 Subject: Improve error message for unknown entity-type When the Rule-driven Validator cannot find any rules for the event's entity type, include the entity type in the content of the error message that is logged and thrown as an Exception. Change-Id: If037a0d512f690350caa169d3af2f0f152ac233b Issue-ID: AAI-2259 Signed-off-by: mark.j.leonard --- .../exception/ValidationServiceError.java | 68 ++++++++++++---------- .../validation/ruledriven/RuleDrivenValidator.java | 5 +- 2 files changed, 39 insertions(+), 34 deletions(-) (limited to 'src/main/java/org/onap') diff --git a/src/main/java/org/onap/aai/validation/exception/ValidationServiceError.java b/src/main/java/org/onap/aai/validation/exception/ValidationServiceError.java index 45d79d4..421d866 100644 --- a/src/main/java/org/onap/aai/validation/exception/ValidationServiceError.java +++ b/src/main/java/org/onap/aai/validation/exception/ValidationServiceError.java @@ -1,37 +1,41 @@ -/* - * ============LICENSE_START=================================================== - * Copyright (c) 2018 Amdocs - * ============================================================================ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright (c) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2018-2019 European Software Marketing Ltd. + * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * ============LICENSE_END===================================================== + * ============LICENSE_END========================================================= */ + package org.onap.aai.validation.exception; import java.text.MessageFormat; /** - * Error text formatting + * Error text formatting. * */ public enum ValidationServiceError { - //@formatter:off + //@formatter:off // Rule Configuration exceptions. Range 100..199 RULES_FILE_ERROR("VS-100", "Error reading rules configuration file(s) {0}"), RULE_UNEXPECTED_TOKEN("VS-101", "Token {0} unexpected in rules configuration file."), - RULES_NOT_DEFINED("VS-102", "Event type {0} has no rule definitions."), - + RULES_NOT_DEFINED("VS-102", "Entity type {0} (Event type {1}) has no rule definitions."), + // Rule exceptions. Range 200..299 RULE_EXECUTION_ERROR("VS-201", "Error executing rule {0} with arguments {1}"), @@ -78,26 +82,26 @@ public enum ValidationServiceError { //@formatter:on - private String id; - private String message; - - private ValidationServiceError(String id, String message) { - this.id = id; - this.message = message; - } - - public String getId() { - return this.id; - } - - /** - * @param args - * to be formatted - * @return the formatted error message - */ - public String getMessage(Object... args) { - MessageFormat formatter = new MessageFormat(""); - formatter.applyPattern(this.message); - return formatter.format(args); - } + private String id; + private String message; + + private ValidationServiceError(String id, String message) { + this.id = id; + this.message = message; + } + + public String getId() { + return this.id; + } + + /** + * @param args + * to be formatted + * @return the formatted error message + */ + public String getMessage(Object... args) { + MessageFormat formatter = new MessageFormat(""); + formatter.applyPattern(this.message); + return formatter.format(args); + } } diff --git a/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java b/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java index 5ca7025..1c6dff7 100644 --- a/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java +++ b/src/main/java/org/onap/aai/validation/ruledriven/RuleDrivenValidator.java @@ -133,8 +133,9 @@ public class RuleDrivenValidator implements Validator { Entity entity = getEventReader().getEntity(event); Optional eventType = eventReader.getEventType(event); - List rules = getRulesToApply(entity, eventType).orElseThrow( - () -> new ValidationServiceException(ValidationServiceError.RULES_NOT_DEFINED, eventType.orElse(null))); + List rules = getRulesToApply(entity, eventType) + .orElseThrow(() -> new ValidationServiceException(ValidationServiceError.RULES_NOT_DEFINED, + entity.getType(), eventType.orElse(null))); ValidationResult validationResult = new ValidationResultBuilder(eventReader, event).build(); Violation.Builder builder = new Violation.Builder(entity); -- cgit 1.2.3-korg