aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2024-09-11 20:07:09 +0000
committerGerrit Code Review <gerrit@onap.org>2024-09-11 20:07:09 +0000
commit70c429d4d3fda6b7f0671221c743fd6ae91fa7c0 (patch)
tree8d5ac68a572db38d4b474382dff43e3ba48473b9 /a1-policy-management/src/main
parent6e7d8d5c4a0275158ee1a82eb48abcaae8f3639e (diff)
parentacfaa81c9975f6c67b6b7043aa598e31ba4b1f12 (diff)
Merge "Improve tests/issues found in Sonar report - A1 Oslo/NewDelhi/Montreal/London-Part 4-master"
Diffstat (limited to 'a1-policy-management/src/main')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java14
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java2
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java13
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java4
7 files changed, 18 insertions, 21 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java
index cac03208..ba8e7a1d 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/OtelConfig.java
@@ -71,7 +71,7 @@ public class OtelConfig {
@PostConstruct
public void checkTracingConfig() {
- logger.info("Application Yaml Tracing Enabled: " + !tracingDisabled);
+ logger.info("Application Yaml Tracing Enabled: {}", !tracingDisabled);
}
public boolean isTracingEnabled() {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java
index 68d9ea71..1e652219 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/WebClientUtil.java
@@ -46,7 +46,7 @@ public class WebClientUtil {
private static SpringWebfluxTelemetry springWebfluxTelemetry;
- public WebClientUtil(OtelConfig otelConfig, @Autowired(required = false) SpringWebfluxTelemetry springWebfluxTelemetry) {
+ WebClientUtil(OtelConfig otelConfig, @Autowired(required = false) SpringWebfluxTelemetry springWebfluxTelemetry) {
WebClientUtil.otelConfig = otelConfig;
if (otelConfig.isTracingEnabled()) {
WebClientUtil.springWebfluxTelemetry = springWebfluxTelemetry;
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
index 9299ffeb..ea943a08 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
@@ -72,6 +72,7 @@ public class PolicyController implements A1PolicyManagementApi {
public static final String API_NAME = "A1 Policy Management";
public static final String API_DESCRIPTION = "";
+ public static final String RIC_NOT_FOUND_MSG = "Near-RT RIC not found";
public static class RejectionException extends Exception {
private static final long serialVersionUID = 1L;
@@ -156,7 +157,7 @@ public class PolicyController implements A1PolicyManagementApi {
return policyInfo.flatMap(policyInfoValue -> {
String jsonString = gson.toJson(policyInfoValue.getPolicyData());
return Mono.zip(Mono.justOrEmpty(rics.get(policyInfoValue.getRicId()))
- .switchIfEmpty(Mono.error(new EntityNotFoundException("Near-RT RIC not found"))),
+ .switchIfEmpty(Mono.error(new EntityNotFoundException(RIC_NOT_FOUND_MSG))),
Mono.justOrEmpty(policyTypes.get(policyInfoValue.getPolicytypeId()))
.switchIfEmpty(Mono.error(new EntityNotFoundException("policy type not found"))))
.flatMap(tuple -> {
@@ -256,7 +257,7 @@ public class PolicyController implements A1PolicyManagementApi {
throw new EntityNotFoundException("Policy type identity not found");
}
if ((ricId != null && this.rics.get(ricId) == null)) {
- throw new EntityNotFoundException("Near-RT RIC not found");
+ throw new EntityNotFoundException(RIC_NOT_FOUND_MSG);
}
Collection<Policy> filtered = policies.filterPolicies(policyTypeId, ricId, serviceId, typeName);
@@ -275,7 +276,7 @@ public class PolicyController implements A1PolicyManagementApi {
throw new EntityNotFoundException("Policy type not found");
}
if ((ricId != null && this.rics.get(ricId) == null)) {
- throw new EntityNotFoundException("Near-RT RIC not found");
+ throw new EntityNotFoundException(RIC_NOT_FOUND_MSG);
}
Collection<Policy> filtered = policies.filterPolicies(policyTypeId, ricId, serviceId, typeName);
@@ -316,11 +317,8 @@ public class PolicyController implements A1PolicyManagementApi {
private PolicyInfo toPolicyInfo(Policy policy) {
try {
- PolicyInfo policyInfo = new PolicyInfo()
- .policyId(policy.getId())
- .policyData(objectMapper.readTree(policy.getJson()))
- .ricId(policy.getRic().id())
- .policytypeId(policy.getType().getId())
+ PolicyInfo policyInfo = new PolicyInfo(policy.getRic().id(), policy.getId(),
+ objectMapper.readTree(policy.getJson()), policy.getType().getId())
.serviceId(policy.getOwnerServiceId())
._transient(policy.isTransient());
if (!policy.getStatusNotificationUri().isEmpty()) {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java
index 08aa7c7b..1ff85773 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v3/PolicyControllerV3.java
@@ -82,7 +82,7 @@ public class PolicyControllerV3 implements A1PolicyManagementApi {
@Override
public Mono<ResponseEntity<Flux<PolicyTypeInformation>>> getPolicyTypes(String nearRtRicId, String typeName, String compatibleWithVersion, String accept, ServerWebExchange exchange) throws Exception {
- return policyService.getPolicyTypesService(nearRtRicId, typeName, compatibleWithVersion, exchange)
+ return policyService.getPolicyTypesService(nearRtRicId, typeName, compatibleWithVersion)
.doOnError(errorHandlingService::handleError);
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java
index af6f0abe..4d40d6d3 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/AuthorizationService.java
@@ -37,6 +37,6 @@ public class AuthorizationService {
public Mono<Policy> authCheck (ServerWebExchange serverWebExchange, Policy policy, AccessType accessType){
return authorization.doAccessControl(serverWebExchange.getRequest().getHeaders().toSingleValueMap(),
- policy, AccessType.WRITE);
+ policy, accessType);
}
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java
index 868a336f..6d59d386 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/service/v3/PolicyService.java
@@ -63,7 +63,7 @@ public class PolicyService {
public Mono<ResponseEntity<PolicyObjectInformation>> createPolicyService
(PolicyObjectInformation policyObjectInfo, ServerWebExchange serverWebExchange) {
try {
- if (!helper.jsonSchemaValidation(gson.toJson(policyObjectInfo.getPolicyObject(), Map.class)))
+ if (Boolean.FALSE.equals(helper.jsonSchemaValidation(gson.toJson(policyObjectInfo.getPolicyObject(), Map.class))))
return Mono.error(new ServiceException("Schema validation failed", HttpStatus.BAD_REQUEST));
Ric ric = rics.getRic(policyObjectInfo.getNearRtRicId());
PolicyType policyType = policyTypes.getType(policyObjectInfo.getPolicyTypeId());
@@ -117,8 +117,7 @@ public class PolicyService {
}
public Mono<ResponseEntity<Flux<PolicyTypeInformation>>> getPolicyTypesService(String nearRtRicId, String typeName,
- String compatibleWithVersion,
- ServerWebExchange webExchange) throws Exception {
+ String compatibleWithVersion) throws ServiceException {
if (compatibleWithVersion != null && typeName == null) {
throw new ServiceException("Parameter " + Consts.COMPATIBLE_WITH_VERSION_PARAM + " can only be used when "
+ Consts.TYPE_NAME_PARAM + " is given", HttpStatus.BAD_REQUEST);
@@ -126,17 +125,17 @@ public class PolicyService {
Collection<PolicyTypeInformation> listOfPolicyTypes = new ArrayList<>();
if (nearRtRicId == null || nearRtRicId.isEmpty() || nearRtRicId.isBlank()) {
for(Ric ric : rics.getRics()) {
- Collection<PolicyType> policyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName,
+ Collection<PolicyType> filteredPolicyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName,
compatibleWithVersion);
- listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(policyTypes, ric));
+ listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(filteredPolicyTypes, ric));
}
} else {
Ric ric = rics.get(nearRtRicId);
if (ric == null)
throw new EntityNotFoundException("Near-RT RIC not Found using ID: " +nearRtRicId);
- Collection<PolicyType> policyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName,
+ Collection<PolicyType> filteredPolicyTypes = PolicyTypes.filterTypes(ric.getSupportedPolicyTypes(), typeName,
compatibleWithVersion);
- listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(policyTypes, ric));
+ listOfPolicyTypes.addAll(helper.toPolicyTypeInfoCollection(filteredPolicyTypes, ric));
}
return Mono.just(new ResponseEntity<>(Flux.fromIterable(listOfPolicyTypes), HttpStatus.OK));
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java
index 406dec06..56bad574 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/util/v3/Helper.java
@@ -97,7 +97,7 @@ public class Helper {
}
public Boolean jsonSchemaValidation(Object jsonObject) {
- String jsonString = toJson(jsonObject);
+ toJson(jsonObject);
return true;
}
@@ -120,7 +120,7 @@ public class Helper {
}
public String buildURI(String policyId, ServerWebExchange serverWebExchange) {
- return UriComponentsBuilder.fromHttpRequest(serverWebExchange.getRequest())
+ return UriComponentsBuilder.fromUri(serverWebExchange.getRequest().getURI())
.path("/{id}")
.buildAndExpand(policyId)
.toString();