blob: 7296c20fe5880cfc2e39c5ee018c70738e9fa68c [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
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
22
23package org.onap.osam.controllers;
24
25
26import org.onap.osam.exceptions.OperationNotAllowedException;
27import org.onap.osam.model.ExceptionResponse;
28
29import org.onap.osam.model.JobAuditStatus;
30import org.onap.osam.model.ServiceInfo;
31import org.onap.osam.model.serviceInstantiation.ServiceInstantiation;
32import org.onap.osam.mso.MsoResponseWrapper2;
33import org.onap.osam.services.IAsyncInstantiationBusinessLogic;
34import org.springframework.beans.factory.annotation.Autowired;
35import org.springframework.web.bind.annotation.*;
36import javax.servlet.http.HttpServletRequest;
37import java.util.List;
38import java.util.UUID;
39import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED;
40
41
42@RestController
43@RequestMapping(AsyncInstantiationController.ASYNC_INSTANTIATION)
44public class AsyncInstantiationController extends OsamCoreRestrictedBaseController {
45
46 public static final String ASYNC_INSTANTIATION = "asyncInstantiation";
47
48 protected final IAsyncInstantiationBusinessLogic asyncInstantiationBL;
49
50 @Autowired
51 public AsyncInstantiationController(IAsyncInstantiationBusinessLogic asyncInstantiationBL) {
52 this.asyncInstantiationBL = asyncInstantiationBL;
53 }
54
55 @ExceptionHandler(OperationNotAllowedException.class)
56 @ResponseStatus(value=METHOD_NOT_ALLOWED)
57 public ExceptionResponse illegalStateExceptionHandler(Exception e) {
58 return ControllersUtils.handleException(e, LOGGER);
59 }
60
61 @RequestMapping(method = RequestMethod.GET)
62 public List<ServiceInfo> getServicesInfo(HttpServletRequest request) {
63 return asyncInstantiationBL.getAllServicesInfo();
64 }
65
66 @RequestMapping(value = "bulk", method = RequestMethod.POST)
67 public MsoResponseWrapper2<List<String>> createBulkOfServices(@RequestBody ServiceInstantiation request, HttpServletRequest httpServletRequest) {
68 //Push to DB according the model
69
70 String userId = ControllersUtils.extractUserId(httpServletRequest);
71 List<UUID> uuids = asyncInstantiationBL.pushBulkJob(request, userId);
72
73 return new MsoResponseWrapper2(200, uuids);
74 }
75
76 @RequestMapping(value = "job/{jobId}", method = RequestMethod.DELETE)
77 public void deleteServiceInfo(@PathVariable("jobId") UUID jobId) {
78 asyncInstantiationBL.deleteJob(jobId);
79 }
80
81 @RequestMapping(value = "hide/{jobId}", method = RequestMethod.POST)
82 public void hideServiceInfo(@PathVariable("jobId") UUID jobId) {
83 asyncInstantiationBL.hideServiceInfo(jobId);
84 }
85
86 @RequestMapping(value = "auditStatus/{jobId}", method = RequestMethod.GET)
87 public List<JobAuditStatus> getJobAuditStatus(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId, @RequestParam(value="source") JobAuditStatus.SourceStatus source){
88 return asyncInstantiationBL.getAuditStatuses(jobId, source);
89 }
90
91
92}