fc94f34761ef9e1165a9138729f5e2cfb8c3513c
[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.HttpStatus;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.web.bind.annotation.RestController;
37
38 @RestController
39 @Profile("stub")
40 @RequiredArgsConstructor
41 public class CommissioningControllerStub extends AbstractRestController implements AutomationCompositionDefinitionApi {
42
43     private final StubUtils stubUtils;
44
45     @Value("${stub.deleteCompositionDefinitionResponse}")
46     private String pathToResponseFile;
47
48     @Value("${stub.getAllCompositionDefinitions}")
49     private String pathToAllDefinitions;
50
51     @Value("${stub.getSingleCompositionDefinition}")
52     private String pathToSingleDefinition;
53
54     @Value("${stub.postCommissionResponse}")
55     private String pathToPostResponse;
56
57     @Value("${stub.putCompositionDefinitionUpdateResponse}")
58     private String pathToPutUpdate;
59
60     @Override
61     public ResponseEntity<CommissioningResponse> createCompositionDefinitions(ToscaServiceTemplate body,
62             UUID xonaprequestid) {
63         var compositionId = body.getMetadata() != null ? body.getMetadata().get("compositionId") : null;
64         if (compositionId == null) {
65             return stubUtils.getResponse(pathToPostResponse, CommissioningResponse.class);
66         } else {
67             return stubUtils.getResponse(pathToPutUpdate, CommissioningResponse.class);
68         }
69     }
70
71     @Override
72     public ResponseEntity<CommissioningResponse> deleteCompositionDefinition(UUID compositionId, UUID xonaprequestid) {
73         return stubUtils.getResponse(pathToResponseFile, CommissioningResponse.class);
74     }
75
76     @Override
77     public ResponseEntity<AutomationCompositionDefinition> getCompositionDefinition(UUID compositionId,
78             UUID xonaprequestid) {
79         return stubUtils.getResponse(pathToSingleDefinition, AutomationCompositionDefinition.class);
80     }
81
82     @Override
83     public ResponseEntity<ToscaServiceTemplates> queryCompositionDefinitions(String name, String version,
84             UUID xonaprequestid) {
85         return stubUtils.getResponse(pathToAllDefinitions, ToscaServiceTemplates.class);
86     }
87
88     @Override
89     public ResponseEntity<Void> compositionDefinitionPriming(UUID compositionId, UUID requestId,
90             AcTypeStateUpdate body) {
91         return new ResponseEntity<>(HttpStatus.ACCEPTED);
92     }
93 }