2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actorserviceprovider;
23 import java.time.Instant;
25 import lombok.NoArgsConstructor;
26 import lombok.NonNull;
27 import org.onap.policy.controlloop.ControlLoopOperation;
28 import org.onap.policy.controlloop.policy.PolicyResult;
31 * Outcome from an operation. Objects of this type are passed from one stage to the next.
35 public class OperationOutcome {
37 private String operation;
38 private String target;
39 private Instant start;
41 private String subRequestId;
42 private PolicyResult result = PolicyResult.SUCCESS;
43 private String message;
44 private boolean finalOutcome;
45 private Object response;
50 * @param source source object from which to copy
52 public OperationOutcome(OperationOutcome source) {
53 this.actor = source.actor;
54 this.operation = source.operation;
55 this.target = source.target;
56 this.start = source.start;
57 this.end = source.end;
58 this.subRequestId = source.subRequestId;
59 this.result = source.result;
60 this.message = source.message;
61 this.finalOutcome = source.finalOutcome;
62 this.response = source.response;
66 * Creates a {@link ControlLoopOperation}, populating all fields with the values from
67 * this object. Sets the outcome field to the string representation of this object's
72 public ControlLoopOperation toControlLoopOperation() {
73 ControlLoopOperation clo = new ControlLoopOperation();
76 clo.setOperation(operation);
77 clo.setTarget(target);
80 clo.setSubRequestId(subRequestId);
81 clo.setOutcome(result.toString());
82 clo.setMessage(message);
87 @SuppressWarnings("unchecked")
88 public <T> T getResponse() {
93 * Determines if this outcome is for the given actor and operation.
95 * @param actor actor name
96 * @param operation operation name
97 * @return {@code true} if this outcome is for the given actor and operation
99 public boolean isFor(@NonNull String actor, @NonNull String operation) {
100 // do the operation check first, as it's most likely to be unique
101 return (operation.equals(this.operation) && actor.equals(this.actor));
105 * Determines if an outcome is for the given actor and operation.
107 * @param outcome outcome to be examined, or {@code null}
108 * @param actor actor name
109 * @param operation operation name
110 * @return {@code true} if this outcome is for the given actor and operation,
111 * {@code false} it is {@code null} or not for the actor/operation
113 public static boolean isFor(OperationOutcome outcome, String actor, String operation) {
114 return (outcome != null && outcome.isFor(actor, operation));
120 * @param result new result
122 public void setResult(@NonNull PolicyResult result) {
123 this.result = result;