From: adheli.tavares Date: Wed, 2 Aug 2023 13:49:33 +0000 (+0100) Subject: Java 17 / Spring 6 / Spring Boot 3 Upgrade X-Git-Tag: 3.0.1~5 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;ds=sidebyside;h=9b0780e59376d20ae9044575ce9921fb7e6b519f;p=policy%2Fapi.git Java 17 / Spring 6 / Spring Boot 3 Upgrade Issue-ID: POLICY-4670 Change-Id: Ie25d0501e5b936621e41f0d3c637320784d56627 Signed-off-by: adheli.tavares --- diff --git a/main/pom.xml b/main/pom.xml index 893cec03..5f88ee54 100644 --- a/main/pom.xml +++ b/main/pom.xml @@ -30,11 +30,12 @@ org.onap.policy.api policy-api - 3.0.0-SNAPSHOT + 3.0.1-SNAPSHOT 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,30 @@ org.springdoc - springdoc-openapi-ui + springdoc-openapi-starter-webmvc-ui io.micrometer micrometer-registry-prometheus - ${version.io.micrometer} runtime + + org.apache.tomcat.embed + tomcat-embed-core + + + com.h2database + h2 + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.mockito + mockito-junit-jupiter + @@ -153,9 +150,10 @@ src/gen/java - java11 + java17 true true + true @@ -164,6 +162,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/xsd/maven-4.0.0.xsd"> 4.0.0 org.onap.policy.api api-packages - 3.0.0-SNAPSHOT + 3.0.1-SNAPSHOT policy-api-tarball diff --git a/packages/pom.xml b/packages/pom.xml index a1aabfac..520be642 100644 --- a/packages/pom.xml +++ b/packages/pom.xml @@ -20,12 +20,13 @@ ============LICENSE_END========================================================= --> - + 4.0.0 org.onap.policy.api policy-api - 3.0.0-SNAPSHOT + 3.0.1-SNAPSHOT api-packages @@ -33,7 +34,7 @@ ${project.artifactId} - + true diff --git a/pom.xml b/pom.xml index deb8fa33..fe58f2bc 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ ================================================================================ Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved. Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. - Modifications Copyright (C) 2019-2020 Nordix Foundation. + Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation. Modifications Copyright (C) 2020 Bell Canada. All rights reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,19 +22,19 @@ --> + 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 - + 4.0.1-SNAPSHOT + org.onap.policy.api policy-api - 3.0.0-SNAPSHOT + 3.0.1-SNAPSHOT pom @@ -42,8 +42,8 @@ Code that define our external API. - 2.0.0-SNAPSHOT - 3.0.0-SNAPSHOT + 2.0.1-SNAPSHOT + 3.0.1-SNAPSHOT @@ -57,36 +57,31 @@ 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 diff --git a/testsuites/performance/pom.xml b/testsuites/performance/pom.xml index 9dafc8bd..9ee4c164 100644 --- a/testsuites/performance/pom.xml +++ b/testsuites/performance/pom.xml @@ -18,12 +18,13 @@ limitations under the License. ============LICENSE_END========================================================= --> - + 4.0.0 org.onap.policy.api api-testsuites - 3.0.0-SNAPSHOT + 3.0.1-SNAPSHOT api-performance diff --git a/testsuites/pom.xml b/testsuites/pom.xml index c49276c3..dad3137f 100644 --- a/testsuites/pom.xml +++ b/testsuites/pom.xml @@ -18,19 +18,20 @@ limitations under the License. ============LICENSE_END========================================================= --> - + 4.0.0 org.onap.policy.api policy-api - 3.0.0-SNAPSHOT + 3.0.1-SNAPSHOT api-testsuites pom - + true diff --git a/testsuites/stability/pom.xml b/testsuites/stability/pom.xml index fcd0bd40..57d7491d 100644 --- a/testsuites/stability/pom.xml +++ b/testsuites/stability/pom.xml @@ -18,12 +18,13 @@ limitations under the License. ============LICENSE_END========================================================= --> - + 4.0.0 org.onap.policy.api api-testsuites - 3.0.0-SNAPSHOT + 3.0.1-SNAPSHOT api-stability diff --git a/version.properties b/version.properties index 4ba0a9a8..3288dcdc 100644 --- a/version.properties +++ b/version.properties @@ -4,7 +4,7 @@ minor=3 minor=0 -patch=0 +patch=1 base_version=${major}.${minor}.${patch}