From bdcf79bfc3dc0cf19deb424724719861aa3aea7f Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Fri, 15 Jan 2021 10:50:53 +0100 Subject: [PATCH] fixed a bug with gzipped files --- .../controllers/OpenairePublicController.java | 37 +++++++++++++------ apps/dnet-orgs-database-application/TODO.txt | 3 +- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/apps/dhp-broker-public-application/src/main/java/eu/dnetlib/broker/oa/controllers/OpenairePublicController.java b/apps/dhp-broker-public-application/src/main/java/eu/dnetlib/broker/oa/controllers/OpenairePublicController.java index 4034f714..96e4437b 100644 --- a/apps/dhp-broker-public-application/src/main/java/eu/dnetlib/broker/oa/controllers/OpenairePublicController.java +++ b/apps/dhp-broker-public-application/src/main/java/eu/dnetlib/broker/oa/controllers/OpenairePublicController.java @@ -2,6 +2,7 @@ package eu.dnetlib.broker.oa.controllers; import java.io.BufferedReader; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; @@ -11,6 +12,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import javax.servlet.ServletOutputStream; @@ -208,18 +210,15 @@ public class OpenairePublicController extends AbstractLbsController { final InputStreamReader isr = new InputStreamReader(fis); final BufferedReader br = new BufferedReader(isr)) { - String line = br.readLine(); - while (line != null) { - if (first) { - first = false; - } else { - IOUtils.write(",\n", gzOut); - } + first = processLine(gzOut, first, br); + } + } else if (path.getName().endsWith(".json.gz")) { + try (final FSDataInputStream fis = fs.open(path); + final GZIPInputStream gzIn = new GZIPInputStream(fis); + final InputStreamReader isr = new InputStreamReader(gzIn); + final BufferedReader br = new BufferedReader(isr)) { - IOUtils.write(line, gzOut); - - line = br.readLine(); - } + first = processLine(gzOut, first, br); } } } @@ -235,6 +234,22 @@ public class OpenairePublicController extends AbstractLbsController { } } + private boolean processLine(final GZIPOutputStream gzOut, boolean first, final BufferedReader br) throws IOException { + String line = br.readLine(); + while (line != null) { + if (first) { + first = false; + } else { + IOUtils.write(",\n", gzOut); + } + + IOUtils.write(line, gzOut); + + line = br.readLine(); + } + return first; + } + @ApiOperation("Returns the list of subscriptions by user email") @GetMapping(value = "/subscriptions") private Iterable listSubscriptionsByUser(@RequestParam final String email) { diff --git a/apps/dnet-orgs-database-application/TODO.txt b/apps/dnet-orgs-database-application/TODO.txt index 2542f651..168b99e2 100644 --- a/apps/dnet-orgs-database-application/TODO.txt +++ b/apps/dnet-orgs-database-application/TODO.txt @@ -17,4 +17,5 @@ select o.name from organizations o left outer join tmp_fulltext f on (o.id = f.i # Togliere merges e merged_in dalla select per le creare le relazioni nel form di editing dei metadati # Nella risoluzione dei conflicts aggiungere i bottoni merge_all, all_different, merge_advanced # Nella risoluzione dei conflicts a partire dai singoli record redirigere la pagina sul nuovo record invece che sul record di partenza - \ No newline at end of file +# Includere la url nell'idice fulltetxt +# verificare acronimo UNIBO