use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.dbentities.TestReport in project IPK-BrAPI-Validator by plantbreeding.
the class TestReportResource method resourcesReport.
/**
* Get reduced report in a specific format
*
* @return JSON with endpoint data
*/
@GET
@Path("/shortreport/{reportId}/{format}")
@Produces({ MediaType.APPLICATION_JSON, "text/csv" })
public Response resourcesReport(@PathParam("reportId") String reportId, @PathParam("format") String format) {
if (Config.get("advancedMode") == null) {
return Response.status(Status.NOT_IMPLEMENTED).build();
}
LOGGER.debug("New GET /shortreport/" + format + ". Id: " + reportId);
if (!format.equalsIgnoreCase("csv") && !format.equalsIgnoreCase("json")) {
String e1 = JsonMessageManager.jsonMessage(400, "Invalid format.", 4400);
return Response.status(Status.BAD_REQUEST).entity(e1).build();
}
try {
TestReport tr = TestReportService.getReport(reportId);
String output;
String type;
if (format.equalsIgnoreCase("csv")) {
type = "text/csv";
output = generateCSVReport(tr);
return Response.ok().entity(output).type(type).header("Content-Disposition", "attachment; filename=\"report.csv\"").build();
} else {
type = "application/json";
output = generateJSONReport(tr);
return Response.ok().entity(output).type(type).build();
}
} catch (SQLException | IOException e) {
e.printStackTrace();
String e1 = JsonMessageManager.jsonMessage(500, "Internal server error", 5401);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1).build();
}
}
use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.dbentities.TestReport in project IPK-BrAPI-Validator by plantbreeding.
the class SingleTestResource method callTest.
/**
* Run a call test
*
* @param url Url of the BrAPI server. Example: https://test.brapi.org/brapi/v1/
* @return Response with json report
*/
@GET
@Path("/call")
@Produces(MediaType.APPLICATION_JSON)
public Response callTest(@QueryParam("url") String url, @QueryParam("brapiversion") @DefaultValue("") String version) {
LOGGER.debug("New GET /call call.");
try {
if (url.equals("")) {
String jsonError = JsonMessageManager.jsonMessage(400, "Missing or invalid url parameter", 4202);
return Response.status(Status.BAD_REQUEST).encoding(jsonError).build();
}
if (!version.equals("v1.0") && !version.equals("v1.1")) {
String jsonError = JsonMessageManager.jsonMessage(400, "Missing or invalid version parameter", 4202);
return Response.status(Status.BAD_REQUEST).encoding(jsonError).build();
}
String collectionResource;
ObjectMapper mapper = new ObjectMapper();
collectionResource = "/collections/CompleteBrapiTest." + version + ".json";
InputStream inJson = TestCollection.class.getResourceAsStream(collectionResource);
TestCollection tc = mapper.readValue(inJson, TestCollection.class);
Resource res = new Resource(url);
TestSuiteReport testSuiteReport = RunnerService.testEndpointWithCall(res, tc);
TestReport report = new TestReport(res, mapper.writeValueAsString(testSuiteReport));
return Response.ok().entity(report).build();
} catch (IllegalArgumentException e) {
e.printStackTrace();
String e1 = JsonMessageManager.jsonMessage(400, "invalid URL: port must be 80", 5201);
return Response.status(Status.BAD_REQUEST).entity(e1).build();
} catch (IOException e) {
// Thrown by .getResourceAsStream(""). Most probably because of missing file or wrong config structure.
e.printStackTrace();
String e1 = JsonMessageManager.jsonMessage(500, "internal server error", 5201);
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e1).build();
}
}
Aggregations