From e81a9de40bc0acb4a15ecf9fd60500a6f71344e4 Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Fri, 8 Oct 2021 14:08:59 +0200 Subject: Create a json schema for validation of the configuration of the A1 PMS - A1 Jakarta Enabling the feature by default and fixing so that the schema can be loaded from the jar. Issue-ID: CCSDK-3468 Signed-off-by: PatrikBuhr Change-Id: I49a41b9124b74d5019200cc9b6eb48c5d46b043d --- .../configuration/ApplicationConfigParser.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'a1-policy-management/src/main/java') diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java index 3cab8aa0..726d67fc 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParser.java @@ -20,14 +20,15 @@ package org.onap.ccsdk.oran.a1policymanagementservice.configuration; +import com.google.common.io.CharStreams; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import java.io.File; import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -46,6 +47,7 @@ import org.json.JSONObject; import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; /** * Parser for the Json representing of the component configuration. @@ -129,13 +131,15 @@ public class ApplicationConfigParser { } } - private String readSchemaFile() throws IOException { - ClassLoader classLoader = getClass().getClassLoader(); + private String readSchemaFile() throws IOException, ServiceException { String filePath = applicationConfig.getConfigurationFileSchemaPath(); - URL url = classLoader.getResource(filePath); - File file = new File(url.getFile()); - return new String(Files.readAllBytes(file.toPath())); - + InputStream in = getClass().getResourceAsStream(filePath); + logger.debug("Reading application schema file from: {} with: {}", filePath, in); + if (in == null) { + throw new ServiceException("Could not read application configuration schema file: " + filePath, + HttpStatus.INTERNAL_SERVER_ERROR); + } + return CharStreams.toString(new InputStreamReader(in, StandardCharsets.UTF_8)); } private void checkConfigurationConsistency(List ricConfigs, -- cgit 1.2.3-korg