2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2021-2023 Nordix Foundation.
 
   4  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
 
   5  * ================================================================================
 
   6  * Licensed under the Apache License, Version 2.0 (the "License");
 
   7  * you may not use this file except in compliance with the License.
 
   8  * You may obtain a copy of the License at
 
  10  *      http://www.apache.org/licenses/LICENSE-2.0
 
  12  * Unless required by applicable law or agreed to in writing, software
 
  13  * distributed under the License is distributed on an "AS IS" BASIS,
 
  14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  15  * See the License for the specific language governing permissions and
 
  16  * limitations under the License.
 
  18  * SPDX-License-Identifier: Apache-2.0
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
 
  25 import java.util.UUID;
 
  26 import lombok.RequiredArgsConstructor;
 
  27 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
 
  28 import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionOutHandler;
 
  29 import org.onap.policy.clamp.acm.participant.intermediary.handler.CacheProvider;
 
  30 import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
 
  31 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
 
  32 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
 
  33 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
 
  34 import org.onap.policy.clamp.models.acm.concepts.DeployState;
 
  35 import org.onap.policy.clamp.models.acm.concepts.LockState;
 
  36 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
 
  37 import org.onap.policy.models.base.PfUtils;
 
  38 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 
  39 import org.springframework.stereotype.Component;
 
  42  * This class is api implementation used by participant intermediary.
 
  45 @RequiredArgsConstructor
 
  46 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
 
  48     // The handler for the automationComposition intermediary
 
  49     private final AutomationCompositionOutHandler automationCompositionHandler;
 
  50     private final CacheProvider cacheProvider;
 
  53     public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState,
 
  54             LockState lockState, StateChangeResult stateChangeResult, String message) {
 
  55         automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, newState,
 
  56                 lockState, stateChangeResult, message);
 
  60     public void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState,
 
  61             String operationalState, Map<String, Object> outProperties) {
 
  62         automationCompositionHandler.sendAcElementInfo(automationCompositionId, elementId, useState, operationalState,
 
  67     public Map<UUID, AutomationComposition> getAutomationCompositions() {
 
  68         return PfUtils.mapMap(cacheProvider.getAutomationCompositions(), AutomationComposition::new);
 
  72     public void updateCompositionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult,
 
  74         automationCompositionHandler.updateCompositionState(compositionId, state, stateChangeResult, message);
 
  78     public AutomationCompositionElement getAutomationCompositionElement(UUID automationCompositionId, UUID elementId) {
 
  79         var automationComposition = cacheProvider.getAutomationCompositions().get(automationCompositionId);
 
  80         if (automationComposition == null) {
 
  83         var element = automationComposition.getElements().get(elementId);
 
  84         return element != null ? new AutomationCompositionElement(element) : null;
 
  88     public void sendAcDefinitionInfo(UUID compositionId, ToscaConceptIdentifier elementId,
 
  89             Map<String, Object> outProperties) {
 
  90         automationCompositionHandler.sendAcDefinitionInfo(compositionId, elementId, outProperties);
 
  94     public AutomationComposition getAutomationComposition(UUID automationCompositionId) {
 
  95         var automationComposition = cacheProvider.getAutomationCompositions().get(automationCompositionId);
 
  96         return automationComposition != null ? new AutomationComposition(automationComposition) : null;
 
 100     public Map<UUID, Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition>> getAcElementsDefinitions() {
 
 101         return PfUtils.mapMap(cacheProvider.getAcElementsDefinitions(),
 
 102                 map -> PfUtils.mapMap(map, AutomationCompositionElementDefinition::new));
 
 106     public Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> getAcElementsDefinitions(
 
 107             UUID compositionId) {
 
 108         var acElementDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId);
 
 109         if (acElementDefinitions == null) {
 
 112         return PfUtils.mapMap(acElementDefinitions, AutomationCompositionElementDefinition::new);
 
 116     public AutomationCompositionElementDefinition getAcElementDefinition(UUID compositionId,
 
 117             ToscaConceptIdentifier elementId) {
 
 118         var acElementDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId);
 
 119         if (acElementDefinitions == null) {
 
 122         var acElementDefinition = acElementDefinitions.get(elementId);
 
 123         return acElementDefinition != null ? new AutomationCompositionElementDefinition(acElementDefinition) : null;