Commit 4759c52d authored by Cyrille Poncelet's avatar Cyrille Poncelet
Browse files

Split Json in subfiles

parent e9055030
This diff is collapsed.
This diff is collapsed.
{
"name": "Provenance",
"dims": [
{
"value": "unlimited",
"javaValue": "1",
"name": "filenames",
"comment": "Can be of fixed or unlimited length, as appropriate."
}
],
"types": [],
"attributes": [
{
"name": "conversion_software_name",
"obligation": "MA",
"comment": "Name of the software used to do the conversion."
},
{
"name": "conversion_software_version",
"obligation": "MA",
"comment": "Version of the software used to do the conversion."
},
{
"name": "conversion_time",
"obligation": "MA",
"comment": "Date and time of the start of the conversion process in extended ISO8601:2005 extended format, including time zone."
}
],
"variables": [
{
"name": "source_filenames",
"obligation": "MA",
"comment": "Vector of datafile names that were used to generate the data in this SONAR-netCDF4 file.",
"dims": [
"filenames"
],
"type": "string",
"attributes": [
{
"name": "long_name",
"value": "Source filenames"
}
]
}
],
"coordinatevariables": [],
"subGroups": []
}
\ No newline at end of file
{
"name": "",
"obligation": "M",
"comment": "root",
"dims": [],
"types": [],
"attributes": [
{
"name": "Conventions",
"obligation": "M",
"comment": "A comma-separated list of the conventions followed in the file. Include the SONAR-netCDF4 convention and version (e.g. ”SONAR-netCDF4-1.1”) and the relevant CF and ACDD conventions (e.g. ”CF-1.7” and ”ACDD-1.3”).",
"value": "CF-1.7, SONAR-netCDF4-1.1, ACDD-1.3"
},
{
"name": "date_created",
"obligation": "M",
"comment": "Timestamp of file creation in ISO8601:2004 extended format, including the time zone (e.g. 2017-05-06T20:21:35Z)."
},
{
"name": "keywords",
"obligation": "M",
"comment": "A comma-separated list of key words and/or phrases. For direct sonar-generated files, this should at least include the type of sonar."
},
{
"name": "license",
"obligation": "O",
"comment": "Either enter the URL to a standard or specific license, enter “Freely distributed” or “None”, or describe any restrictions to data access and distribution in free text."
},
{
"name": "rights",
"obligation": "O",
"comment": "Description of the usage rights of data in the file."
},
{
"name": "sonar_convention_authority",
"obligation": "M",
"comment": "Name of the organization managing and distributing the SONAR-netCDF4 convention. Currently ICES.",
"value": "ICES"
},
{
"name": "sonar_convention_name",
"obligation": "M",
"comment": "Formal name of this convention (i.e. ”SONAR-netCDF4”).",
"value": "SONAR-netCDF4"
},
{
"name": "sonar_convention_version",
"obligation": "M",
"comment": "SONAR-netCDF4 version number in the form “major.minor”, where major and minor are non-negative integers.",
"value": "1.1"
},
{
"name": "summary",
"obligation": "M",
"comment": "A paragraph describing the dataset, analogous to an abstract for a paper. For direct sonar-generated files, this can be blank."
},
{
"name": "title",
"obligation": "M",
"comment": "A short phrase or sentence describing the dataset. For direct sonar-generated files, this can be as simple as \"Files generated by the XYZ sonar\"."
},
{
"name": "xsf_convention_version",
"obligation": "M",
"comment": "version number in the form “major.minor”, where major and minor are non-negative integers.",
"value": "0.1",
"type": "string"
}
],
"variables": [
{
"name": "crs",
"obligation": "O",
"comment": " A container variable storing information about the grid_mapping. All the attributes within a grid_mapping variable are described in http://cfconventions.org/Data/cf-conventions/cf-conventions-1.6/build/cf-conventions.html#grid-mappings-and-projections. For all the measurements based on WSG84, the default coordinate system used for GPS measurements, the values shown here should be used.",
"dims": [],
"type": "double",
"attributes": [
{
"name": "grid_mapping_name",
"value": "latitude_longitude"
},
{
"name": "epsg_code",
"value": "EPSG:4326"
},
{
"name": "semi_major_axis",
"value": "6378137.0d",
"type": "double"
},
{
"name": "inverse_flattening ",
"value": "298.257223563d",
"type": "double"
},
{
"name": "_FillValue",
"value": "Double.NaN",
"type": "double"
}
]
}
],
"coordinatevariables": [],
"subGroups": []
}
\ No newline at end of file
This diff is collapsed.
......@@ -2,9 +2,14 @@ package fr.ifremer.fr.xsf.generator;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.Writer;
import java.nio.file.Paths;
import java.util.Arrays;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.DefaultParser;
......@@ -26,7 +31,7 @@ import fr.ifremer.fr.xsf.generator.model.Variable;
public class CodeGenerator {
static File outputDir=new File("C:\\dev\\xsf_generator_output");
static File outputDir=new File("D:\\tmp\\XSFGenerator");
private static final String OUTPUT_DIR_OPTION="out";
private static final String MODEL_FILE_OPTION="model";
......@@ -42,40 +47,66 @@ public class CodeGenerator {
}
public static void main( String[] args ) throws Exception
{
System.out.println("Starting");
// Parse file
try{
CommandLine commandLine = new DefaultParser().parse(createCommandLineOptions(), args);
if (commandLine.hasOption(HELP_OPTION)) { // Display help if asked
CommandLine commandLine = new DefaultParser().parse(createCommandLineOptions(), args);
if (commandLine.hasOption(HELP_OPTION)) { // Display help if asked
displayHelp();
return;
} else {
outputDir=new File(commandLine.getOptionValue(OUTPUT_DIR_OPTION));
if(!outputDir.isDirectory())
{
System.err.println(String.format("Error %s is not a directory or does not exist",outputDir.toString()));
displayHelp();
return;
} else {
outputDir=new File(commandLine.getOptionValue(OUTPUT_DIR_OPTION));
if(!outputDir.isDirectory())
{
System.err.println(String.format("Error %s is not a directory or does not exist",outputDir.toString()));
displayHelp();
return;
}
}
}
} catch(Exception e)
}
System.out.println("Starting into directory " + outputDir.getAbsolutePath() );
{
// System.err.println(String.format("Error while parsing command line ",e.getMessage()));
// displayHelp();
// return;
}
String ModelFile="./XSFModel.json";
try (Reader reader=new InputStreamReader(new FileInputStream(ModelFile))){
Gson gson=getGson();
Group root=gson.fromJson(reader, Group.class);
// new ExcelGenerator().run(root,Paths.get(outputDir.getAbsolutePath(), "XSF_model.xlsx").toFile());
Group root=readJson("./Root.json");
Group environment=readJson("./Environment.json");
Group platform=readJson("./Platform.json");
Group provenance=readJson("./Provenance.json");
Group sonar=readJson("./Sonar.json");
root.getSubGroups().addAll(Arrays.asList(environment,platform,provenance,sonar));
new AsciiDoctorGenerator().run(root, Paths.get(outputDir.getAbsolutePath()).toFile());
new JavaSourceCodeGenerator().run(root, Paths.get(outputDir.getAbsolutePath(), "code").toFile());
new PythonSourceCodeGenerator().run(root, Paths.get(outputDir.getAbsolutePath(), "code").toFile());
}
System.out.println("Done");
System.out.println("Done ");
}
public static Group readJson(String file_name) throws FileNotFoundException, IOException
{
try (Reader reader=new InputStreamReader(new FileInputStream(file_name))){
Gson gson=getGson();
Group root=gson.fromJson(reader, Group.class);
return root;
}
}
/***
* Temporary Code in order to split JSon File
* @throws IOException
*
**/
public static void splitJson(Group root) throws IOException
{
for(Group g:root.getSubGroups())
{
Gson gson=getGson();
Writer writer = new FileWriter(g.getName()+".json");
gson.toJson(g, writer);
writer.close();
}
root.getSubGroups().clear();
Gson gson=getGson();
Writer writer = new FileWriter("Root.json");
gson.toJson(root, writer);
writer.close();
}
/** Display help. */
public static void displayHelp() {
......
......@@ -13,6 +13,8 @@ public class GGroupAdapter implements JsonSerializer<Group> {
public JsonElement serialize(Group value, Type type, JsonSerializationContext context) {
JsonObject object = new JsonObject();
GBaseAdapter.serialize(object, value, context);
if(value.groupCategory!=null)
object.add("groupCategory", context.serialize(value.groupCategory));
object.add("dims", context.serialize(value.dims));
object.add("types", context.serialize(value.types));
object.add("attributes", context.serialize(value.attributes));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment