Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 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 |
|
| 23 | package org.onap.osam.controllers;
|
| 24 |
|
| 25 |
|
| 26 | import org.onap.osam.exceptions.OperationNotAllowedException;
|
| 27 | import org.onap.osam.model.ExceptionResponse;
|
| 28 |
|
| 29 | import org.onap.osam.model.JobAuditStatus;
|
| 30 | import org.onap.osam.model.ServiceInfo;
|
| 31 | import org.onap.osam.model.serviceInstantiation.ServiceInstantiation;
|
| 32 | import org.onap.osam.mso.MsoResponseWrapper2;
|
| 33 | import org.onap.osam.services.IAsyncInstantiationBusinessLogic;
|
| 34 | import org.springframework.beans.factory.annotation.Autowired;
|
| 35 | import org.springframework.web.bind.annotation.*;
|
| 36 | import javax.servlet.http.HttpServletRequest;
|
| 37 | import java.util.List;
|
| 38 | import java.util.UUID;
|
| 39 | import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED;
|
| 40 |
|
| 41 |
|
| 42 | @RestController
|
| 43 | @RequestMapping(AsyncInstantiationController.ASYNC_INSTANTIATION)
|
| 44 | public 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 | }
|