aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSuresh Charan <suresh.charan@bell.ca>2023-02-09 12:17:13 -0500
committerSuresh Charan <suresh.charan@bell.ca>2023-02-09 12:22:19 -0500
commitea458fd83b811d7c55030fbcc168e2769524dfc8 (patch)
treeb9bbc713b127817281d680f301514c7dba47b9b8 /main
parentacdd6b6d915736ac8575769ea63bfc745e184b2b (diff)
Fixed sonar issue in policy-api
Fixed cognitive complexity reported by sonar. Issue-ID: POLICY-4536 Change-Id: Ic3b5b7d79165afed15a1593e03b8374fb2122e12 Signed-off-by: Suresh Charan <suresh.charan@bell.ca>
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java23
1 files changed, 14 insertions, 9 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
index d9f4f777..55f49b18 100644
--- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
+++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
@@ -120,15 +120,7 @@ public class ApiDatabaseInitializer {
var multiVersionTemplates = new ArrayList<ToscaServiceTemplate>();
for (String entity : entities) {
- var entityAsStringYaml = ResourceUtils.getResourceAsString(entity);
- if (entityAsStringYaml == null) {
- throw new PolicyApiException("Preloaded entity cannot be found " + entity);
- }
-
- ToscaServiceTemplate singleEntity = coder.decode(entityAsStringYaml, ToscaServiceTemplate.class);
- if (singleEntity == null) {
- throw new PolicyApiException("Error deserializing entity from file: " + entity);
- }
+ ToscaServiceTemplate singleEntity = deserializeServiceTemplate(entity);
if (isMultiVersion(serviceTemplate.getPolicyTypes(), singleEntity.getPolicyTypes())) {
// if this entity introduces a new policy version of an existing policy type,
@@ -173,6 +165,19 @@ public class ApiDatabaseInitializer {
return createdServiceTemplate;
}
+ private ToscaServiceTemplate deserializeServiceTemplate(String entity) throws PolicyApiException, CoderException {
+ var entityAsStringYaml = ResourceUtils.getResourceAsString(entity);
+ if (entityAsStringYaml == null) {
+ throw new PolicyApiException("Preloaded entity cannot be found " + entity);
+ }
+
+ ToscaServiceTemplate singleEntity = coder.decode(entityAsStringYaml, ToscaServiceTemplate.class);
+ if (singleEntity == null) {
+ throw new PolicyApiException("Error deserializing entity from file: " + entity);
+ }
+ return singleEntity;
+ }
+
// This method is templated, so it can be used with other derivations of ToscaEntity in the future,
// if multi-version are desired.