e32d90b137e01bd30113917a212954bf42b8df2a
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License")
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.requestsdb;
22
23 import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException;
24 import org.onap.so.db.request.beans.OrchestrationTask;
25 import org.onap.so.db.request.data.repository.OrchestrationTaskRepository;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.web.bind.annotation.*;
28 import java.util.List;
29
30 @RestController
31 public class OrchestrationTaskRepositoryCustomController {
32
33     @Autowired
34     private OrchestrationTaskRepository orchestrationTaskRepository;
35
36     @RequestMapping(method = RequestMethod.GET, value = "/orchestrationTask")
37     public List<OrchestrationTask> getAllOrchestrationTask() {
38         return orchestrationTaskRepository.findAll();
39     }
40
41     @RequestMapping(method = RequestMethod.GET, value = "/orchestrationTask/{taskId}")
42     public OrchestrationTask getOrchestrationTask(@PathVariable("taskId") String taskId) throws MsoRequestsDbException {
43         return orchestrationTaskRepository.findById(taskId)
44                 .orElseThrow(() -> new MsoRequestsDbException("orchestration task not found: " + taskId));
45     }
46
47     @RequestMapping(method = RequestMethod.POST, value = "/orchestrationTask/")
48     public OrchestrationTask createOrchestrationTask(@RequestBody OrchestrationTask orchestrationTask) {
49         return orchestrationTaskRepository.save(orchestrationTask);
50     }
51
52     @RequestMapping(method = RequestMethod.PUT, value = "/orchestrationTask/{taskId}")
53     public OrchestrationTask updateOrchestrationTask(@PathVariable("taskId") String taskId,
54             @RequestBody OrchestrationTask orchestrationTask) throws MsoRequestsDbException {
55         return orchestrationTaskRepository.save(orchestrationTask);
56     }
57
58     @RequestMapping(method = RequestMethod.DELETE, value = "/orchestrationTask/{taskId}")
59     public void deleteOrchestrationTask(@PathVariable("taskId") String taskId) {
60         orchestrationTaskRepository.deleteById(taskId);
61     }
62 }