ca5f08793f8e7bc6121774f57245a4589d141b8e
[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.DeployState;
34 import org.onap.policy.clamp.models.acm.concepts.LockState;
35 import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
36 import org.onap.policy.models.base.PfUtils;
37 import org.springframework.stereotype.Component;
38
39 /**
40  * This class is api implementation used by participant intermediary.
41  */
42 @Component
43 @RequiredArgsConstructor
44 public class ParticipantIntermediaryApiImpl implements ParticipantIntermediaryApi {
45
46     // The handler for the automationComposition intermediary
47     private final AutomationCompositionOutHandler automationCompositionHandler;
48     private final CacheProvider cacheProvider;
49
50     @Override
51     public void updateAutomationCompositionElementState(UUID automationCompositionId, UUID id, DeployState newState,
52             LockState lockState, StateChangeResult stateChangeResult, String message) {
53         automationCompositionHandler.updateAutomationCompositionElementState(automationCompositionId, id, newState,
54                 lockState, stateChangeResult, message);
55     }
56
57     @Override
58     public void sendAcElementInfo(UUID automationCompositionId, UUID elementId, String useState,
59             String operationalState, Map<String, Object> outProperties) {
60         automationCompositionHandler.sendAcElementInfo(automationCompositionId, elementId, useState, operationalState,
61                 outProperties);
62     }
63
64     @Override
65     public Map<UUID, AutomationComposition> getAutomationCompositions() {
66         return PfUtils.mapMap(cacheProvider.getAutomationCompositions(), AutomationComposition::new);
67     }
68
69     @Override
70     public void updateCompositionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult,
71             String message) {
72         automationCompositionHandler.updateCompositionState(compositionId, state, stateChangeResult, message);
73     }
74
75     @Override
76     public AutomationCompositionElement getAutomationCompositionElement(UUID automationCompositionId, UUID elementId) {
77         var automationComposition = cacheProvider.getAutomationCompositions().get(automationCompositionId);
78         if (automationComposition == null) {
79             return null;
80         }
81         var element = automationComposition.getElements().get(elementId);
82         return element != null ? new AutomationCompositionElement(element) : null;
83     }
84 }