1 package org.onap.vid.controller;
4 import com.fasterxml.jackson.databind.ObjectMapper;
5 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
6 import org.onap.vid.exceptions.OperationNotAllowedException;
7 import org.onap.vid.model.ExceptionResponse;
8 import org.onap.vid.model.JobAuditStatus;
9 import org.onap.vid.model.ServiceInfo;
10 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
11 import org.onap.vid.mso.MsoResponseWrapper2;
12 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
13 import org.onap.vid.services.AuditService;
14 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.web.bind.annotation.*;
17 import javax.servlet.http.HttpServletRequest;
18 import java.util.List;
19 import java.util.UUID;
21 import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED;
25 @RequestMapping(AsyncInstantiationController.ASYNC_INSTANTIATION)
26 public class AsyncInstantiationController extends VidRestrictedBaseController {
28 public static final String ASYNC_INSTANTIATION = "asyncInstantiation";
30 protected final AsyncInstantiationBusinessLogic asyncInstantiationBL;
32 protected ObjectMapper objectMapper = new ObjectMapper();
35 protected AuditService auditService;
38 public AsyncInstantiationController(AsyncInstantiationBusinessLogic asyncInstantiationBL) {
39 this.asyncInstantiationBL = asyncInstantiationBL;
42 @ExceptionHandler(OperationNotAllowedException.class)
43 @ResponseStatus(value=METHOD_NOT_ALLOWED)
44 public ExceptionResponse illegalStateExceptionHandler(Exception e) {
45 return ControllersUtils.handleException(e, LOGGER);
49 * Gets the new services status.
50 * @param request the request
51 * @return the services list
53 @RequestMapping(method = RequestMethod.GET)
54 public List<ServiceInfo> getServicesInfo(HttpServletRequest request) {
55 return asyncInstantiationBL.getAllServicesInfo();
58 @RequestMapping(value = "bulk", method = RequestMethod.POST)
59 public MsoResponseWrapper2<List<String>> createBulkOfServices(@RequestBody ServiceInstantiation request, HttpServletRequest httpServletRequest) {
60 //Push to DB according the model
62 LOGGER.debug(EELFLoggerDelegate.debugLogger, "incoming ServiceInstantiation request: "+ objectMapper.writeValueAsString(request));
65 LOGGER.error(EELFLoggerDelegate.errorLogger, "failed to log incoming ServiceInstantiation request ", e);
67 String userId = ControllersUtils.extractUserId(httpServletRequest);
68 List<UUID> uuids = asyncInstantiationBL.pushBulkJob(request, userId);
70 return new MsoResponseWrapper2(200, uuids);
73 @RequestMapping(value = "job/{jobId}", method = RequestMethod.DELETE)
74 public void deleteServiceInfo(@PathVariable("jobId") UUID jobId) {
75 asyncInstantiationBL.deleteJob(jobId);
78 @RequestMapping(value = "hide/{jobId}", method = RequestMethod.POST)
79 public void hideServiceInfo(@PathVariable("jobId") UUID jobId) {
80 asyncInstantiationBL.hideServiceInfo(jobId);
83 @RequestMapping(value = "auditStatus/{jobId}", method = RequestMethod.GET)
84 public List<JobAuditStatus> getJobAuditStatus(HttpServletRequest request, @PathVariable(value="jobId") UUID jobId, @RequestParam(value="source") JobAuditStatus.SourceStatus source){
85 return asyncInstantiationBL.getAuditStatuses(jobId, source);
88 @RequestMapping(value = "auditStatus/{jobId}/mso", method = RequestMethod.GET)
89 public List<JobAuditStatus> getJobMsoAuditStatusForAlaCarte(HttpServletRequest request,
90 @PathVariable(value="jobId") UUID jobId,
91 @RequestParam(value="requestId", required = false) UUID requestId,
92 @RequestParam(value="serviceInstanceId", required = false) UUID serviceInstanceId){
93 if (serviceInstanceId != null) {
94 return auditService.getAuditStatusFromMsoByServiceInstanceId(jobId, serviceInstanceId);
96 if (requestId != null){
97 return auditService.getAuditStatusFromMsoByRequestId(jobId, requestId);
99 return auditService.getAuditStatusFromMsoByJobId(jobId);