diff options
author | Jim Hahn <jrh3@att.com> | 2020-08-13 11:15:29 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-08-13 12:27:43 -0400 |
commit | 72f4497f573d2b4f2306a99419021b659fb7d21f (patch) | |
tree | e932fba746532012475f09339f8d7af40df7f61b /models-interactions/model-actors/actorServiceProvider/src/main | |
parent | 00e48acdc51fa2a64b0f7fdc221c28308d7f214d (diff) |
Do not require context in ControlLoopOperationParams
Modified ControlLoopOperationParams so that the request ID can
be provided instead of the context. However, if the request ID
is not provided, then it still requires a context. (This requirement
should be lifted in a subsequent review).
Issue-ID: POLICY-2746
Change-Id: Ib00f46f2fe56430d700ee2edfba12f2c1a106a3f
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actorServiceProvider/src/main')
-rw-r--r-- | models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java index f5dd49877..d0b7c26a8 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/ControlLoopOperationParams.java @@ -33,6 +33,7 @@ import lombok.Getter; import org.onap.policy.common.parameters.BeanValidationResult; import org.onap.policy.common.parameters.BeanValidator; import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.ActorService; import org.onap.policy.controlloop.actorserviceprovider.Operation; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; @@ -68,10 +69,14 @@ public class ControlLoopOperationParams { /** * Event for which the operation applies. */ - @NotNull private ControlLoopEventContext context; /** + * If {@code null}, this value is extracted from the context. + */ + private UUID requestId; + + /** * Executor to use to run the operation. */ @NotNull @@ -175,7 +180,12 @@ public class ControlLoopOperationParams { * @return the event's request ID, or {@code null} if no request ID is available */ public UUID getRequestId() { - return (context == null || context.getEvent() == null ? null : context.getEvent().getRequestId()); + if (requestId == null && context != null && context.getEvent() != null) { + // cache the request ID + requestId = context.getEvent().getRequestId(); + } + + return requestId; } /** @@ -230,6 +240,34 @@ public class ControlLoopOperationParams { * @return the validation result */ public BeanValidationResult validate() { - return new BeanValidator().validateTop(ControlLoopOperationParams.class.getSimpleName(), this); + BeanValidationResult result = + new BeanValidator().validateTop(ControlLoopOperationParams.class.getSimpleName(), this); + + // validate that we have a request ID, or that we can get it from the context's + // event + + if (context == null) { + // no context specified - invoker must provide a request ID then + result.validateNotNull("requestId", requestId); + + } else if (requestId == null) { + // have a context, but no request ID - check the context's event for the + // request ID + BeanValidationResult contextResult = new BeanValidationResult("context", context); + VirtualControlLoopEvent event = context.getEvent(); + contextResult.validateNotNull("event", event); + + if (event != null) { + // cache the request id for later use + BeanValidationResult eventResult = new BeanValidationResult("event", event); + eventResult.validateNotNull("requestId", event.getRequestId()); + + contextResult.addResult(eventResult); + } + + result.addResult(contextResult); + } + + return result; } } |