1
|
package eu.dnetlib.grid.process;
|
2
|
|
3
|
import java.util.List;
|
4
|
import java.util.Map;
|
5
|
import java.util.Objects;
|
6
|
import java.util.stream.Collectors;
|
7
|
|
8
|
import org.springframework.boot.CommandLineRunner;
|
9
|
import org.springframework.boot.SpringApplication;
|
10
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
11
|
|
12
|
import com.googlecode.protobuf.format.JsonFormat;
|
13
|
|
14
|
import eu.dnetlib.grid.process.model.GridOrganization;
|
15
|
import eu.dnetlib.grid.process.utils.Datasource;
|
16
|
import eu.dnetlib.grid.process.utils.GridCleaner;
|
17
|
import eu.dnetlib.grid.process.utils.GridUtils;
|
18
|
|
19
|
@SpringBootApplication
|
20
|
public class GridOrganizationsApplication implements CommandLineRunner {
|
21
|
|
22
|
private static final Datasource gridDs = new Datasource("openaire____::grid", "GRID - Global Research Identifier Database", "grid________");
|
23
|
|
24
|
public static void main(final String[] args) {
|
25
|
SpringApplication.run(GridOrganizationsApplication.class, args);
|
26
|
}
|
27
|
|
28
|
@Override
|
29
|
public void run(final String... args) throws Exception {
|
30
|
if (args.length == 1) {
|
31
|
processFile(args[0]);
|
32
|
} else {
|
33
|
System.err.println();
|
34
|
System.err.println("Usage: java -jar <JARFILE> <GridJsonFile>");
|
35
|
System.err.println();
|
36
|
}
|
37
|
}
|
38
|
|
39
|
protected void processFile(final String jsonFile) throws Exception {
|
40
|
final GridCleaner cleaner = new GridCleaner();
|
41
|
|
42
|
final Map<String, String> parents = GridUtils.streamOrganizations(jsonFile)
|
43
|
.filter(Objects::nonNull)
|
44
|
.filter(o -> o.getStatus().equals("active"))
|
45
|
.collect(Collectors.toMap(GridOrganization::getId, GridUtils::findShortName));
|
46
|
|
47
|
final JsonFormat jsonFormat = new JsonFormat();
|
48
|
|
49
|
GridUtils.streamOrganizations(jsonFile)
|
50
|
.filter(Objects::nonNull)
|
51
|
.filter(o -> o.getStatus().equals("active"))
|
52
|
.map(cleaner)
|
53
|
.map(org -> GridUtils.toProtos(org, parents, gridDs))
|
54
|
.flatMap(List::stream)
|
55
|
.map(jsonFormat::printToString)
|
56
|
.forEach(System.out::println);
|
57
|
|
58
|
}
|
59
|
|
60
|
}
|