Fix nexus and sonar vulnerabilities
[policy/models.git] / models-interactions / model-actors / actor.appclcm / src / main / java / org / onap / policy / controlloop / actor / appclcm / AppcLcmOperation.java
index 1d687cd..4e8f590 100644 (file)
@@ -2,7 +2,8 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. 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.
@@ -22,7 +23,6 @@ package org.onap.policy.controlloop.actor.appclcm;
 
 import java.util.List;
 import java.util.Map;
-import java.util.concurrent.CompletableFuture;
 import org.onap.policy.appclcm.AppcLcmBody;
 import org.onap.policy.appclcm.AppcLcmCommonHeader;
 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
@@ -66,35 +66,27 @@ public class AppcLcmOperation extends BidirectionalTopicOperation<AppcLcmDmaapWr
         super(params, config, AppcLcmDmaapWrapper.class, PROPERTY_NAMES);
     }
 
-    /**
-     * Ensures that A&AI customer query has been performed, and then runs the guard query.
-     * Starts the GUARD using startGuardAsync.
-     */
-    @Override
-    protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
-        return startGuardAsync();
-    }
-
     @Override
     protected AppcLcmDmaapWrapper makeRequest(int attempt) {
         String subRequestId = getSubRequestId();
 
-        AppcLcmCommonHeader header = new AppcLcmCommonHeader();
+        var header = new AppcLcmCommonHeader();
         header.setOriginatorId(params.getRequestId().toString());
         header.setRequestId(params.getRequestId());
         header.setSubRequestId(subRequestId);
 
-        AppcLcmInput inputRequest = new AppcLcmInput();
+        var inputRequest = new AppcLcmInput();
         inputRequest.setCommonHeader(header);
 
-        AppcLcmRecipeFormatter recipeFormatter = new AppcLcmRecipeFormatter(getName());
+        var recipeFormatter = new AppcLcmRecipeFormatter(getName());
         inputRequest.setAction(recipeFormatter.getBodyRecipe());
 
         /*
          * Action Identifiers are required for APPC LCM requests. For R1, the recipes
          * supported by Policy only require a vnf-id.
          */
-        inputRequest.setActionIdentifiers(Map.of(VNF_ID_KEY, getTargetEntity()));
+        String target = getRequiredProperty(OperationProperties.AAI_TARGET_ENTITY, "target entity");
+        inputRequest.setActionIdentifiers(Map.of(VNF_ID_KEY, target));
 
         /*
          * For R1, the payloads will not be required for the Restart, Rebuild, or Migrate
@@ -108,10 +100,10 @@ public class AppcLcmOperation extends BidirectionalTopicOperation<AppcLcmDmaapWr
             inputRequest.setPayload(null);
         }
 
-        AppcLcmBody body = new AppcLcmBody();
+        var body = new AppcLcmBody();
         body.setInput(inputRequest);
 
-        AppcLcmDmaapWrapper dmaapRequest = new AppcLcmDmaapWrapper();
+        var dmaapRequest = new AppcLcmDmaapWrapper();
         dmaapRequest.setBody(body);
         dmaapRequest.setVersion("2.0");
         dmaapRequest.setCorrelationId(params.getRequestId() + "-" + subRequestId);
@@ -128,11 +120,11 @@ public class AppcLcmOperation extends BidirectionalTopicOperation<AppcLcmDmaapWr
      * decoded into an object.
      *
      * @param source source from which to get the values
-     * @param map where to place the decoded values
+     * @param request where to place the decoded values
      */
     private void convertPayload(Map<String, Object> source, AppcLcmInput request) {
         try {
-            String encodedPayloadString = getCoder().encode(source);
+            var encodedPayloadString = getCoder().encode(source);
             request.setPayload(encodedPayloadString);
         } catch (CoderException e) {
             throw new IllegalArgumentException("Cannot convert payload", e);
@@ -159,18 +151,13 @@ public class AppcLcmOperation extends BidirectionalTopicOperation<AppcLcmDmaapWr
             throw new IllegalArgumentException("unknown APPC-LCM response status code: " + status.getCode());
         }
 
-        switch (code) {
-            case AppcLcmResponseCode.SUCCESS:
-                return Status.SUCCESS;
-            case AppcLcmResponseCode.FAILURE:
-                return Status.FAILURE;
-            case AppcLcmResponseCode.ERROR:
-            case AppcLcmResponseCode.REJECT:
+        return switch (code) {
+            case AppcLcmResponseCode.SUCCESS -> Status.SUCCESS;
+            case AppcLcmResponseCode.FAILURE -> Status.FAILURE;
+            case AppcLcmResponseCode.ERROR, AppcLcmResponseCode.REJECT ->
                 throw new IllegalArgumentException("APPC-LCM request was not accepted, code=" + code);
-            case AppcLcmResponseCode.ACCEPTED:
-            default:
-                return Status.STILL_WAITING;
-        }
+            default -> Status.STILL_WAITING;
+        };
     }
 
     /**