diff --git a/library/build.gradle b/library/build.gradle index 88bab706..c3d8f8f9 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -44,4 +44,8 @@ apply from: "publishing.gradle" srcclr { scope = "runtimeClasspath" +} + +sourcesJar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE } \ No newline at end of file diff --git a/library/src/main/avro/sample.avdl b/library/src/main/avro/sample.avdl index c27ebdca..31e89c98 100644 --- a/library/src/main/avro/sample.avdl +++ b/library/src/main/avro/sample.avdl @@ -74,8 +74,4 @@ protocol SimplePFB { union{Metadata,string} object; union{null,array} relations; } - - record PFB { - array entities; - } } diff --git a/library/src/main/java/bio/terra/pfb/PfbReader.java b/library/src/main/java/bio/terra/pfb/PfbReader.java index 0cbf0b27..2e75c338 100644 --- a/library/src/main/java/bio/terra/pfb/PfbReader.java +++ b/library/src/main/java/bio/terra/pfb/PfbReader.java @@ -4,7 +4,6 @@ import java.io.*; import java.net.URL; import java.net.URLConnection; -import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; @@ -12,9 +11,6 @@ import org.apache.avro.file.DataFileReader; import org.apache.avro.file.DataFileStream; import org.apache.avro.io.DatumReader; -import org.apache.avro.io.Decoder; -import org.apache.avro.io.DecoderFactory; -import org.apache.avro.specific.SpecificData; import org.apache.avro.specific.SpecificDatumReader; public class PfbReader { @@ -36,11 +32,9 @@ public String showNodes(String fileLocation) throws IOException { } public String show(String fileLocation) throws IOException { - // "object" is ia union between metadata and demographic. So, it's possible this parsing will - // fail - // I think the generated files are not handling this quite right. - SpecificData data = deserializeAvroFile(fileLocation).getSpecificData(); - return data.toString(); + // TODO - figure out how to read the rest of the Entity objects into a list of single json + // objects + return "NOT IMPLEMENTED"; } public String showMetadata(String fileLocation) throws IOException { @@ -48,9 +42,6 @@ public String showMetadata(String fileLocation) throws IOException { return metadata.toString(); } - // List particular enum symbols - // schema.getField("object").schema().getTypes().get(3).getFields().get(1).schema().getTypes().stream().filter(s -> s.getType().equals(Schema.Type.ENUM)).findFirst().get().getEnumSymbols() - public Schema getSchema(String fileLocation) throws IOException { boolean isUrl = isValidUrl(fileLocation); if (isUrl) { @@ -93,25 +84,6 @@ public Metadata deserializeAvroFile(String fileLocation) throws IOException { throw new InvalidPfbException("No metadata object found in PFB file"); } - Entity decodeStream(String fileLocation) throws FileNotFoundException { - Entity result = null; - Decoder decoder = null; - DatumReader datumReader = new SpecificDatumReader<>(Entity.class); - try { - File initialFile = new File(fileLocation); - InputStream inputStream = new FileInputStream(initialFile); - String text = - new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)) - .lines() - .collect(Collectors.joining("\n")); - decoder = DecoderFactory.get().jsonDecoder(Entity.getClassSchema(), text); - return datumReader.read(null, decoder); - } catch (IOException e) { - System.err.println("Deserialization error:" + e.getMessage()); - } - return result; - } - Schema readUrlPFBSchema(String signedUrl) throws IOException { Schema schema; DatumReader datumReader = new SpecificDatumReader<>(Entity.class); @@ -126,6 +98,9 @@ Schema readUrlPFBSchema(String signedUrl) throws IOException { // Helper methods + // List particular enum symbols + // schema.getField("object").schema().getTypes().get(3).getFields().get(1).schema().getTypes().stream().filter(s -> s.getType().equals(Schema.Type.ENUM)).findFirst().get().getEnumSymbols() + boolean isValidUrl(String fileLocation) { try { new URL(fileLocation); diff --git a/library/src/test/java/bio/terra/pfb/PfbReaderTest.java b/library/src/test/java/bio/terra/pfb/PfbReaderTest.java index 5c66e167..6a6e57d1 100644 --- a/library/src/test/java/bio/terra/pfb/PfbReaderTest.java +++ b/library/src/test/java/bio/terra/pfb/PfbReaderTest.java @@ -35,6 +35,16 @@ void showMetadata() throws IOException { } } + // TODO: Show is not yet working + // @Test + // void showTest() throws IOException { + // var listOfTestFiles = List.of("minimal_data"); + // for (String fileName : listOfTestFiles) { + // CompareOutputUtils.compareJsonOutputWithPyPFB( + // fileName, CompareOutputUtils.PfbCommandType.show, ""); + // } + // } + @Disabled("Disabled because we don't have a way to generate a signed URL for testing") @Test void testSignedURL() throws IOException {