Fix issues missed by checkstyle 30/142930/1
authorToineSiebelink <toine.siebelink@est.tech>
Wed, 14 Jan 2026 16:29:40 +0000 (16:29 +0000)
committerToineSiebelink <toine.siebelink@est.tech>
Wed, 14 Jan 2026 17:17:32 +0000 (17:17 +0000)
- Added a module in our checkstyle config to check for unused variable
  (very surprised this was never there)
- the missing finals in ProvMnSException were a false positive since there was a @NoArgsContructor
  (surprised Sonar didnt realize that)
- it was still a code smell though and I refactored the code so we didn't need the allArgsConstructor anymore (nor setters)
- also fixed valid warning on access level noArgsCosntructor (checkstyle never caught those before so that's ok)

Issue-ID: CPS-3128
Change-Id: I6acc5bd9bc6bd18f30a346e8049ce6ee456c580a
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
checkstyle/src/main/resources/cps-checkstyle/cps-java-style.xml
cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/ProvMnSController.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/exceptions/ProvMnSException.java
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/provmns/ParameterHelper.java
cps-service/src/main/java/org/onap/cps/impl/CpsDataServiceImpl.java

index 6e1664a..a7c36b8 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <!--
-   Copyright (C) 2024 Nordix Foundation.
+   Copyright (C) 2024-2026 OpenInfra Foundation Europe. 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.
@@ -337,6 +337,7 @@ https://lf-onap.atlassian.net/wiki/spaces/DW/pages/16429749/How+to+update+ONAP+c
             <property name="tokens" value="VARIABLE_DEF,PARAMETER_DEF"/>
             <property name="validateEnhancedForLoopVariable" value="true"/>
         </module>
+        <module name="UnusedLocalVariable"/>
         <module name="UnusedImports"/>
     </module>
-</module>
\ No newline at end of file
+</module>
index 7de3891..06c37d3 100644 (file)
@@ -216,10 +216,6 @@ public class ProvMnSController implements ProvMnS {
         if (exception instanceof ProvMnSException) {
             return (ProvMnSException) exception;
         }
-        final ProvMnSException provMnSException = new ProvMnSException();
-        provMnSException.setHttpMethodName(httpMethodName);
-        provMnSException.setTitle(exception.getMessage());
-        provMnSException.setBadOp(badOp);
         final HttpStatus httpStatus;
         if (exception instanceof PolicyExecutorException) {
             httpStatus = CONFLICT;
@@ -230,9 +226,8 @@ public class ProvMnSController implements ProvMnS {
         } else {
             httpStatus = INTERNAL_SERVER_ERROR;
         }
-        provMnSException.setHttpStatus(httpStatus);
-        log.warn("ProvMns Exception: {}", provMnSException.getTitle());
-        return provMnSException;
+        log.warn("ProvMns Exception: {}", exception.getMessage());
+        return new ProvMnSException(httpMethodName, httpStatus, exception.getMessage(), badOp);
     }
 
 }
index 28c451c..057a1a5 100644 (file)
 package org.onap.cps.ncmp.api.exceptions;
 
 import lombok.Getter;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
 import org.springframework.http.HttpStatus;
 
 @Getter
-@Setter
-@NoArgsConstructor
 public class ProvMnSException extends RuntimeException {
 
-    private String httpMethodName;
-    private HttpStatus httpStatus;
-    private String title;
-    private String badOp;
+    private final String httpMethodName;
+    private final HttpStatus httpStatus;
+    private final String title;
+    private final String badOp;
 
     /**
      * Constructor.
index d290385..1126ef0 100644 (file)
 package org.onap.cps.ncmp.impl.provmns;
 
 import jakarta.servlet.http.HttpServletRequest;
+import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.onap.cps.ncmp.api.exceptions.ProvMnSException;
 import org.springframework.http.HttpStatus;
 
-@NoArgsConstructor
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
 public class ParameterHelper {
 
     public static final String NO_OP = null;
index 69650df..de2e3c3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
+ *  Copyright (C) 2021-2026 OpenInfra Foundation Europe. All rights reserved.
  *  Modifications Copyright (C) 2020-2022 Bell Canada.
  *  Modifications Copyright (C) 2021 Pantheon.tech
  *  Modifications Copyright (C) 2022-2025 Deutsche Telekom AG
@@ -319,7 +319,6 @@ public class CpsDataServiceImpl implements CpsDataService {
         description = "Time taken to delete all data nodes for multiple anchors")
     public void deleteDataNodes(final String dataspaceName, final Collection<String> anchorNames,
                                 final OffsetDateTime observedTimestamp) {
-        final boolean deltaNotification = false;
         cpsValidator.validateNameCharacters(dataspaceName);
         cpsValidator.validateNameCharacters(anchorNames);
         cpsDataPersistenceService.deleteDataNodes(dataspaceName, anchorNames);