fixed a bug with gzipped files

This commit is contained in:
Michele Artini 2021-01-15 10:50:53 +01:00
parent 488f0c5f62
commit bdcf79bfc3
2 changed files with 28 additions and 12 deletions

View File

@ -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<Subscription> listSubscriptionsByUser(@RequestParam final String email) {

View File

@ -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
# Includere la url nell'idice fulltetxt
# verificare acronimo UNIBO