Remove Target and TargetType
[policy/models.git] / models-interactions / model-actors / actor.sdnr / src / main / java / org / onap / policy / controlloop / actor / sdnr / SdnrOperation.java
index 40face7..308ddd9 100644 (file)
@@ -22,14 +22,13 @@ package org.onap.policy.controlloop.actor.sdnr;
 
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
-import org.onap.policy.controlloop.ControlLoopResponse;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
 import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
 import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey;
-import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.sdnr.PciBody;
 import org.onap.policy.sdnr.PciCommonHeader;
 import org.onap.policy.sdnr.PciMessage;
@@ -47,6 +46,8 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
      */
     public static final String NAME = "any";
 
+    private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.EVENT_PAYLOAD);
+
     /**
      * Keys used to match the response with the request listener. The sub request ID is a
      * UUID, so it can be used to uniquely identify the response.
@@ -58,7 +59,7 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
                     List.of(new SelectorKey("body", "output", "CommonHeader", "SubRequestID"));
 
     public SdnrOperation(ControlLoopOperationParams params, BidirectionalTopicConfig config) {
-        super(params, config, PciMessage.class);
+        super(params, config, PciMessage.class, PROPERTY_NAMES);
     }
 
     /**
@@ -117,57 +118,32 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
      * Sets the message to the status description, if available.
      */
     @Override
-    public OperationOutcome setOutcome(OperationOutcome outcome, PolicyResult result, PciMessage responseWrapper) {
+    public OperationOutcome setOutcome(OperationOutcome outcome, OperationResult result, PciMessage responseWrapper) {
+        outcome.setResponse(responseWrapper);
+
         if (responseWrapper.getBody() == null || responseWrapper.getBody().getOutput() == null) {
-            outcome.setControlLoopResponse(makeControlLoopResponse(null));
             return setOutcome(outcome, result);
         }
 
-        PciResponse response = responseWrapper.getBody().getOutput();
-        if (response.getStatus() == null || response.getStatus().getValue() == null) {
-            outcome.setControlLoopResponse(makeControlLoopResponse(response.getPayload()));
+        PciResponse pciResponse = responseWrapper.getBody().getOutput();
+        if (pciResponse.getStatus() == null || pciResponse.getStatus().getValue() == null) {
             return setOutcome(outcome, result);
         }
 
         outcome.setResult(result);
-        outcome.setMessage(response.getStatus().getValue());
-        outcome.setControlLoopResponse(makeControlLoopResponse(response.getPayload()));
+        outcome.setMessage(pciResponse.getStatus().getValue());
         return outcome;
     }
 
-    /**
-     * Converts the SDNR response to a ControlLoopResponse.
-     *
-     * @param responsePayload payload from the response
-     *
-     * @return a new ControlLoopResponse
-     */
-    private ControlLoopResponse makeControlLoopResponse(String responsePayload) {
-        VirtualControlLoopEvent event = params.getContext().getEvent();
-
-        ControlLoopResponse clRsp = new ControlLoopResponse();
-        clRsp.setPayload(responsePayload);
-        clRsp.setFrom(params.getActor());
-        clRsp.setTarget("DCAE");
-        clRsp.setClosedLoopControlName(event.getClosedLoopControlName());
-        clRsp.setPolicyName(event.getPolicyName());
-        clRsp.setPolicyVersion(event.getPolicyVersion());
-        clRsp.setRequestId(event.getRequestId());
-        clRsp.setVersion(event.getVersion());
-
-        return clRsp;
-    }
-
     @Override
     protected PciMessage makeRequest(int attempt) {
-        VirtualControlLoopEvent onset = params.getContext().getEvent();
         String subRequestId = getSubRequestId();
 
         /* Construct an SDNR request using pci Model */
 
         PciMessage dmaapRequest = new PciMessage();
         dmaapRequest.setVersion("1.0");
-        dmaapRequest.setCorrelationId(onset.getRequestId() + "-" + subRequestId);
+        dmaapRequest.setCorrelationId(params.getRequestId() + "-" + subRequestId);
         dmaapRequest.setType("request");
         dmaapRequest.setRpcName(params.getOperation().toLowerCase());
 
@@ -176,11 +152,11 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
 
         /* The common header is a required field for all SDNR requests. */
         PciCommonHeader requestCommonHeader = new PciCommonHeader();
-        requestCommonHeader.setRequestId(onset.getRequestId());
+        requestCommonHeader.setRequestId(params.getRequestId());
         requestCommonHeader.setSubRequestId(subRequestId);
 
         sdnrRequest.setCommonHeader(requestCommonHeader);
-        sdnrRequest.setPayload(onset.getPayload());
+        sdnrRequest.setPayload(getEventPayload());
         sdnrRequest.setAction(params.getOperation());
 
         /*
@@ -193,4 +169,18 @@ public class SdnrOperation extends BidirectionalTopicOperation<PciMessage, PciMe
         /* 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);
+        }
+
+        return params.getContext().getEvent().getPayload();
+    }
 }