Skip to content

Commit

Permalink
Merge pull request #61 from sanctuuary/serialisation_fix
Browse files Browse the repository at this point in the history
Fix serialisation issue when returning object by the API
  • Loading branch information
kretep authored Apr 30, 2024
2 parents 385e9e2 + d1c29f9 commit 8da5e45
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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}.
*
Expand Down Expand Up @@ -151,7 +156,7 @@ private static List<WorkflowStepBenchmark> countCitationPerTool(List<JSONObject>
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");
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/nl/esciencecenter/restape/APEWorkflowMetadata.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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.

/**
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -130,7 +125,7 @@ private static List<Benchmark> 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);
Expand Down

0 comments on commit 8da5e45

Please sign in to comment.