Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
snf2ye committed Aug 11, 2023
1 parent 347fc42 commit 55dde04
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 35 deletions.
4 changes: 4 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ apply from: "publishing.gradle"

srcclr {
scope = "runtimeClasspath"
}

sourcesJar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
4 changes: 0 additions & 4 deletions library/src/main/avro/sample.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,4 @@ protocol SimplePFB {
union{Metadata,string} object;
union{null,array<Relation>} relations;
}

record PFB {
array<Entity> entities;
}
}
37 changes: 6 additions & 31 deletions library/src/main/java/bio/terra/pfb/PfbReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
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;
import org.apache.avro.Schema;
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 {
Expand All @@ -36,21 +32,16 @@ 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 {
Metadata metadata = deserializeAvroFile(fileLocation);
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) {
Expand Down Expand Up @@ -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<Entity> 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<Entity> datumReader = new SpecificDatumReader<>(Entity.class);
Expand All @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions library/src/test/java/bio/terra/pfb/PfbReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 55dde04

Please sign in to comment.