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.entity.ValidationDbTestResult;
24 import org.akraino.validation.ui.service.DbAdapter;
25 import org.akraino.validation.ui.service.IntegratedResultService;
26 import org.onap.portalsdk.core.controller.RestrictedBaseController;
27 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
28 import org.onap.portalsdk.core.web.support.UserUtils;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.http.HttpStatus;
31 import org.springframework.http.ResponseEntity;
32 import org.springframework.stereotype.Controller;
33 import org.springframework.web.bind.annotation.PathVariable;
34 import org.springframework.web.bind.annotation.RequestMapping;
35 import org.springframework.web.bind.annotation.RequestMethod;
38 @RequestMapping("/api/v1/results")
39 public class ResultController extends RestrictedBaseController {
41 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ResultController.class);
44 IntegratedResultService resultService;
49 public ResultController() {
53 @RequestMapping(value = { "/getblueprintnamesoflab/{lab}" }, method = RequestMethod.GET)
54 public ResponseEntity<Set<String>> getBlueprintNamesOfLab(@PathVariable("lab") String lab) {
56 return new ResponseEntity<>(resultService.getBlueprintNamesOfLabFromDb(lab), HttpStatus.OK);
57 } catch (Exception e) {
58 LOGGER.error(EELFLoggerDelegate.errorLogger,
59 "Error when retrieving blueprint names of a lab. " + UserUtils.getStackTrace(e));
61 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
64 @RequestMapping(value = { "/getblueprintversions/{name}/{lab}" }, method = RequestMethod.GET)
65 public ResponseEntity<Set<String>> getBlueprintVersions(@PathVariable("name") String name,
66 @PathVariable("lab") String lab) {
68 return new ResponseEntity<>(resultService.getBlueprintVersionsFromDb(name, lab), HttpStatus.OK);
69 } catch (Exception e) {
70 LOGGER.error(EELFLoggerDelegate.errorLogger,
71 "Error when retrieving blueprint versions. " + UserUtils.getStackTrace(e));
73 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
76 @RequestMapping(value = { "/getbysubmissionid/{id}" }, method = RequestMethod.GET)
77 public ResponseEntity<ValidationDbTestResult> getBySubmissionId(@PathVariable("id") String submissionId) {
79 return new ResponseEntity<>(resultService.getResults(submissionId), HttpStatus.OK);
80 } catch (Exception e) {
81 LOGGER.error(EELFLoggerDelegate.errorLogger,
82 "Error when retrieving results using submission id. " + UserUtils.getStackTrace(e));
84 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
87 @RequestMapping(value = { "/getmostrecent/{name}/{version}/{lab}" }, method = RequestMethod.GET)
88 public ResponseEntity<List<ValidationDbTestResult>> getMostRecent(@PathVariable("name") String name,
89 @PathVariable("version") String version, @PathVariable("lab") String lab) {
91 return new ResponseEntity<>(dbAdapter.readResultFromDb(name, version, lab, null, null, null, null),
93 } catch (Exception e) {
94 LOGGER.error(EELFLoggerDelegate.errorLogger,
95 "Error when retrieving most recent results. " + UserUtils.getStackTrace(e));
97 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
100 @RequestMapping(value = { "/getbytimestamp/{lab}/{name}/{version}/{timestamp}" }, method = RequestMethod.GET)
101 public ResponseEntity<ValidationDbTestResult> getByTimestamp(@PathVariable("lab") String lab,
102 @PathVariable("name") String name, @PathVariable("version") String version,
103 @PathVariable("timestamp") String timestamp) {
105 return new ResponseEntity<>(resultService.getResult(name, version, lab, timestamp), HttpStatus.OK);
106 } catch (Exception e) {
107 LOGGER.error(EELFLoggerDelegate.errorLogger,
108 "Error when retrieving results using timestamp data. " + UserUtils.getStackTrace(e));
110 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
113 @RequestMapping(value = {
114 "/getlastrun/{lab}/{name}/{version}/{allLayers}/{optional}/{outcome}" }, method = RequestMethod.GET)
115 public ResponseEntity<ValidationDbTestResult> getLastRun(@PathVariable("lab") String lab,
116 @PathVariable("name") String name, @PathVariable("version") String version,
117 @PathVariable("allLayers") Boolean allLayers, @PathVariable("optional") Boolean optional,
118 @PathVariable("outcome") boolean outcome) {
120 return new ResponseEntity<>(
121 resultService.getLastResultBasedOnOutcome(name, version, lab, allLayers, optional, outcome),
123 } catch (Exception e) {
124 LOGGER.error(EELFLoggerDelegate.errorLogger,
125 "Error when retrieving last result. " + UserUtils.getStackTrace(e));
127 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
130 @RequestMapping(value = {
131 "/getlastrunoflayers/{lab}/{name}/{version}/{layers}/{optional}/{outcome}" }, method = RequestMethod.GET)
132 public ResponseEntity<ValidationDbTestResult> getLastRunOfLayers(@PathVariable("lab") String lab,
133 @PathVariable("name") String name, @PathVariable("version") String version,
134 @PathVariable("layers") List<String> layers, @PathVariable("optional") Boolean optional,
135 @PathVariable("outcome") boolean outcome) {
137 return new ResponseEntity<>(
138 resultService.getLastResultBasedOnOutcome(name, version, lab, layers, optional, outcome),
140 } catch (Exception e) {
141 LOGGER.error(EELFLoggerDelegate.errorLogger,
142 "Error when retrieving last result. " + UserUtils.getStackTrace(e));
144 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
147 @RequestMapping(value = { "/getbasedondate/{lab}/{name}/{version}/{date}" }, method = RequestMethod.GET)
148 public ResponseEntity<List<ValidationDbTestResult>> getBasedOnDate(@PathVariable("lab") String lab,
149 @PathVariable("name") String name, @PathVariable("version") String version,
150 @PathVariable("date") String date) {
152 DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
153 return new ResponseEntity<>(
154 resultService.getBasedOnDateFromNexus(name, version, lab, dateFormat.parse(date)), HttpStatus.OK);
155 } catch (Exception e) {
156 LOGGER.error(EELFLoggerDelegate.errorLogger,
157 "Error when retrieving results based on date. " + UserUtils.getStackTrace(e));
159 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);