X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=validation.git;a=blobdiff_plain;f=ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fakraino%2Fvalidation%2Fui%2Fcontroller%2FResultController.java;fp=ui%2Fsrc%2Fmain%2Fjava%2Forg%2Fakraino%2Fvalidation%2Fui%2Fcontroller%2FResultController.java;h=f9c205a415f023b02c908dd2721b01a40f7de76f;hp=0000000000000000000000000000000000000000;hb=2eba847ebb6acb2686be08eb1cdafc1b12071e7d;hpb=f86b9715d156238532fcb0bf464bd72e9cf7ce96 diff --git a/ui/src/main/java/org/akraino/validation/ui/controller/ResultController.java b/ui/src/main/java/org/akraino/validation/ui/controller/ResultController.java new file mode 100644 index 0000000..f9c205a --- /dev/null +++ b/ui/src/main/java/org/akraino/validation/ui/controller/ResultController.java @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.akraino.validation.ui.controller; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.Set; + +import org.akraino.validation.ui.client.nexus.resources.ValidationNexusTestResult; +import org.akraino.validation.ui.data.BlueprintLayer; +import org.akraino.validation.ui.data.Lab; +import org.akraino.validation.ui.service.DbResultAdapter; +import org.akraino.validation.ui.service.IntegratedResultService; +import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +@Controller +@RequestMapping("/api/v1/results") +public class ResultController extends RestrictedBaseController { + + private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ResultController.class); + + @Autowired + IntegratedResultService resultService; + + @Autowired + DbResultAdapter dbAdapter; + + public ResultController() { + super(); + } + + @RequestMapping(value = { "/getlabs/" }, method = RequestMethod.GET) + public ResponseEntity> getLabs() { + try { + return new ResponseEntity<>(resultService.getLabsFromDb(), HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, "Error when retrieving labs. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + + @RequestMapping(value = { "/getblueprintnamesoflab/{lab}" }, method = RequestMethod.GET) + public ResponseEntity> getBlueprintNamesOfLab(@PathVariable("lab") Lab lab) { + try { + return new ResponseEntity<>(resultService.getBlueprintNamesOfLabFromDb(lab), HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving blueprint names of a lab. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + + @RequestMapping(value = { "/getblueprintversions/{name}/{lab}" }, method = RequestMethod.GET) + public ResponseEntity> getBlueprintVersions(@PathVariable("name") String name, + @PathVariable("lab") Lab lab) { + try { + return new ResponseEntity<>(resultService.getBlueprintVersionsFromDb(name, lab), HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving blueprint versions. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + + @RequestMapping(value = { "/getbysubmissionid/{id}" }, method = RequestMethod.GET) + public ResponseEntity getBySubmissionId(@PathVariable("id") String submissionId) { + try { + return new ResponseEntity<>(resultService.getResults(submissionId), HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving results using submission id. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + + @RequestMapping(value = { "/getmostrecent/{name}/{version}/{lab}" }, method = RequestMethod.GET) + public ResponseEntity> getMostRecent(@PathVariable("name") String name, + @PathVariable("version") String version, @PathVariable("lab") Lab lab) { + try { + return new ResponseEntity<>(dbAdapter.readResultFromDb(name, version, lab, null, null, null, null), + HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving most recent results. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + + @RequestMapping(value = { "/getbytimestamp/{lab}/{name}/{version}/{timestamp}" }, method = RequestMethod.GET) + public ResponseEntity getByTimestamp(@PathVariable("lab") Lab lab, + @PathVariable("name") String name, @PathVariable("version") String version, + @PathVariable("timestamp") String timestamp) { + try { + return new ResponseEntity<>(resultService.getResult(name, version, lab, timestamp), HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving results using timestamp data. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + + @RequestMapping(value = { + "/getlastrun/{lab}/{name}/{version}/{allLayers}/{optional}/{outcome}" }, method = RequestMethod.GET) + public ResponseEntity getLastRun(@PathVariable("lab") Lab lab, + @PathVariable("name") String name, @PathVariable("version") String version, + @PathVariable("allLayers") Boolean allLayers, @PathVariable("optional") Boolean optional, + @PathVariable("outcome") boolean outcome) { + try { + return new ResponseEntity<>( + resultService.getLastResultBasedOnOutcome(name, version, lab, allLayers, optional, outcome), + HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving last result. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + + @RequestMapping(value = { + "/getlastrunoflayers/{lab}/{name}/{version}/{layers}/{optional}/{outcome}" }, method = RequestMethod.GET) + public ResponseEntity getLastRunOfLayers(@PathVariable("lab") Lab lab, + @PathVariable("name") String name, @PathVariable("version") String version, + @PathVariable("layers") List layers, @PathVariable("optional") Boolean optional, + @PathVariable("outcome") boolean outcome) { + try { + return new ResponseEntity<>( + resultService.getLastResultBasedOnOutcome(name, version, lab, layers, optional, outcome), + HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving last result. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + + @RequestMapping(value = { "/getbasedondate/{lab}/{name}/{version}/{date}" }, method = RequestMethod.GET) + public ResponseEntity> getBasedOnDate(@PathVariable("lab") Lab lab, + @PathVariable("name") String name, @PathVariable("version") String version, + @PathVariable("date") String date) { + try { + DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy"); + return new ResponseEntity<>( + resultService.getBasedOnDateFromNexus(name, version, lab, dateFormat.parse(date)), HttpStatus.OK); + } catch (Exception e) { + LOGGER.error(EELFLoggerDelegate.errorLogger, + "Error when retrieving results based on date. " + UserUtils.getStackTrace(e)); + } + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + } + +}