2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021-2022 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;
24 import java.util.LinkedHashMap;
25 import java.util.List;
27 import java.util.UUID;
28 import org.onap.policy.clamp.acm.participant.intermediary.api.AutomationCompositionElementListener;
29 import org.onap.policy.clamp.acm.participant.intermediary.api.ParticipantIntermediaryApi;
30 import org.onap.policy.clamp.acm.participant.intermediary.handler.AutomationCompositionHandler;
31 import org.onap.policy.clamp.acm.participant.intermediary.handler.ParticipantHandler;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
34 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
35 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
36 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
37 import org.onap.policy.clamp.models.acm.concepts.Participant;
38 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
39 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
42 import org.springframework.stereotype.Component;
45 * This class is api implementation used by participant intermediary.
48 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
50 // The handler for the participant intermediary
51 private final ParticipantHandler participantHandler;
53 // The handler for the automationComposition intermediary
54 private final AutomationCompositionHandler automationCompositionHandler;
59 * @param participantHandler ParticipantHandler
60 * @param automationCompositionHandler AutomationCompositionHandler
62 public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler,
63 AutomationCompositionHandler automationCompositionHandler) {
64 this.participantHandler = participantHandler;
65 this.automationCompositionHandler = automationCompositionHandler;
69 public void registerAutomationCompositionElementListener(
70 AutomationCompositionElementListener automationCompositionElementListener) {
71 automationCompositionHandler.registerAutomationCompositionElementListener(automationCompositionElementListener);
75 public List<Participant> getParticipants(String name, String version) {
76 return List.of(participantHandler.getParticipant(name, version));
80 public Map<String, ToscaProperty> getAcElementDefinitionCommonProperties(ToscaConceptIdentifier acElementDef) {
81 return participantHandler.getAcElementDefinitionCommonProperties(acElementDef);
85 public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
86 return participantHandler.updateParticipantState(definition, state);
90 public AutomationCompositions getAutomationCompositions(String name, String version) {
91 return automationCompositionHandler.getAutomationCompositions();
95 public Map<UUID, AutomationCompositionElement> getAutomationCompositionElements(String name, String version) {
96 List<AutomationComposition> automationCompositions =
97 automationCompositionHandler.getAutomationCompositions().getAutomationCompositionList();
99 for (AutomationComposition automationComposition : automationCompositions) {
100 if (name.equals(automationComposition.getDefinition().getName())) {
101 return automationComposition.getElements();
104 return new LinkedHashMap<>();
108 public AutomationCompositionElement getAutomationCompositionElement(UUID id) {
109 List<AutomationComposition> automationCompositions =
110 automationCompositionHandler.getAutomationCompositions().getAutomationCompositionList();
112 for (AutomationComposition automationComposition : automationCompositions) {
113 AutomationCompositionElement acElement = automationComposition.getElements().get(id);
114 if (acElement != null) {
122 public AutomationCompositionElement updateAutomationCompositionElementState(
123 ToscaConceptIdentifier automationCompositionId, UUID id, AutomationCompositionOrderedState currentState,
124 AutomationCompositionState newState, ParticipantMessageType messageType) {
125 return automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id,
126 currentState, newState);