2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. 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.vid.controller;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
26 import org.onap.vid.exceptions.OperationNotAllowedException;
27 import org.onap.vid.model.ExceptionResponse;
28 import org.onap.vid.model.JobAuditStatus;
29 import org.onap.vid.model.ServiceInfo;
30 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
31 import org.onap.vid.mso.MsoResponseWrapper2;
32 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
33 import org.onap.vid.services.AuditService;
34 import org.onap.vid.utils.SystemPropertiesWrapper;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.web.bind.annotation.*;
38 import javax.servlet.http.HttpServletRequest;
39 import java.util.List;
40 import java.util.UUID;
42 import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED;
46 @RequestMapping(AsyncInstantiationController.ASYNC_INSTANTIATION)
47 public class AsyncInstantiationController extends VidRestrictedBaseController {
49 public static final String ASYNC_INSTANTIATION = "asyncInstantiation";
51 protected final AsyncInstantiationBusinessLogic asyncInstantiationBL;
52 private final SystemPropertiesWrapper systemPropertiesWrapper;
54 protected ObjectMapper objectMapper = new ObjectMapper();
57 protected AuditService auditService;
60 public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL, SystemPropertiesWrapper systemPropertiesWrapper) {
61 this.asyncInstantiationBL = asyncInstantiationBL;
62 this.systemPropertiesWrapper = systemPropertiesWrapper;
65 @ExceptionHandler(OperationNotAllowedException.class)
66 @ResponseStatus(value=METHOD_NOT_ALLOWED)
67 public ExceptionResponse illegalStateExceptionHandler(Exception e) {
68 return ControllersUtils.handleException(e, LOGGER);
72 * Gets the new services status.
73 * @param request the request
74 * @return the services list
76 @RequestMapping(method = RequestMethod.GET)
77 public List<ServiceInfo> getServicesInfo(HttpServletRequest request) {
78 return asyncInstantiationBL.getAllServicesInfo();
81 @RequestMapping(value = "bulk", method = RequestMethod.POST)
82 public MsoResponseWrapper2<List<String>> createBulkOfServices(@RequestBody ServiceInstantiation request, HttpServletRequest httpServletRequest) {
83 //Push to DB according the model
85 LOGGER.debug(EELFLoggerDelegate.debugLogger, "incoming ServiceInstantiation request: "+ objectMapper.writeValueAsString(request));
88 LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to log incoming ServiceInstantiation request ", e);
90 String userId = new ControllersUtils(systemPropertiesWrapper).extractUserId(httpServletRequest);
91 List<UUID> uuids = asyncInstantiationBL.pushBulkJob(request, userId);
93 return new MsoResponseWrapper2(200, uuids);
96 @RequestMapping(value = "job/{jobId}", method = RequestMethod.DELETE)
97 public void deleteServiceInfo(@PathVariable("jobId") UUID jobId) {
98 asyncInstantiationBL.deleteJob(jobId);
101 @RequestMapping(value = "hide/{jobId}", method = RequestMethod.POST)
102 public void hideServiceInfo(@PathVariable("jobId") UUID jobId) {
103 asyncInstantiationBL.hideServiceInfo(jobId);
106 @RequestMapping(value = "auditStatus/{jobId}", method = RequestMethod.GET)
107 public List<JobAuditStatus> getJobAuditStatus(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId, @RequestParam(value="source") JobAuditStatus.SourceStatus source){
108 return asyncInstantiationBL.getAuditStatuses(jobId, source);
111 @RequestMapping(value = "auditStatus/{jobId}/mso", method = RequestMethod.GET)
112 public List<JobAuditStatus> getJobMsoAuditStatusForAlaCarte(HttpServletRequest request,
113 @PathVariable(value="jobId") UUID jobId,
114 @RequestParam(value="requestId", required = false) UUID requestId,
115 @RequestParam(value="serviceInstanceId", required = false) UUID serviceInstanceId){
116 if (serviceInstanceId != null) {
117 return auditService.getAuditStatusFromMsoByServiceInstanceId(jobId, serviceInstanceId);
119 if (requestId != null){
120 return auditService.getAuditStatusFromMsoByRequestId(jobId, requestId);
122 return auditService.getAuditStatusFromMsoByJobId(jobId);