From 6438ef61e253f5071a5539c0c8de8890260d4f58 Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Wed, 2 Aug 2023 14:49:33 +0100 Subject: Java 17 / Spring 6 / Spring Boot 3 Upgrade Issue-ID: POLICY-4670 Change-Id: Id28a45fa0bcb17903065904bd9544012d5fefbb7 Signed-off-by: adheli.tavares --- .gitreview | 2 +- main/pom.xml | 45 +++---- .../policy/api/main/config/PolicyApiAafConfig.java | 7 +- .../api/main/config/PolicyPreloadConfig.java | 8 +- .../policy/api/main/config/SecurityConfig.java | 13 +- .../org/onap/policy/api/main/config/WebConfig.java | 6 +- .../api/main/exception/PolicyApiException.java | 8 +- .../main/exception/PolicyApiRuntimeException.java | 10 +- .../main/exception/ServiceExceptionHandler.java | 5 +- .../policy/api/main/rest/ApiRestController.java | 144 +++++++++------------ .../policy/api/main/rest/CommonRestController.java | 11 +- .../api/main/rest/stub/ApiRestControllerStub.java | 12 +- .../main/rest/stub/NodeTemplateControllerStub.java | 2 +- .../onap/policy/api/main/rest/stub/StubUtils.java | 5 +- .../api/main/service/NodeTemplateService.java | 4 +- .../policy/api/main/service/PdpGroupService.java | 5 +- .../main/service/ToscaServiceTemplateService.java | 25 ++-- .../api/main/startstop/ApiDatabaseInitializer.java | 4 +- main/src/main/resources/META-INF/persistence.xml | 5 +- main/src/main/resources/openapi/openapi.yaml | 2 +- .../onap/policy/api/contract/ApiContractTest.java | 32 ++--- .../api/main/exception/TestPolicyApiException.java | 12 +- .../exception/TestPolicyApiRuntimeException.java | 12 +- .../policy/api/main/rest/TestApiRestServer.java | 73 +++++------ .../api/main/rest/TestCommonRestController.java | 20 ++- .../api/main/rest/TestNodeTemplateController.java | 25 ++-- .../policy/api/main/rest/aaf/TestAafApiFilter.java | 14 +- .../main/rest/utils/CommonTestRestController.java | 33 +++-- .../TestCommonToscaServiceTemplateService.java | 44 ++++--- .../api/main/service/TestNodeTemplateService.java | 48 ++++--- .../api/main/service/TestPdpGroupService.java | 26 +++- .../policy/api/main/service/TestPolicyService.java | 27 +++- .../api/main/service/TestPolicyTypeService.java | 24 +++- .../TestToscaServiceTemplateForNodeTemplate.java | 51 ++++---- ...stToscaServiceTemplateServiceForPolicyCrud.java | 92 ++++++------- ...scaServiceTemplateServiceForPolicyTypeCrud.java | 66 +++++----- .../main/startstop/ApiDatabaseInitializerTest.java | 10 +- main/src/test/resources/META-INF/persistence.xml | 4 +- pom.xml | 28 ++-- 39 files changed, 476 insertions(+), 488 deletions(-) diff --git a/.gitreview b/.gitreview index dc96ff88..7d0a47af 100644 --- a/.gitreview +++ b/.gitreview @@ -2,4 +2,4 @@ host=gerrit.onap.org port=29418 project=policy/api.git -defaultbranch=master +defaultbranch=java-17 diff --git a/main/pom.xml b/main/pom.xml index 893cec03..f0f50b9a 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -35,6 +35,7 @@ api-main ${project.artifactId} The main module of Policy Api that handles startup, lifecycle management, and parameters. + org.onap.policy.models @@ -46,45 +47,25 @@ spring-utils ${policy.common.version} - - com.h2database - h2 - - - org.assertj - assertj-core - test - org.onap.policy.common utils-test ${policy.common.version} test - - org.junit.vintage - junit-vintage-engine - test - + org.springframework.boot spring-boot-starter-test test - com.google.code.gson - gson + org.springframework.boot + spring-boot-starter-web org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-json - - + spring-boot-starter-tomcat org.springframework.boot @@ -100,14 +81,23 @@ org.springdoc - springdoc-openapi-ui + springdoc-openapi-starter-webmvc-ui + 2.1.0 io.micrometer micrometer-registry-prometheus - ${version.io.micrometer} runtime + + org.apache.tomcat.embed + tomcat-embed-core + 10.1.11 + + + com.h2database + h2 + @@ -131,6 +121,7 @@ io.swagger.codegen.v3 swagger-codegen-maven-plugin + 3.0.46 code-gen @@ -156,6 +147,7 @@ java11 true true + true @@ -164,6 +156,7 @@ org.springframework.boot spring-boot-maven-plugin + ${version.springboot} diff --git a/main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java b/main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java index bd55344a..2d0a2285 100644 --- a/main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java +++ b/main/src/main/java/org/onap/policy/api/main/config/PolicyApiAafConfig.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.api.main.config; -import javax.servlet.Filter; +import jakarta.servlet.Filter; import org.onap.policy.api.main.rest.aaf.AafApiFilter; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; @@ -34,4 +35,4 @@ public class PolicyApiAafConfig { public Filter aafFilter() { return new AafApiFilter(); } -} \ No newline at end of file +} diff --git a/main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java b/main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java index c2c40ff2..802d37c8 100644 --- a/main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java +++ b/main/src/main/java/org/onap/policy/api/main/config/PolicyPreloadConfig.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,15 +27,14 @@ import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; +@Getter @Component @ConfigurationProperties("policy-preload") public class PolicyPreloadConfig { - @Getter @Setter List policyTypes; - @Getter @Setter List policies; -} \ No newline at end of file +} diff --git a/main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java b/main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java index 231456d3..074675b6 100644 --- a/main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java +++ b/main/src/main/java/org/onap/policy/api/main/config/SecurityConfig.java @@ -23,7 +23,9 @@ package org.onap.policy.api.main.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.web.SecurityFilterChain; /** @@ -31,6 +33,7 @@ import org.springframework.security.web.SecurityFilterChain; */ @Configuration public class SecurityConfig { + /** * Return the configuration of how access to this module's REST end points is secured. * @@ -40,11 +43,9 @@ public class SecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http - .httpBasic() - .and() - .authorizeHttpRequests().anyRequest().authenticated() - .and() - .csrf().disable(); + .httpBasic(Customizer.withDefaults()) + .authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated()) + .csrf(AbstractHttpConfigurer::disable); return http.build(); } -} \ No newline at end of file +} diff --git a/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java b/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java index ffc0edfd..42e07d64 100644 --- a/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java +++ b/main/src/main/java/org/onap/policy/api/main/config/WebConfig.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,6 @@ package org.onap.policy.api.main.config; -import java.util.Arrays; import java.util.List; import org.onap.policy.api.main.config.converter.StringToEnumConverter; import org.onap.policy.common.spring.utils.YamlHttpMessageConverter; @@ -43,7 +43,7 @@ public class WebConfig implements WebMvcConfigurer { @Override public void extendMessageConverters(List> converters) { var yamlConverter = new YamlHttpMessageConverter(); - yamlConverter.setSupportedMediaTypes(Arrays.asList(MediaType.parseMediaType("application/yaml"))); + yamlConverter.setSupportedMediaTypes(List.of(MediaType.parseMediaType("application/yaml"))); converters.add(yamlConverter); } } diff --git a/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java b/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java index 580ba33d..b5364395 100644 --- a/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java +++ b/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiException.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +21,13 @@ package org.onap.policy.api.main.exception; +import java.io.Serial; + /** * This exception will be called if an error occurs in policy api external service. */ public class PolicyApiException extends Exception { + @Serial private static final long serialVersionUID = -8507246953751956974L; /** @@ -48,7 +52,7 @@ public class PolicyApiException extends Exception { * Instantiates a new policy api exception with a message and a caused by exception. * * @param message the message - * @param exp the exception that caused this exception to be thrown + * @param exp the exception that caused this exception to be thrown */ public PolicyApiException(final String message, final Exception exp) { super(message, exp); diff --git a/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java b/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java index 19bf5e12..d4140d47 100644 --- a/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java +++ b/main/src/main/java/org/onap/policy/api/main/exception/PolicyApiRuntimeException.java @@ -1,7 +1,8 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. - * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.policy.api.main.exception; +import java.io.Serial; import java.util.UUID; import lombok.Getter; import org.onap.policy.models.errors.concepts.ErrorResponse; @@ -28,13 +30,13 @@ import org.onap.policy.models.errors.concepts.ErrorResponse; /** * This runtime exception will be called if a runtime error occurs when using policy api. */ +@Getter public class PolicyApiRuntimeException extends RuntimeException { + @Serial private static final long serialVersionUID = -8507246953751956974L; - @Getter private final UUID requestId; - @Getter private final ErrorResponse errorResponse; /** diff --git a/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java b/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java index 93240df9..4b601439 100644 --- a/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java +++ b/main/src/main/java/org/onap/policy/api/main/exception/ServiceExceptionHandler.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022-2023 Bell Canada. All rights reserved. + * Copyright (C) 2022-2023 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.api.main.exception; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.core.Response; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; diff --git a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java index a1e6db25..b44e60fa 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/ApiRestController.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2020-2022 Nordix Foundation. + * Modifications Copyright (C) 2020-2023 Nordix Foundation. * Modifications Copyright (C) 2020-2023 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,9 +25,9 @@ package org.onap.policy.api.main.rest; +import jakarta.ws.rs.core.Response.Status; import java.util.List; import java.util.UUID; -import javax.ws.rs.core.Response.Status; import lombok.RequiredArgsConstructor; import org.onap.policy.api.main.exception.PolicyApiRuntimeException; import org.onap.policy.api.main.rest.genapi.PolicyDesignApi; @@ -41,8 +41,6 @@ import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.context.annotation.Profile; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; @@ -56,12 +54,6 @@ import org.springframework.web.bind.annotation.RestController; @Profile("default") public class ApiRestController extends CommonRestController implements PolicyDesignApi { - private enum Target { - POLICY, - POLICY_TYPE, - OTHER - } - private final ToscaServiceTemplateService toscaServiceTemplateService; private final HealthCheckProvider healthCheckProvider; @@ -96,13 +88,12 @@ public class ApiRestController extends CommonRestController implements PolicyDes * Retrieves all versions of a particular policy type. * * @param policyTypeId the ID of specified policy type - * * @return the Response object containing the results of the API operation */ @Override public ResponseEntity getAllVersionsOfPolicyType( - String policyTypeId, - UUID requestId) { + String policyTypeId, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, null); return makeOkResponse(requestId, serviceTemplate); @@ -116,15 +107,14 @@ public class ApiRestController extends CommonRestController implements PolicyDes * Retrieves specified version of a particular policy type. * * @param policyTypeId the ID of specified policy type - * @param versionId the version of specified policy type - * + * @param versionId the version of specified policy type * @return the Response object containing the results of the API operation */ @Override public ResponseEntity getSpecificVersionOfPolicyType( - String policyTypeId, - String versionId, - UUID requestId) { + String policyTypeId, + String versionId, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicyTypes(policyTypeId, versionId); @@ -139,13 +129,12 @@ public class ApiRestController extends CommonRestController implements PolicyDes * Retrieves latest version of a particular policy type. * * @param policyTypeId the ID of specified policy type - * * @return the Response object containing the results of the API operation */ @Override public ResponseEntity getLatestVersionOfPolicyType( - String policyTypeId, - UUID requestId) { + String policyTypeId, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicyTypes(policyTypeId); return makeOkResponse(requestId, serviceTemplate); @@ -159,13 +148,12 @@ public class ApiRestController extends CommonRestController implements PolicyDes * Creates a new policy type. * * @param body the body of policy type following TOSCA definition - * * @return the Response object containing the results of the API operation */ @Override public ResponseEntity createPolicyType( - ToscaServiceTemplate body, - UUID requestId) { + ToscaServiceTemplate body, + UUID requestId) { if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes", toJson(body)); } @@ -182,15 +170,14 @@ public class ApiRestController extends CommonRestController implements PolicyDes * Deletes specified version of a particular policy type. * * @param policyTypeId the ID of specified policy type - * @param versionId the version of specified policy type - * + * @param versionId the version of specified policy type * @return the Response object containing the results of the API operation */ @Override public ResponseEntity deleteSpecificVersionOfPolicyType( - String policyTypeId, - String versionId, - UUID requestId) { + String policyTypeId, + String versionId, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.deletePolicyType(policyTypeId, versionId); @@ -204,17 +191,16 @@ public class ApiRestController extends CommonRestController implements PolicyDes /** * Retrieves all versions of a particular policy. * - * @param policyTypeId the ID of specified policy type + * @param policyTypeId the ID of specified policy type * @param policyTypeVersion the version of specified policy type - * * @return the Response object containing the results of the API operation */ @Override public ResponseEntity getAllPolicies( - String policyTypeId, - String policyTypeVersion, - PolicyFetchMode mode, - UUID requestId) { + String policyTypeId, + String policyTypeVersion, + PolicyFetchMode mode, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, null, null, mode); @@ -228,19 +214,18 @@ public class ApiRestController extends CommonRestController implements PolicyDes /** * Retrieves all versions of a particular policy. * - * @param policyTypeId the ID of specified policy type + * @param policyTypeId the ID of specified policy type * @param policyTypeVersion the version of specified policy type - * @param policyId the ID of specified policy - * + * @param policyId the ID of specified policy * @return the Response object containing the results of the API operation */ @Override public ResponseEntity getAllVersionsOfPolicy( - String policyId, - String policyTypeId, - String policyTypeVersion, - PolicyFetchMode mode, - UUID requestId) { + String policyId, + String policyTypeId, + String policyTypeVersion, + PolicyFetchMode mode, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicies(policyTypeId, policyTypeVersion, policyId, null, mode); @@ -255,21 +240,20 @@ public class ApiRestController extends CommonRestController implements PolicyDes /** * Retrieves the specified version of a particular policy. * - * @param policyTypeId the ID of specified policy type + * @param policyTypeId the ID of specified policy type * @param policyTypeVersion the version of specified policy type - * @param policyId the ID of specified policy - * @param policyVersion the version of specified policy - * + * @param policyId the ID of specified policy + * @param policyVersion the version of specified policy * @return the Response object containing the results of the API operation */ @Override public ResponseEntity getSpecificVersionOfPolicy( - String policyId, - String policyTypeId, - String policyTypeVersion, - String policyVersion, - PolicyFetchMode mode, - UUID requestId) { + String policyId, + String policyTypeId, + String policyTypeVersion, + String policyVersion, + PolicyFetchMode mode, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService .fetchPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion, mode); @@ -284,19 +268,18 @@ public class ApiRestController extends CommonRestController implements PolicyDes /** * Retrieves the latest version of a particular policy. * - * @param policyTypeId the ID of specified policy type + * @param policyTypeId the ID of specified policy type * @param policyTypeVersion the version of specified policy type - * @param policyId the ID of specified policy - * + * @param policyId the ID of specified policy * @return the Response object containing the results of the API operation */ @Override public ResponseEntity getLatestVersionOfPolicy( - String policyId, - String policyTypeId, - String policyTypeVersion, - PolicyFetchMode mode, - UUID requestId) { + String policyId, + String policyTypeId, + String policyTypeVersion, + PolicyFetchMode mode, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchLatestPolicies(policyTypeId, policyTypeVersion, policyId, mode); @@ -311,18 +294,17 @@ public class ApiRestController extends CommonRestController implements PolicyDes /** * Creates a new policy for a particular policy type and version. * - * @param policyTypeId the ID of specified policy type + * @param policyTypeId the ID of specified policy type * @param policyTypeVersion the version of specified policy type - * @param body the body of policy following TOSCA definition - * + * @param body the body of policy following TOSCA definition * @return the Response object containing the results of the API operation */ @Override public ResponseEntity createPolicy( - String policyTypeId, - String policyTypeVersion, - ToscaServiceTemplate body, - UUID requestId) { + String policyTypeId, + String policyTypeVersion, + ToscaServiceTemplate body, + UUID requestId) { if (NetLoggerUtil.getNetworkLogger().isInfoEnabled()) { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, "/policytypes/" + policyTypeId + "/versions/" + policyTypeVersion + "/policies", toJson(body)); @@ -340,11 +322,10 @@ public class ApiRestController extends CommonRestController implements PolicyDes /** * Deletes the specified version of a particular policy. * - * @param policyTypeId the ID of specified policy type + * @param policyTypeId the ID of specified policy type * @param policyTypeVersion the version of specified policy type - * @param policyId the ID of specified policy - * @param policyVersion the version of specified policy - * + * @param policyId the ID of specified policy + * @param policyVersion the version of specified policy * @return the Response object containing the results of the API operation */ @Override @@ -372,8 +353,8 @@ public class ApiRestController extends CommonRestController implements PolicyDes */ @Override public ResponseEntity getPolicies( - PolicyFetchMode mode, - UUID requestId) { + PolicyFetchMode mode, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicies(null, null, null, null, mode); @@ -391,17 +372,16 @@ public class ApiRestController extends CommonRestController implements PolicyDes /** * Retrieves the specified version of a particular policy. * - * @param policyId the Name of specified policy + * @param policyId the Name of specified policy * @param policyVersion the version of specified policy - * * @return the Response object containing the results of the API operation */ @Override public ResponseEntity getSpecificPolicy( - String policyId, - String policyVersion, - PolicyFetchMode mode, - UUID requestId) { + String policyId, + String policyVersion, + PolicyFetchMode mode, + UUID requestId) { try { ToscaServiceTemplate serviceTemplate = toscaServiceTemplateService.fetchPolicies(null, null, policyId, policyVersion, mode); @@ -416,7 +396,6 @@ public class ApiRestController extends CommonRestController implements PolicyDes * Creates one or more new policies in one call. * * @param body the body of policy following TOSCA definition - * * @return the Response object containing the results of the API operation */ @Override @@ -438,9 +417,8 @@ public class ApiRestController extends CommonRestController implements PolicyDes /** * Deletes the specified version of a particular policy. * - * @param policyId the ID of specified policy + * @param policyId the ID of specified policy * @param policyVersion the version of specified policy - * * @return the Response object containing the results of the API operation */ @Override diff --git a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java index ef288e47..eadd8d34 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/CommonRestController.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ package org.onap.policy.api.main.rest; +import java.util.Objects; import java.util.UUID; import org.onap.policy.api.main.exception.PolicyApiRuntimeException; import org.onap.policy.common.utils.coder.Coder; @@ -107,12 +108,10 @@ public class CommonRestController { * @return the response builder, with version logging */ public static ResponseEntity.BodyBuilder addLoggingHeaders(ResponseEntity.BodyBuilder respBuilder, UUID requestId) { - if (requestId == null) { - // Generate a random uuid if client does not embed requestId in rest request - return respBuilder.header(REQUEST_ID_NAME, UUID.randomUUID().toString()); - } + // Generate a random uuid if client does not embed requestId in rest request + return respBuilder.header(REQUEST_ID_NAME, + Objects.requireNonNullElseGet(requestId, UUID::randomUUID).toString()); - return respBuilder.header(REQUEST_ID_NAME, requestId.toString()); } /** diff --git a/main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java b/main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java index 38fe0032..49c9bf45 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/stub/ApiRestControllerStub.java @@ -21,8 +21,8 @@ package org.onap.policy.api.main.rest.stub; +import jakarta.validation.Valid; import java.util.UUID; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import org.onap.policy.api.main.rest.CommonRestController; import org.onap.policy.api.main.rest.PolicyFetchMode; @@ -42,7 +42,7 @@ public class ApiRestControllerStub extends CommonRestController implements Polic @Override public ResponseEntity createPolicies( - @Valid ToscaServiceTemplate body, UUID requestID) { + @Valid ToscaServiceTemplate body, UUID requestID) { return stubUtils.getStubbedResponse(ToscaServiceTemplate.class); } @@ -57,15 +57,15 @@ public class ApiRestControllerStub extends CommonRestController implements Polic @Override public ResponseEntity createPolicyType( - @Valid ToscaServiceTemplate body, UUID requestID) { + @Valid ToscaServiceTemplate body, UUID requestID) { return stubUtils.getStubbedResponse(ToscaServiceTemplate.class); } @Override public ResponseEntity deleteSpecificPolicy( - String policyId, - String policyVersion, - UUID requestID) { + String policyId, + String policyVersion, + UUID requestID) { return stubUtils.getStubbedResponse(ToscaServiceTemplate.class); } diff --git a/main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java b/main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java index 2e9f4a21..5045eb69 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/stub/NodeTemplateControllerStub.java @@ -20,9 +20,9 @@ package org.onap.policy.api.main.rest.stub; +import jakarta.validation.Valid; import java.util.List; import java.util.UUID; -import javax.validation.Valid; import lombok.RequiredArgsConstructor; import org.onap.policy.api.main.rest.CommonRestController; import org.onap.policy.api.main.rest.genapi.ToscaNodeTemplateDesignApi; diff --git a/main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java b/main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java index 562ce565..62f091cb 100644 --- a/main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java +++ b/main/src/main/java/org/onap/policy/api/main/rest/stub/StubUtils.java @@ -21,11 +21,10 @@ package org.onap.policy.api.main.rest.stub; import com.google.gson.Gson; +import jakarta.servlet.http.HttpServletRequest; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.List; -import javax.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,7 +67,7 @@ class StubUtils { final var resource = new ClassPathResource(TOSCA_NODE_TEMPLATE_RESOURCE); try (var inputStream = resource.getInputStream()) { final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); - var targetObject = Arrays.asList(JSON_TRANSLATOR.fromJson(string, clazz)); + var targetObject = List.of(JSON_TRANSLATOR.fromJson(string, clazz)); return new ResponseEntity<>(targetObject, HttpStatus.OK); } catch (IOException e) { log.error("Couldn't serialize response for content type application/json", e); diff --git a/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java b/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java index b4eec379..620248d4 100644 --- a/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java +++ b/main/src/main/java/org/onap/policy/api/main/service/NodeTemplateService.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. All rights reserved. + * Copyright (C) 2022-2023 Nordix Foundation. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,8 @@ package org.onap.policy.api.main.service; +import jakarta.ws.rs.core.Response; import java.util.Optional; -import javax.ws.rs.core.Response; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.onap.policy.api.main.repository.NodeTemplateRepository; diff --git a/main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java b/main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java index 0bac8722..e9d84be5 100644 --- a/main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java +++ b/main/src/main/java/org/onap/policy/api/main/service/PdpGroupService.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +21,9 @@ package org.onap.policy.api.main.service; +import jakarta.ws.rs.core.Response; import java.util.List; import java.util.stream.Collectors; -import javax.ws.rs.core.Response; import lombok.RequiredArgsConstructor; import org.onap.policy.api.main.repository.PdpGroupRepository; import org.onap.policy.models.base.PfModelRuntimeException; diff --git a/main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java b/main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java index 2e8fc9eb..9ec28d1b 100644 --- a/main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java +++ b/main/src/main/java/org/onap/policy/api/main/service/ToscaServiceTemplateService.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2022 Nordix Foundation. + * Modifications Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,11 +21,10 @@ package org.onap.policy.api.main.service; +import jakarta.ws.rs.core.Response; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import javax.annotation.Nonnull; -import javax.ws.rs.core.Response; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.CollectionUtils; @@ -119,12 +118,9 @@ public class ToscaServiceTemplateService { // append the incoming fragment to the DB TOSCA service template var dbServiceTemplateOpt = getDefaultJpaToscaServiceTemplateOpt(); JpaToscaServiceTemplate serviceTemplateToWrite; - if (dbServiceTemplateOpt.isEmpty()) { - serviceTemplateToWrite = incomingServiceTemplate; - } else { - serviceTemplateToWrite = - ToscaServiceTemplateUtils.addFragment(dbServiceTemplateOpt.get(), incomingServiceTemplate); - } + serviceTemplateToWrite = dbServiceTemplateOpt.map( + jpaToscaServiceTemplate -> ToscaServiceTemplateUtils.addFragment(jpaToscaServiceTemplate, + incomingServiceTemplate)).orElse(incomingServiceTemplate); final var result = serviceTemplateToWrite.validate("service template"); if (!result.isValid()) { @@ -265,12 +261,9 @@ public class ToscaServiceTemplateService { // append the incoming fragment to the DB TOSCA service template var dbServiceTemplateOpt = getDefaultJpaToscaServiceTemplateOpt(); JpaToscaServiceTemplate serviceTemplateToWrite; - if (dbServiceTemplateOpt.isEmpty()) { - serviceTemplateToWrite = incomingServiceTemplate; - } else { - serviceTemplateToWrite = - ToscaServiceTemplateUtils.addFragment(dbServiceTemplateOpt.get(), incomingServiceTemplate); - } + serviceTemplateToWrite = dbServiceTemplateOpt.map( + jpaToscaServiceTemplate -> ToscaServiceTemplateUtils.addFragment(jpaToscaServiceTemplate, + incomingServiceTemplate)).orElse(incomingServiceTemplate); final var result = serviceTemplateToWrite.validate("Policies CRUD service template."); if (!result.isValid()) { @@ -501,7 +494,7 @@ public class ToscaServiceTemplateService { * @return the TOSCA service template containing the node template that were deleted * @throws PfModelException on errors deleting node templates */ - public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @Nonnull final String version) + public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull final String name, @NonNull final String version) throws PfModelException { LOGGER.debug("->deleteToscaNodeTemplate: name={}, version={}", name, version); 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 55f49b18..edff3004 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 @@ -3,7 +3,7 @@ * ONAP Policy API * ================================================================================ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation. * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,13 +25,13 @@ package org.onap.policy.api.main.startstop; import com.google.common.collect.Sets; +import jakarta.annotation.PostConstruct; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; -import javax.annotation.PostConstruct; import lombok.RequiredArgsConstructor; import org.onap.policy.api.main.config.PolicyPreloadConfig; import org.onap.policy.api.main.exception.PolicyApiException; diff --git a/main/src/main/resources/META-INF/persistence.xml b/main/src/main/resources/META-INF/persistence.xml index 43024eea..8adb850c 100644 --- a/main/src/main/resources/META-INF/persistence.xml +++ b/main/src/main/resources/META-INF/persistence.xml @@ -1,9 +1,8 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 org.onap.policy.parent integration 4.0.0-SNAPSHOT - + org.onap.policy.api @@ -57,36 +57,32 @@ org.slf4j slf4j-api - - junit - junit - test - org.onap.policy.common policy-endpoints ${policy.common.version} - javax.servlet - javax.servlet-api + org.assertj + assertj-core + test + - org.eclipse.jetty - jetty-server + org.glassfish.jersey.containers + jersey-container-servlet org.eclipse.jetty - jetty-security + jetty-server org.eclipse.jetty jetty-servlet - org.glassfish.jersey.containers - jersey-container-servlet - ${version.jersey} + org.eclipse.jetty + jetty-security -- cgit 1.2.3-korg