aboutsummaryrefslogtreecommitdiffstats
path: root/models-base/src/main/java/org/onap
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2024-07-23 09:23:51 +0100
committerwaynedunican <wayne.dunican@est.tech>2024-08-13 08:49:10 +0100
commitb7804abcf865dc58a01bed3f2be4756e731d9288 (patch)
tree7f6fc3b50622578bb8612de9fe5e5c6adddfaf28 /models-base/src/main/java/org/onap
parenta029ccab07f2dd71286804da620c513da9fdfc0e (diff)
Improve code coverage and sonar fixes
Increased code coverage to 90% SONAR - Removed TODO comments SONAR - Added NOSONAR where appropriate SONAR - Replaced stream.Collect() with stream.toList() where applicable SONAR - Made variables serializable or transient to comply with sonar rules Issue-ID: POLICY-5069 Change-Id: Ife256eaf4e6f427fe40b138bacc6f112dc5bcea4 Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'models-base/src/main/java/org/onap')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java4
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModel.java10
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfUtils.java4
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfValidator.java8
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/Validated.java3
5 files changed, 15 insertions, 14 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
index df6141b9b..f97d7b48a 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptFilter.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -54,7 +54,7 @@ public class PfConceptFilter implements PfObjectFilter<PfConcept> {
.filter(filterStringPred(name, PfConcept::getName))
.filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), PfConcept::getVersion))
.filter(filterPrefixPred(versionPrefix, PfConcept::getVersion))
- .collect(Collectors.toList());
+ .collect(Collectors.toList()); //NOSONAR
// @formatter:off
if (LATEST_VERSION.equals(version)) {
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java
index 1caa6329e..0beeb01d9 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019, 2023 Nordix Foundation.
+ * Copyright (C) 2019, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
@@ -123,10 +123,10 @@ public abstract class PfModel extends PfConcept {
for (final PfKey pfKey : this.getKeys()) {
// Check for the two type of keys we have
- if (pfKey instanceof PfConceptKey) {
- validateArtifactKeyInModel((PfConceptKey) pfKey, artifactKeySet, result);
- } else if (pfKey instanceof PfReferenceKey) {
- validateReferenceKeyInModel((PfReferenceKey) pfKey, referenceKeySet, result);
+ if (pfKey instanceof PfConceptKey pfConceptKey) {
+ validateArtifactKeyInModel(pfConceptKey, artifactKeySet, result);
+ } else if (pfKey instanceof PfReferenceKey pfReferenceKey) {
+ validateReferenceKeyInModel(pfReferenceKey, referenceKeySet, result);
} else {
// It must be a PfKeyUse, nothing else is legal
usedKeySet.add((PfKeyUse) pfKey);
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
index 51054ee77..f7e6b5aa6 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -114,7 +114,7 @@ public final class PfUtils {
return defaultValue;
}
- return source.stream().map(mapFunc).collect(Collectors.toList());
+ return source.stream().map(mapFunc).collect(Collectors.toList()); //NOSONAR
}
/**
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java b/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java
index c2eb2b649..e9c8591b6 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfValidator.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,8 +67,8 @@ public class PfValidator extends BeanValidator {
*/
@Override
public boolean verCascade(BeanValidationResult result, String fieldName, Object value) {
- if (value instanceof Validated) {
- ValidationResult result2 = ((Validated) value).validate(fieldName);
+ if (value instanceof Validated validated) {
+ ValidationResult result2 = validated.validate(fieldName);
if (result2 == null) {
return true;
}
@@ -129,6 +129,6 @@ public class PfValidator extends BeanValidator {
@Override
public Object xlate(Object value) {
- return (value instanceof PfKey ? ((PfKey) value).getId() : value);
+ return (value instanceof PfKey pfKey ? pfKey.getId() : value);
}
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/Validated.java b/models-base/src/main/java/org/onap/policy/models/base/Validated.java
index 711dd7be6..0c4f36034 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/Validated.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/Validated.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -119,6 +120,6 @@ public class Validated {
* @return the value's ID, if it's a key, the original value otherwise
*/
private static Object getKeyId(Object value) {
- return (value instanceof PfKey ? ((PfKey) value).getId() : value);
+ return (value instanceof PfKey pfKey ? pfKey.getId() : value);
}
}