Remove dmaap from models
[policy/models.git] / models-interactions / model-actors / actor.sdnr / src / main / java / org / onap / policy / controlloop / actor / sdnr / SdnrOperation.java
index 308ddd9..c466963 100644 (file)
@@ -2,7 +2,8 @@
  * ============LICENSE_START=======================================================
  * SdnrOperation
  * ================================================================================
- * 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-2024 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,7 +22,6 @@
 package org.onap.policy.controlloop.actor.sdnr;
 
 import java.util.List;
-import java.util.concurrent.CompletableFuture;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
@@ -70,11 +70,6 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
         return List.of(getSubRequestId());
     }
 
-    @Override
-    protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
-        return startGuardAsync();
-    }
-
     /*
      * NOTE: This should avoid throwing exceptions, so that a ControlLoopResponse can be
      * added to the outcome. Consequently, it returns FAILURE if a required field is
@@ -89,29 +84,24 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
             return Status.FAILURE;
         }
 
-        StatusCodeEnum code = StatusCodeEnum.fromStatusCode(response.getStatus().getCode());
+        var code = StatusCodeEnum.fromStatusCode(response.getStatus().getCode());
 
         if (code == null) {
             logger.warn("unknown SDNR response status code: {}", response.getStatus().getCode());
             return Status.FAILURE;
         }
 
-        switch (code) {
-            case SUCCESS:
-            case PARTIAL_SUCCESS:
-                return Status.SUCCESS;
-            case FAILURE:
-            case PARTIAL_FAILURE:
-                return Status.FAILURE;
-            case ERROR:
-            case REJECT:
+        return switch (code) {
+            case SUCCESS, PARTIAL_SUCCESS -> Status.SUCCESS;
+            case FAILURE, PARTIAL_FAILURE -> Status.FAILURE;
+            case ERROR, REJECT -> {
                 logger.warn("SDNR request was not accepted, code={}", code);
-                return Status.FAILURE;
-            case ACCEPTED:
-            default:
+                yield Status.FAILURE;
+            }
+            default ->
                 // awaiting a "final" response
-                return Status.STILL_WAITING;
-        }
+                Status.STILL_WAITING;
+        };
     }
 
     /**
@@ -125,7 +115,7 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
             return setOutcome(outcome, result);
         }
 
-        PciResponse pciResponse = responseWrapper.getBody().getOutput();
+        var pciResponse = responseWrapper.getBody().getOutput();
         if (pciResponse.getStatus() == null || pciResponse.getStatus().getValue() == null) {
             return setOutcome(outcome, result);
         }
@@ -141,46 +131,32 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
 
         /* Construct an SDNR request using pci Model */
 
-        PciMessage dmaapRequest = new PciMessage();
-        dmaapRequest.setVersion("1.0");
-        dmaapRequest.setCorrelationId(params.getRequestId() + "-" + subRequestId);
-        dmaapRequest.setType("request");
-        dmaapRequest.setRpcName(params.getOperation().toLowerCase());
+        var messageRequest = new PciMessage();
+        messageRequest.setVersion("1.0");
+        messageRequest.setCorrelationId(params.getRequestId() + "-" + subRequestId);
+        messageRequest.setType("request");
+        messageRequest.setRpcName(params.getOperation().toLowerCase());
 
-        /* This is the actual request that is placed in the dmaap wrapper. */
-        final PciRequest sdnrRequest = new PciRequest();
+        /* This is the actual request that is placed in the message wrapper. */
+        final var sdnrRequest = new PciRequest();
 
         /* The common header is a required field for all SDNR requests. */
-        PciCommonHeader requestCommonHeader = new PciCommonHeader();
+        var requestCommonHeader = new PciCommonHeader();
         requestCommonHeader.setRequestId(params.getRequestId());
         requestCommonHeader.setSubRequestId(subRequestId);
 
         sdnrRequest.setCommonHeader(requestCommonHeader);
-        sdnrRequest.setPayload(getEventPayload());
+        sdnrRequest.setPayload(getRequiredProperty(OperationProperties.EVENT_PAYLOAD, "event payload"));
         sdnrRequest.setAction(params.getOperation());
 
         /*
-         * Once the pci request is constructed, add it into the body of the dmaap wrapper.
+         * Once the pci request is constructed, add it into the body of the message wrapper.
          */
-        PciBody body = new PciBody();
+        var body = new PciBody();
         body.setInput(sdnrRequest);
-        dmaapRequest.setBody(body);
-
-        /* Return the request to be sent through dmaap. */
-        return dmaapRequest;
-    }
-
-    /**
-     * Gets the event payload, first checking for it in the properties and then in the
-     * event.
-     *
-     * @return the event payload
-     */
-    protected String getEventPayload() {
-        if (containsProperty(OperationProperties.EVENT_PAYLOAD)) {
-            return getProperty(OperationProperties.EVENT_PAYLOAD);
-        }
+        messageRequest.setBody(body);
 
-        return params.getContext().getEvent().getPayload();
+        /* Return the request to be sent through kafka. */
+        return messageRequest;
     }
 }