5cdbacab6d687a383c77d3991433c304d12f755d
[policy/clamp.git] /
1 /*-
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
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.Map;
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;
40
41 /**
42  * This class is api implementation used by participant intermediary.
43  */
44 @Component
45 @RequiredArgsConstructor
46 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
47
48     // The handler for the automationComposition intermediary
49     private final AutomationCompositionOutHandler automationCompositionHandler;
50     private final CacheProvider cacheProvider;
51
52     @Override
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);
57     }
58
59     @Override
60     public void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState,
61             String operationalState, Map<String, Object> outProperties) {
62         automationCompositionHandler.sendAcElementInfo(automationCompositionId, elementId, useState, operationalState,
63                 outProperties);
64     }
65
66     @Override
67     public Map<UUID, AutomationComposition> getAutomationCompositions() {
68         return PfUtils.mapMap(cacheProvider.getAutomationCompositions(), AutomationComposition::new);
69     }
70
71     @Override
72     public void updateCompositionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult,
73             String message) {
74         automationCompositionHandler.updateCompositionState(compositionId, state, stateChangeResult, message);
75     }
76
77     @Override
78     public AutomationCompositionElement getAutomationCompositionElement(UUID automationCompositionId, UUID elementId) {
79         var automationComposition = cacheProvider.getAutomationCompositions().get(automationCompositionId);
80         if (automationComposition == null) {
81             return null;
82         }
83         var element = automationComposition.getElements().get(elementId);
84         return element != null ? new AutomationCompositionElement(element) : null;
85     }
86
87     @Override
88     public void sendAcDefinitionInfo(UUID compositionId, ToscaConceptIdentifier elementId,
89             Map<String, Object> outProperties) {
90         automationCompositionHandler.sendAcDefinitionInfo(compositionId, elementId, outProperties);
91     }
92
93     @Override
94     public AutomationComposition getAutomationComposition(UUID automationCompositionId) {
95         var automationComposition = cacheProvider.getAutomationCompositions().get(automationCompositionId);
96         return automationComposition != null ? new AutomationComposition(automationComposition) : null;
97     }
98
99     @Override
100     public Map<UUID, Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition>> getAcElementsDefinitions() {
101         return PfUtils.mapMap(cacheProvider.getAcElementsDefinitions(),
102                 map -> PfUtils.mapMap(map, AutomationCompositionElementDefinition::new));
103     }
104
105     @Override
106     public Map<ToscaConceptIdentifier, AutomationCompositionElementDefinition> getAcElementsDefinitions(
107             UUID compositionId) {
108         var acElementDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId);
109         if (acElementDefinitions == null) {
110             return null;
111         }
112         return PfUtils.mapMap(acElementDefinitions, AutomationCompositionElementDefinition::new);
113     }
114
115     @Override
116     public AutomationCompositionElementDefinition getAcElementDefinition(UUID compositionId,
117             ToscaConceptIdentifier elementId) {
118         var acElementDefinitions = cacheProvider.getAcElementsDefinitions().get(compositionId);
119         if (acElementDefinitions == null) {
120             return null;
121         }
122         var acElementDefinition = acElementDefinitions.get(elementId);
123         return acElementDefinition != null ? new AutomationCompositionElementDefinition(acElementDefinition) : null;
124     }
125 }