diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/PublicApiController.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/PublicApiController.java index 3adc8244..ba584f26 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/PublicApiController.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/controller/PublicApiController.java @@ -13,6 +13,7 @@ import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import eu.dnetlib.organizations.utils.DatabaseUtils; @@ -24,6 +25,22 @@ public class PublicApiController { @Autowired private DatabaseUtils dbUtils; + @GetMapping("/logs") + public void findJournalById(@RequestParam final String id, + final HttpServletResponse res) throws IOException { + + final String filename = String.format("%s.log", id.replaceAll(":", "_")); + + res.setContentType(MediaType.TEXT_PLAIN.getType()); + res.setHeader("Content-Disposition", "attachment; filename=" + filename); + + try (final ServletOutputStream out = res.getOutputStream()) { + for (final String s : dbUtils.obtainLogEntries(id)) { + IOUtils.write(s, out, StandardCharsets.UTF_8); + } + } + } + @GetMapping("/logs/{year}/{month}/{country}") public void findJournalByCountry(@PathVariable final int year, @PathVariable final int month, diff --git a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java index 31ace246..f95eac9c 100644 --- a/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java +++ b/apps/dnet-orgs-database-application/src/main/java/eu/dnetlib/organizations/utils/DatabaseUtils.java @@ -682,6 +682,17 @@ public class DatabaseUtils { persistentOrganizationRepository.deleteById(id); } + public List obtainLogEntries(final String id) { + final String query = "SELECT o.id, o.name, j.operation, j.description, date(j.op_date) as op_date " + + "FROM organizations o JOIN journal j ON o.id = j.id " + + "WHERE o.id=? " + + "ORDER BY date(j.op_date)"; + return jdbcTemplate.queryForList(query, id) + .stream() + .map(this::asLogEntry) + .collect(Collectors.toList()); + } + public List obtainLogEntries(final int year, final int month, final String country) { final String query = "SELECT o.id, o.name, j.operation, j.description, date(j.op_date) as op_date " + "FROM organizations o JOIN journal j ON o.id = j.id "