Skip to content

Commit

Permalink
Sync source tree
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanni committed Mar 9, 2018
1 parent f983ee8 commit 17dd7ea
Show file tree
Hide file tree
Showing 16 changed files with 449 additions and 408 deletions.
Binary file added lib/square/okhttp-3.10.0.jar
Binary file not shown.
Binary file added lib/square/okio-1.14.0.jar
Binary file not shown.
130 changes: 0 additions & 130 deletions src/org/helioviewer/jhv/base/FileUtils.java

This file was deleted.

38 changes: 0 additions & 38 deletions src/org/helioviewer/jhv/base/JSONUtils.java

This file was deleted.

6 changes: 4 additions & 2 deletions src/org/helioviewer/jhv/base/Regex.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public class Regex {
public static final Pattern FloatingPoint = Pattern.compile("[\\x00-\\x20]*[+-]?(NaN|Infinity|((((\\p{Digit}+)(\\.)?((\\p{Digit}+)?)([eE][+-]?(\\p{Digit}+))?)|(\\.((\\p{Digit}+))([eE][+-]?(\\p{Digit}+))?)|(((0[xX](\\p{XDigit}+)(\\.)?)|(0[xX](\\p{XDigit}+)?(\\.)(\\p{XDigit}+)))[pP][+-]?(\\p{Digit}+)))[fFdD]?))[\\x00-\\x20]*");
public static final Pattern Integer = Pattern.compile("\\d+");

// Pattern to extract the filename from HTTP Content-Disposition header
public static final Pattern ContentDispositionFilename = Pattern.compile("filename=\\\"(.*?)\\\"");
public static final Pattern Comma = Pattern.compile(",");
public static final Pattern Return = Pattern.compile("\n");
public static final Pattern Space = Pattern.compile(" ");
public static final Pattern HttpField = Pattern.compile(": ");

}
55 changes: 38 additions & 17 deletions src/org/helioviewer/jhv/io/DataSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

import org.everit.json.schema.Validator;

@SuppressWarnings("serial")
public class DataSources {

static final Set<String> SupportedObservatories = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(
"SOHO", "SDO", "STEREO_A", "STEREO_B", "PROBA2", "ROB-USET", "ROB-Humain", "NSO-GONG", "NSO-SOLIS", "Kanzelhoehe", "NRH", "Yohkoh", "Hinode", "TRACE"
)));

private static final HashMap<String, HashMap<String, String>> serverSettings = new HashMap<String, HashMap<String, String>>() {
private static final Map<String, Map<String, String>> serverSettings = Collections.unmodifiableMap(new LinkedHashMap<String, Map<String, String>>() {
{
put("ROB", new HashMap<String, String>() {
put("ROB", Collections.unmodifiableMap(new HashMap<String, String>() {
{
put("API.getDataSources", "http://swhv.oma.be/hv/api/?action=getDataSources&verbose=true&enable=[STEREO_A,STEREO_B,PROBA2]");
put("API.getJP2Image", "http://swhv.oma.be/hv/api/index.php?action=getJP2Image&");
Expand All @@ -25,56 +28,73 @@ public class DataSources {
put("schema", "/data/sources_v1.0.json");
put("availability.images", "http://swhv.oma.be/availability/images/availability/availability.html");
}
});
put("IAS", new HashMap<String, String>() {
}));
/* put("ROB Test", Collections.unmodifiableMap(new HashMap<String, String>() {
{
put("API.getDataSources", "http://swhv2.oma.be:8083/index.php?action=getDataSources&verbose=true&enable=[STEREO_A,STEREO_B,PROBA2]");
put("API.getJP2Image", "http://swhv2.oma.be:8083/index.php?action=getJP2Image&");
put("API.getJPX", "http://swhv2.oma.be:8083/index.php?action=getJPX&");
put("label", "Royal Observatory of Belgium");
put("schema", "/data/sources_v1.0.json");
put("availability.images", "http://swhv2.oma.be/availability/images/availability/availability.html");
}
})); */
put("IAS", Collections.unmodifiableMap(new HashMap<String, String>() {
{
put("API.getDataSources", "https://helioviewer-api.ias.u-psud.fr/v2/getDataSources/?verbose=true&enable=[TRACE,Hinode,Yohkoh,STEREO_A,STEREO_B,PROBA2]");
put("API.getJP2Image", "https://helioviewer-api.ias.u-psud.fr/v2/getJP2Image/?");
put("API.getJPX", "https://helioviewer-api.ias.u-psud.fr/v2/getJPX/?");
put("label", "Institut d'Astrophysique Spatiale");
put("schema", "/data/sources_v1.0.json");
}
});
put("GSFC", new HashMap<String, String>() {
}));
/* put("IAS Test", Collections.unmodifiableMap(new HashMap<String, String>() {
{
put("API.getDataSources", "https://inf-helio-test-api.ias.u-psud.fr/v2/getDataSources/?verbose=true&enable=[TRACE,Hinode,Yohkoh,STEREO_A,STEREO_B,PROBA2]");
put("API.getJP2Image", "https://inf-helio-test-api.ias.u-psud.fr/v2/getJP2Image/?");
put("API.getJPX", "https://inf-helio-test-api.ias.u-psud.fr/v2/getJPX/?");
put("label", "Institut d'Astrophysique Spatiale");
put("schema", "/data/sources_v1.0.json");
}
})); */
put("GSFC", Collections.unmodifiableMap(new HashMap<String, String>() {
{
put("API.getDataSources", "https://api.helioviewer.org/v2/getDataSources/?verbose=true&enable=[TRACE,Hinode,Yohkoh,STEREO_A,STEREO_B,PROBA2]");
put("API.getJP2Image", "https://api.helioviewer.org/v2/getJP2Image/?");
put("API.getJPX", "https://api.helioviewer.org/v2/getJPX/?");
put("label", "Goddard Space Flight Center");
put("schema", "/data/sources_v1.0.json");
}
});
/*
put("GSFC SCI Test", new HashMap<String, String>() {
}));
/* put("GSFC SCI Test", Collections.unmodifiableMap(new HashMap<String, String>() {
{
put("API.getDataSources", "http://helioviewer.sci.gsfc.nasa.gov/api.php?action=getDataSources&verbose=true&enable=[TRACE,Hinode,Yohkoh,STEREO_A,STEREO_B,PROBA2]");
put("API.getJP2Image", "http://helioviewer.sci.gsfc.nasa.gov/api.php?action=getJP2Image&");
put("API.getJPX", "http://helioviewer.sci.gsfc.nasa.gov/api.php?action=getJPX&");
put("label", "Goddard Space Flight Center SCI Test");
put("schema", "/data/sources_v1.0.json");
}
});
put("GSFC NDC Test", new HashMap<String, String>() {
}));
put("GSFC NDC Test", Collections.unmodifiableMap(new HashMap<String, String>() {
{
put("API.getDataSources", "http://gs671-heliovw7.ndc.nasa.gov/api.php?action=getDataSources&verbose=true&enable=[TRACE,Hinode,Yohkoh,STEREO_A,STEREO_B,PROBA2]");
put("API.getJP2Image", "http://gs671-heliovw7.ndc.nasa.gov/api.php?action=getJP2Image&");
put("API.getJPX", "http://gs671-heliovw7.ndc.nasa.gov/api.php?action=getJPX&");
put("label", "Goddard Space Flight Center NDC Test");
put("schema", "/data/sources_v1.0.json");
}
});
put("LOCALHOST", new HashMap<String, String>() {
})); */
/* put("LOCALHOST", Collections.unmodifiableMap(new HashMap<String, String>() {
{
put("API.getDataSources", "http://localhost:8080/helioviewer/api/?action=getDataSources&verbose=true&enable=[STEREO_A,STEREO_B,PROBA2]");
put("API.getJP2Image", "http://localhost:8080/helioviewer/api/index.php?action=getJP2Image&");
put("API.getJPX", "http://localhost:8080/helioviewer/api/index.php?action=getJPX&");
put("schema", "/data/sources_v1.0.json");
put("label", "Localhost");
}
});
*/
})); */
}
};
});

public static Set<String> getServers() {
return serverSettings.keySet();
Expand All @@ -86,8 +106,9 @@ public static String getServerSetting(String server, String setting) {
}

public static void loadSources() {
Validator validator = Validator.builder().failEarly().build();
for (String serverName : serverSettings.keySet())
new DataSourcesTask(serverName);
new DataSourcesTask(serverName, validator);
}

}
22 changes: 12 additions & 10 deletions src/org/helioviewer/jhv/io/DataSourcesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,23 @@

import java.io.InputStream;

import org.helioviewer.jhv.log.Log;
import org.helioviewer.jhv.time.TimeUtils;

import org.everit.json.schema.Schema;
import org.everit.json.schema.Validator;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaLoader;
import org.helioviewer.jhv.base.FileUtils;
import org.helioviewer.jhv.base.JSONUtils;
import org.helioviewer.jhv.log.Log;
import org.helioviewer.jhv.time.TimeUtils;
import org.json.JSONObject;
import org.json.JSONTokener;

public class DataSourcesTask implements Runnable {

private final Validator validator;
private final String url;
private final String schemaName;

public DataSourcesTask(String server) {
public DataSourcesTask(String server, Validator _validator) {
validator = _validator;
url = DataSources.getServerSetting(server, "API.getDataSources");
schemaName = DataSources.getServerSetting(server, "schema");
Thread t = new Thread(this, server);
Expand All @@ -26,12 +27,13 @@ public DataSourcesTask(String server) {

@Override
public void run() {
try (InputStream is = FileUtils.getResourceInputStream(schemaName)) {
JSONObject rawSchema = new JSONObject(new JSONTokener(is));
try (InputStream is = FileUtils.getResource(schemaName)) {
JSONObject rawSchema = JSONUtils.get(is);
SchemaLoader schemaLoader = SchemaLoader.builder().schemaJson(rawSchema).addFormatValidator(new TimeUtils.SQLDateTimeFormatValidator()).build();
Schema schema = schemaLoader.load().build();
JSONObject json = JSONUtils.getJSONStream(new DownloadStream(url).getInput());
schema.validate(json);

JSONObject jo = JSONUtils.get(url);
validator.performValidation(schema, jo);
} catch (ValidationException e) {
Log.error("Server " + url + " " + e);
e.getCausingExceptions().stream().map(ValidationException::getMessage).forEach(Log::error);
Expand Down
Loading

0 comments on commit 17dd7ea

Please sign in to comment.