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;
49 * @param source source object from which to copy
51 public OperationOutcome(OperationOutcome source) {
52 this.actor = source.actor;
53 this.operation = source.operation;
54 this.target = source.target;
55 this.start = source.start;
56 this.end = source.end;
57 this.subRequestId = source.subRequestId;
58 this.result = source.result;
59 this.message = source.message;
60 this.finalOutcome = source.finalOutcome;
64 * Creates a {@link ControlLoopOperation}, populating all fields with the values from
65 * this object. Sets the outcome field to the string representation of this object's
70 public ControlLoopOperation toControlLoopOperation() {
71 ControlLoopOperation clo = new ControlLoopOperation();
74 clo.setOperation(operation);
75 clo.setTarget(target);
78 clo.setSubRequestId(subRequestId);
79 clo.setOutcome(result.toString());
80 clo.setMessage(message);
86 * Determines if this outcome is for the given actor and operation.
88 * @param actor actor name
89 * @param operation operation name
90 * @return {@code true} if this outcome is for the given actor and operation
92 public boolean isFor(@NonNull String actor, @NonNull String operation) {
93 // do the operation check first, as it's most likely to be unique
94 return (operation.equals(this.operation) && actor.equals(this.actor));
98 * Determines if an outcome is for the given actor and operation.
100 * @param outcome outcome to be examined, or {@code null}
101 * @param actor actor name
102 * @param operation operation name
103 * @return {@code true} if this outcome is for the given actor and operation,
104 * {@code false} it is {@code null} or not for the actor/operation
106 public static boolean isFor(OperationOutcome outcome, String actor, String operation) {
107 return (outcome != null && outcome.isFor(actor, operation));
113 * @param result new result
115 public void setResult(@NonNull PolicyResult result) {
116 this.result = result;