1a1f8500f276e27beef9eb895ce157266103517a
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.clamp.acm.participant.intermediary.api.impl;
23
24 import java.util.LinkedHashMap;
25 import java.util.List;
26 import java.util.Map;
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.AcElementStatistics;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
34 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
35 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
36 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
37 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
38 import org.onap.policy.clamp.models.acm.concepts.Participant;
39 import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
40 import org.onap.policy.clamp.models.acm.concepts.ParticipantStatistics;
41 import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
44 import org.springframework.stereotype.Component;
45
46 /**
47  * This class is api implementation used by participant intermediary.
48  */
49 @Component
50 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
51
52     // The handler for the participant intermediary
53     private final ParticipantHandler participantHandler;
54
55     // The handler for the automationComposition intermediary
56     private final AutomationCompositionHandler automationCompositionHandler;
57
58     /**
59      * Constructor.
60      *
61      * @param participantHandler ParticipantHandler
62      * @param automationCompositionHandler AutomationCompositionHandler
63      */
64     public ParticipantIntermediaryApiImpl(ParticipantHandler participantHandler,
65         AutomationCompositionHandler automationCompositionHandler) {
66         this.participantHandler = participantHandler;
67         this.automationCompositionHandler = automationCompositionHandler;
68     }
69
70     @Override
71     public void registerAutomationCompositionElementListener(
72         AutomationCompositionElementListener automationCompositionElementListener) {
73         automationCompositionHandler.registerAutomationCompositionElementListener(automationCompositionElementListener);
74     }
75
76     @Override
77     public List<Participant> getParticipants(String name, String version) {
78         return List.of(participantHandler.getParticipant(name, version));
79     }
80
81     @Override
82     public Map<String, ToscaProperty> getAcElementDefinitionCommonProperties(ToscaConceptIdentifier acElementDef) {
83         return participantHandler.getAcElementDefinitionCommonProperties(acElementDef);
84     }
85
86     @Override
87     public Participant updateParticipantState(ToscaConceptIdentifier definition, ParticipantState state) {
88         return participantHandler.updateParticipantState(definition, state);
89     }
90
91     @Override
92     public void updateParticipantStatistics(ParticipantStatistics participantStatistics) {
93         participantHandler.updateParticipantStatistics(participantStatistics);
94     }
95
96     @Override
97     public AutomationCompositions getAutomationCompositions(String name, String version) {
98         return automationCompositionHandler.getAutomationCompositions();
99     }
100
101     @Override
102     public Map<UUID, AutomationCompositionElement> getAutomationCompositionElements(String name, String version) {
103         List<AutomationComposition> automationCompositions =
104             automationCompositionHandler.getAutomationCompositions().getAutomationCompositionList();
105
106         for (AutomationComposition automationComposition : automationCompositions) {
107             if (name.equals(automationComposition.getDefinition().getName())) {
108                 return automationComposition.getElements();
109             }
110         }
111         return new LinkedHashMap<>();
112     }
113
114     @Override
115     public AutomationCompositionElement getAutomationCompositionElement(UUID id) {
116         List<AutomationComposition> automationCompositions =
117             automationCompositionHandler.getAutomationCompositions().getAutomationCompositionList();
118
119         for (AutomationComposition automationComposition : automationCompositions) {
120             AutomationCompositionElement acElement = automationComposition.getElements().get(id);
121             if (acElement != null) {
122                 return acElement;
123             }
124         }
125         return null;
126     }
127
128     @Override
129     public AutomationCompositionElement updateAutomationCompositionElementState(
130         ToscaConceptIdentifier automationCompositionId, UUID id, AutomationCompositionOrderedState currentState,
131         AutomationCompositionState newState, ParticipantMessageType messageType) {
132         return automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id,
133             currentState, newState);
134     }
135
136     @Override
137     public void updateAutomationCompositionElementStatistics(UUID id, AcElementStatistics elementStatistics) {
138         automationCompositionHandler.updateAutomationCompositionElementStatistics(id, elementStatistics);
139     }
140 }