From d1c29f988f4958a080d774fea7fd2b2614009d63 Mon Sep 17 00:00:00 2001 From: Vedran Kasalica Date: Mon, 29 Apr 2024 16:21:23 +0200 Subject: [PATCH] Fix serialisation issue when returning object by the API --- .../OpenEBenchBenchmarkProcessor.java | 7 +++++- .../restape/APEWorkflowMetadata.java | 24 +++++++++---------- .../restape/ToolBenchmarkingAPIs.java | 7 +----- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/nl/esciencecenter/externalAPIs/OpenEBenchBenchmarkProcessor.java b/src/main/java/nl/esciencecenter/externalAPIs/OpenEBenchBenchmarkProcessor.java index cf9375c..518dda1 100644 --- a/src/main/java/nl/esciencecenter/externalAPIs/OpenEBenchBenchmarkProcessor.java +++ b/src/main/java/nl/esciencecenter/externalAPIs/OpenEBenchBenchmarkProcessor.java @@ -7,6 +7,8 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -15,6 +17,7 @@ import nl.esciencecenter.models.benchmarks.BenchmarkBase; import nl.esciencecenter.models.benchmarks.WorkflowStepBenchmark; import nl.esciencecenter.restape.LicenseType; +import nl.esciencecenter.restape.ToolBenchmarkingAPIs; /** * Class {@link OpenEBenchBenchmarkProcessor} used to compute the design-time benchmarks for a workflow using the @@ -27,6 +30,8 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public class OpenEBenchBenchmarkProcessor { + private static final Logger log = LoggerFactory.getLogger(OpenEBenchBenchmarkProcessor.class); + /** * Benchmark for each tool in the workflow the license type according to the openness of the license. The licensed are characterized according to {@link LicenseType}. * @@ -151,7 +156,7 @@ private static List countCitationPerTool(List biotoolsEntryBenchmark.setDescription(String.valueOf(count)); biotoolsEntries.add(biotoolsEntryBenchmark); } catch (JSONException e) { - e.printStackTrace(); + log.warn("No publication data found for tool: {}", toolAnnot.getString(ToolBenchmarkingAPIs.restAPEtoolID)); // set case for each license type biotoolsEntryBenchmark.setDesirabilityValue(0); biotoolsEntryBenchmark.setValue("0"); diff --git a/src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java b/src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java index 0e32af4..7304bce 100644 --- a/src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java +++ b/src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java @@ -1,6 +1,9 @@ package nl.esciencecenter.restape; import org.json.JSONObject; + +import com.fasterxml.jackson.annotation.JsonProperty; + import lombok.Getter; import lombok.NoArgsConstructor; import nl.uu.cs.ape.solver.solutionStructure.SolutionWorkflow; @@ -15,13 +18,21 @@ @NoArgsConstructor public class APEWorkflowMetadata { + @JsonProperty("workflow_name") private String workflowName; + @JsonProperty("descriptive_name") private String descriptiveName; + @JsonProperty("description") private String description; + @JsonProperty("workflow_length") private int workflowLength; + @JsonProperty("run_id") private String runId; + @JsonProperty("cwl_name") private String cwlName; + @JsonProperty("figure_name") private String figureName; + @JsonProperty("benchmark_file") private String benchmarkFile; // Optional, indicates if benchmark data should be included. /** @@ -72,17 +83,6 @@ public JSONObject toJSONObject() { * @return A JSON string representation of the APEWorkflowMetadata instance. */ public String toString() { - JSONObject json = new JSONObject(); - json.put("workflow_name", this.workflowName); - json.put("descriptive_name", this.descriptiveName); - json.put("description", this.description); - json.put("workflow_length", this.workflowLength); - json.put("run_id", this.runId); - json.put("cwl_name", this.cwlName); - json.put("figure_name", this.figureName); - if (this.benchmarkFile != null && !this.benchmarkFile.isEmpty()) { - json.put("benchmark_file", this.benchmarkFile); - } - return json.toString(); + return toJSONObject().toString(); } } diff --git a/src/main/java/nl/esciencecenter/restape/ToolBenchmarkingAPIs.java b/src/main/java/nl/esciencecenter/restape/ToolBenchmarkingAPIs.java index f953cf8..855d099 100644 --- a/src/main/java/nl/esciencecenter/restape/ToolBenchmarkingAPIs.java +++ b/src/main/java/nl/esciencecenter/restape/ToolBenchmarkingAPIs.java @@ -2,16 +2,11 @@ import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -import org.apache.commons.io.FileUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -130,7 +125,7 @@ private static List computeBiotoolsBenchmark(SolutionWorkflow workflo try { biotoolsEntry = BioToolsRestClient.fetchToolFromBioTools(toolID); } catch (JSONException | IOException e) { - e.printStackTrace(); + log.warn(e.getMessage()); } finally { biotoolsEntry.put(ToolBenchmarkingAPIs.restAPEtoolID, toolNode.getUsedModule().getPredicateLabel()); biotoolsAnnotations.add(biotoolsEntry);