Skip to content

Commit

Permalink
Object Oriented Serilization
Browse files Browse the repository at this point in the history
Instead of reading in the JSON as a hash map using strings to index java object is used instead.
  • Loading branch information
AvocadoMoon committed Jan 19, 2024
1 parent 6ef459f commit 8111f04
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 17 deletions.
57 changes: 57 additions & 0 deletions src/main/java/org/vcell/vcellfiji/ExportDataRepresentation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.vcell.vcellfiji;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Stack;

public class ExportDataRepresentation {
public ArrayList<String> globalJobIDs;
public HashMap<String, FormatExportDataRepresentation> formatData;

public ExportDataRepresentation(ArrayList<String> globalJobIDs, HashMap<String, FormatExportDataRepresentation> formatData){
this.globalJobIDs = globalJobIDs;
this.formatData = formatData;
}

public static class FormatExportDataRepresentation {
public HashMap<String, SimulationExportDataRepresentation> simulationDataMap;
public Stack<String> formatJobIDs;

public FormatExportDataRepresentation(HashMap<String, SimulationExportDataRepresentation> simulationDataMap, Stack<String> formatJobIDs){
this.formatJobIDs = formatJobIDs;
this.simulationDataMap = simulationDataMap;
}
}

public static class SimulationExportDataRepresentation {
public String exportDate;
public String uri;
public String jobID;
public String dataID;
public String simulationName;
public String applicationName;
public String biomodelName;
public String variables;
public String startAndEndTime;

public ArrayList<String> defaultParameterValues;
public ArrayList<String> setParameterValues;

public SimulationExportDataRepresentation(String exportDate, String uri, String jobID, String dataID, String simulationName,
String applicationName, String biomodelName, String variables, String startAndEndTime,
ArrayList<String> defaultParameterValues, ArrayList<String> setParameterValues){
this.exportDate = exportDate;
this.uri = uri;
this.jobID = jobID;
this.dataID = dataID;
this.simulationName = simulationName;
this.applicationName = applicationName;
this.biomodelName = biomodelName;
this.variables = variables;
this.startAndEndTime = startAndEndTime;
this.defaultParameterValues = defaultParameterValues;
this.setParameterValues = setParameterValues;
}
}

}
28 changes: 11 additions & 17 deletions src/main/java/org/vcell/vcellfiji/N5ImageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public void actionPerformed(ActionEvent e) {
protected ArrayList<String> doInBackground() throws Exception {
vGui.setCursor(new Cursor(Cursor.WAIT_CURSOR));
ArrayList<String> n5DataSetList = null;

if (e.getSource() == vGui.localFileDialog) {
selectedLocalFile = vGui.localFileDialog.getSelectedFile();
n5DataSetList = getN5DatasetList();
Expand All @@ -79,19 +78,15 @@ protected ArrayList<String> doInBackground() throws Exception {
createS3Client(vGui.remoteFileSelection.getS3URL(), vGui.remoteFileSelection.returnCredentials(), vGui.remoteFileSelection.returnEndpoint());
n5DataSetList = getS3N5DatasetList();
} else if (e.getSource() == vGui.mostRecentExport) {
HashMap<String, Object> jsonData = getJsonData();
if (jsonData != null) {
List<String> set = (ArrayList<String>) jsonData.get("jobIDs");
LinkedTreeMap<String, String> lastElement = null;
for (int i = set.size() - 1; i > -1; i--) {
lastElement = (LinkedTreeMap<String, String>) jsonData.get(set.get(i));
if (lastElement != null && lastElement.get("format").equalsIgnoreCase("n5")) {
break;
}
lastElement = null;
}
ExportDataRepresentation jsonData = getJsonData();
if (jsonData != null && jsonData.formatData.containsKey("N5")) {
ExportDataRepresentation.FormatExportDataRepresentation formatExportDataRepresentation = jsonData.formatData.get("N5");
Stack<String> formatJobIDs = formatExportDataRepresentation.formatJobIDs;
String jobID = formatJobIDs.isEmpty() ? null : formatJobIDs.peek();

ExportDataRepresentation.SimulationExportDataRepresentation lastElement = jobID == null ? null : formatExportDataRepresentation.simulationDataMap.get(jobID);
if (lastElement != null) {
String url = lastElement.get("uri");
String url = lastElement.uri;
createS3Client(url);
n5DataSetList = getS3N5DatasetList();
}
Expand Down Expand Up @@ -338,13 +333,12 @@ public static void main(String[] args) {
n5ImageHandler.run();
}

public static HashMap<String, Object> getJsonData() throws FileNotFoundException {
public static ExportDataRepresentation getJsonData() throws FileNotFoundException {
File jsonFile = new File(System.getProperty("user.home") + "/.vcell", "exportMetaData.json");
if (jsonFile.exists() && jsonFile.length() != 0){
HashMap<String, Object> jsonHashMap;
ExportDataRepresentation jsonHashMap;
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Type type = new TypeToken<HashMap<String, Object>>() {}.getType();
jsonHashMap = gson.fromJson(new FileReader(jsonFile.getAbsolutePath()), type);
jsonHashMap = gson.fromJson(new FileReader(jsonFile.getAbsolutePath()), ExportDataRepresentation.class);
return jsonHashMap;
}
return null;
Expand Down

0 comments on commit 8111f04

Please sign in to comment.