2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.requestsdb;
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;
31 public class OrchestrationTaskRepositoryCustomController {
34 private OrchestrationTaskRepository orchestrationTaskRepository;
36 @RequestMapping(method = RequestMethod.GET, value = "/orchestrationTask")
37 public List<OrchestrationTask> getAllOrchestrationTask() {
38 return orchestrationTaskRepository.findAll();
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));
47 @RequestMapping(method = RequestMethod.POST, value = "/orchestrationTask/")
48 public OrchestrationTask createOrchestrationTask(@RequestBody OrchestrationTask orchestrationTask) {
49 return orchestrationTaskRepository.save(orchestrationTask);
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);
58 @RequestMapping(method = RequestMethod.DELETE, value = "/orchestrationTask/{taskId}")
59 public void deleteOrchestrationTask(@PathVariable("taskId") String taskId) {
60 orchestrationTaskRepository.deleteById(taskId);