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.controlloop;
 
  23 import java.io.Serializable;
 
  25 import java.util.UUID;
 
  26 import java.util.concurrent.ConcurrentHashMap;
 
  27 import lombok.AccessLevel;
 
  29 import lombok.NonNull;
 
  31 import org.onap.policy.controlloop.VirtualControlLoopEvent;
 
  34  * Context associated with a control loop event.
 
  38 public class ControlLoopEventContext implements Serializable {
 
  39     private static final long serialVersionUID = 1L;
 
  42     private final VirtualControlLoopEvent event;
 
  45      * Enrichment data extracted from the event. Never {@code null}, though it may be
 
  48     private final Map<String, String> enrichment;
 
  50     @Getter(AccessLevel.NONE)
 
  51     @Setter(AccessLevel.NONE)
 
  52     private Map<String, Serializable> properties = new ConcurrentHashMap<>();
 
  55      * Request ID extracted from the event, or a generated value if the event has no
 
  56      * request id; never {@code null}.
 
  58     private final UUID requestId;
 
  62      * Constructs the object.
 
  64      * @param event event with which this is associated
 
  66     public ControlLoopEventContext(@NonNull VirtualControlLoopEvent event) {
 
  68         this.requestId = (event.getRequestId() != null ? event.getRequestId() : UUID.randomUUID());
 
  69         this.enrichment = (event.getAai() != null ? event.getAai() : Map.of());
 
  73      * Determines if the context contains a property.
 
  75      * @param name name of the property of interest
 
  76      * @return {@code true} if the context contains the property, {@code false} otherwise
 
  78     public boolean contains(String name) {
 
  79         return properties.containsKey(name);
 
  83      * Gets a property, casting it to the desired type.
 
  85      * @param <T> desired type
 
  86      * @param name name of the property whose value is to be retrieved
 
  87      * @return the property's value, or {@code null} if it does not yet have a value
 
  89     @SuppressWarnings("unchecked")
 
  90     public <T> T getProperty(String name) {
 
  91         return (T) properties.get(name);
 
  95      * Sets a property's value.
 
  97      * @param name property name
 
  98      * @param value new property value
 
 100     public void setProperty(String name, Serializable value) {
 
 101         properties.put(name, value);