adcb1410b8d791e20f3477ce428993109822c016
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2022-2023 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.runtime.main.rest.stub;
22
23 import java.util.UUID;
24 import lombok.RequiredArgsConstructor;
25 import org.onap.policy.clamp.acm.runtime.main.rest.gen.AutomationCompositionDefinitionApi;
26 import org.onap.policy.clamp.acm.runtime.main.web.AbstractRestController;
27 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
28 import org.onap.policy.clamp.models.acm.messages.rest.commissioning.AcTypeStateUpdate;
29 import org.onap.policy.clamp.models.acm.messages.rest.commissioning.CommissioningResponse;
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.context.annotation.Profile;
34 import org.springframework.http.ResponseEntity;
35 import org.springframework.web.bind.annotation.RestController;
36
37 @RestController
38 @Profile("stub")
39 @RequiredArgsConstructor
40 public class CommissioningControllerStub extends AbstractRestController implements AutomationCompositionDefinitionApi {
41
42     private final StubUtils stubUtils;
43
44     @Value("${stub.deleteCompositionDefinitionResponse}")
45     private String pathToResponseFile;
46
47     @Value("${stub.getAllCompositionDefinitions}")
48     private String pathToAllDefinitions;
49
50     @Value("${stub.getSingleCompositionDefinition}")
51     private String pathToSingleDefinition;
52
53     @Value("${stub.postCommissionResponse}")
54     private String pathToPostResponse;
55
56     @Value("${stub.putCompositionDefinitionUpdateResponse}")
57     private String pathToPutUpdate;
58
59     @Override
60     public ResponseEntity<CommissioningResponse> createCompositionDefinitions(ToscaServiceTemplate body,
61             UUID xonaprequestid) {
62         var compositionId = body.getMetadata() != null ? body.getMetadata().get("compositionId") : null;
63         if (compositionId == null) {
64             return stubUtils.getResponse(pathToPostResponse, CommissioningResponse.class);
65         } else {
66             return stubUtils.getResponse(pathToPutUpdate, CommissioningResponse.class);
67         }
68     }
69
70     @Override
71     public ResponseEntity<CommissioningResponse> deleteCompositionDefinition(UUID compositionId, UUID xonaprequestid) {
72         return stubUtils.getResponse(pathToResponseFile, CommissioningResponse.class);
73     }
74
75     @Override
76     public ResponseEntity<AutomationCompositionDefinition> getCompositionDefinition(UUID compositionId,
77             UUID xonaprequestid) {
78         return stubUtils.getResponse(pathToSingleDefinition, AutomationCompositionDefinition.class);
79     }
80
81     @Override
82     public ResponseEntity<ToscaServiceTemplates> queryCompositionDefinitions(String name, String version,
83             UUID xonaprequestid) {
84         return stubUtils.getResponse(pathToAllDefinitions, ToscaServiceTemplates.class);
85     }
86
87     @Override
88     public ResponseEntity<Void> compositionDefinitionPriming(UUID compositionId, UUID requestId,
89             AcTypeStateUpdate body) {
90         // TODO Auto-generated method stub
91         return null;
92     }
93 }