2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 * not use this file except in compliance with the License. You may obtain
6 * a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 * implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 package org.akraino.validation.ui.controller;
18 import java.text.DateFormat;
19 import java.text.SimpleDateFormat;
20 import java.util.List;
23 import org.akraino.validation.ui.client.nexus.resources.ValidationNexusTestResult;
24 import org.akraino.validation.ui.data.BlueprintLayer;
25 import org.akraino.validation.ui.data.Lab;
26 import org.akraino.validation.ui.service.DbResultAdapter;
27 import org.akraino.validation.ui.service.IntegratedResultService;
28 import org.onap.portalsdk.core.controller.RestrictedBaseController;
29 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
30 import org.onap.portalsdk.core.web.support.UserUtils;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.http.HttpStatus;
33 import org.springframework.http.ResponseEntity;
34 import org.springframework.stereotype.Controller;
35 import org.springframework.web.bind.annotation.PathVariable;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RequestMethod;
40 @RequestMapping("/api/v1/results")
41 public class ResultController extends RestrictedBaseController {
43 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ResultController.class);
46 IntegratedResultService resultService;
49 DbResultAdapter dbAdapter;
51 public ResultController() {
55 @RequestMapping(value = { "/getlabs/" }, method = RequestMethod.GET)
56 public ResponseEntity<Set<Lab>> getLabs() {
58 return new ResponseEntity<>(resultService.getLabsFromDb(), HttpStatus.OK);
59 } catch (Exception e) {
60 LOGGER.error(EELFLoggerDelegate.errorLogger, "Error when retrieving labs. " + UserUtils.getStackTrace(e));
62 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
65 @RequestMapping(value = { "/getblueprintnamesoflab/{lab}" }, method = RequestMethod.GET)
66 public ResponseEntity<Set<String>> getBlueprintNamesOfLab(@PathVariable("lab") Lab lab) {
68 return new ResponseEntity<>(resultService.getBlueprintNamesOfLabFromDb(lab), HttpStatus.OK);
69 } catch (Exception e) {
70 LOGGER.error(EELFLoggerDelegate.errorLogger,
71 "Error when retrieving blueprint names of a lab. " + UserUtils.getStackTrace(e));
73 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
76 @RequestMapping(value = { "/getblueprintversions/{name}/{lab}" }, method = RequestMethod.GET)
77 public ResponseEntity<Set<String>> getBlueprintVersions(@PathVariable("name") String name,
78 @PathVariable("lab") Lab lab) {
80 return new ResponseEntity<>(resultService.getBlueprintVersionsFromDb(name, lab), HttpStatus.OK);
81 } catch (Exception e) {
82 LOGGER.error(EELFLoggerDelegate.errorLogger,
83 "Error when retrieving blueprint versions. " + UserUtils.getStackTrace(e));
85 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
88 @RequestMapping(value = { "/getbysubmissionid/{id}" }, method = RequestMethod.GET)
89 public ResponseEntity<ValidationNexusTestResult> getBySubmissionId(@PathVariable("id") String submissionId) {
91 return new ResponseEntity<>(resultService.getResults(submissionId), HttpStatus.OK);
92 } catch (Exception e) {
93 LOGGER.error(EELFLoggerDelegate.errorLogger,
94 "Error when retrieving results using submission id. " + UserUtils.getStackTrace(e));
96 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
99 @RequestMapping(value = { "/getmostrecent/{name}/{version}/{lab}" }, method = RequestMethod.GET)
100 public ResponseEntity<List<ValidationNexusTestResult>> getMostRecent(@PathVariable("name") String name,
101 @PathVariable("version") String version, @PathVariable("lab") Lab lab) {
103 return new ResponseEntity<>(dbAdapter.readResultFromDb(name, version, lab, null, null, null, null),
105 } catch (Exception e) {
106 LOGGER.error(EELFLoggerDelegate.errorLogger,
107 "Error when retrieving most recent results. " + UserUtils.getStackTrace(e));
109 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
112 @RequestMapping(value = { "/getbytimestamp/{lab}/{name}/{version}/{timestamp}" }, method = RequestMethod.GET)
113 public ResponseEntity<ValidationNexusTestResult> getByTimestamp(@PathVariable("lab") Lab lab,
114 @PathVariable("name") String name, @PathVariable("version") String version,
115 @PathVariable("timestamp") String timestamp) {
117 return new ResponseEntity<>(resultService.getResult(name, version, lab, timestamp), HttpStatus.OK);
118 } catch (Exception e) {
119 LOGGER.error(EELFLoggerDelegate.errorLogger,
120 "Error when retrieving results using timestamp data. " + UserUtils.getStackTrace(e));
122 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
125 @RequestMapping(value = {
126 "/getlastrun/{lab}/{name}/{version}/{allLayers}/{optional}/{outcome}" }, method = RequestMethod.GET)
127 public ResponseEntity<ValidationNexusTestResult> getLastRun(@PathVariable("lab") Lab lab,
128 @PathVariable("name") String name, @PathVariable("version") String version,
129 @PathVariable("allLayers") Boolean allLayers, @PathVariable("optional") Boolean optional,
130 @PathVariable("outcome") boolean outcome) {
132 return new ResponseEntity<>(
133 resultService.getLastResultBasedOnOutcome(name, version, lab, allLayers, optional, outcome),
135 } catch (Exception e) {
136 LOGGER.error(EELFLoggerDelegate.errorLogger,
137 "Error when retrieving last result. " + UserUtils.getStackTrace(e));
139 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
142 @RequestMapping(value = {
143 "/getlastrunoflayers/{lab}/{name}/{version}/{layers}/{optional}/{outcome}" }, method = RequestMethod.GET)
144 public ResponseEntity<ValidationNexusTestResult> getLastRunOfLayers(@PathVariable("lab") Lab lab,
145 @PathVariable("name") String name, @PathVariable("version") String version,
146 @PathVariable("layers") List<BlueprintLayer> layers, @PathVariable("optional") Boolean optional,
147 @PathVariable("outcome") boolean outcome) {
149 return new ResponseEntity<>(
150 resultService.getLastResultBasedOnOutcome(name, version, lab, layers, optional, outcome),
152 } catch (Exception e) {
153 LOGGER.error(EELFLoggerDelegate.errorLogger,
154 "Error when retrieving last result. " + UserUtils.getStackTrace(e));
156 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
159 @RequestMapping(value = { "/getbasedondate/{lab}/{name}/{version}/{date}" }, method = RequestMethod.GET)
160 public ResponseEntity<List<ValidationNexusTestResult>> getBasedOnDate(@PathVariable("lab") Lab lab,
161 @PathVariable("name") String name, @PathVariable("version") String version,
162 @PathVariable("date") String date) {
164 DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
165 return new ResponseEntity<>(
166 resultService.getBasedOnDateFromNexus(name, version, lab, dateFormat.parse(date)), HttpStatus.OK);
167 } catch (Exception e) {
168 LOGGER.error(EELFLoggerDelegate.errorLogger,
169 "Error when retrieving results based on date. " + UserUtils.getStackTrace(e));
171 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);