SQLDISTINCT

This commit is contained in:
Michele Artini 2024-02-20 08:32:11 +01:00
parent e5a9ee0b21
commit 383fc49908
2 changed files with 11 additions and 9 deletions

View File

@ -42,6 +42,8 @@ public class FunderService {
@Autowired
private MongoLoggerClient mongoLoggerClient;
private File tempDir;
private File tempFile;
private final DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@ -50,7 +52,10 @@ public class FunderService {
@PostConstruct
public void init() {
for (final File f : new File("/tmp").listFiles((FilenameFilter) (dir, name) -> name.endsWith(TEMP_FILE_SUFFIX))) {
tempDir = new File(System.getProperty("java.io.tmpdir", "/tmp"));
for (final File f : tempDir.listFiles((FilenameFilter) (dir, name) -> name.endsWith(TEMP_FILE_SUFFIX))) {
deleteFile(f);
}
@ -71,7 +76,7 @@ public class FunderService {
mapper.registerModule(new JavaTimeModule());
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
final File tmp = File.createTempFile("funders-api-", TEMP_FILE_SUFFIX, new File("/tmp"));
final File tmp = File.createTempFile("funders-api-", TEMP_FILE_SUFFIX, tempDir);
log.info("Generating funders file: " + tmp.getAbsolutePath());
@ -80,7 +85,7 @@ public class FunderService {
boolean first = true;
for (final FunderDbEntry funder : funderRepository.findAll()) {
log.info(" - adding: " + funder.getId());
// addAggregationHistory(funder);
addAggregationHistory(funder);
if (first) {
first = false;
@ -123,6 +128,7 @@ public class FunderService {
.distinct()
.map(s -> LocalDate.parse(s, DATEFORMATTER))
.sorted(Comparator.reverseOrder())
.limit(10)
.collect(Collectors.toList());
funder.setAggregationDates(dates);

View File

@ -1,9 +1,5 @@
ALTER TABLE dsm_organizations ADD COLUMN registered_funder boolean;
-- TODO OCCORRE METTERE DELLE DISTINCT
CREATE VIEW funders_view AS SELECT
o.id AS id,
o.legalshortname AS legalshortname,
@ -13,8 +9,8 @@ CREATE VIEW funders_view AS SELECT
o.country AS country,
o.dateofcollection AS registrationdate,
o.registered_funder AS registered,
CASE WHEN count(s.id) = 0 THEN '[]'::jsonb ELSE jsonb_agg(jsonb_build_object('id', s.id,'name', s.officialname,'type',s.eosc_datasource_type)) END AS datasources,
CASE WHEN count(pids.pid) = 0 THEN '[]'::jsonb ELSE jsonb_agg(jsonb_build_object('type', pids.issuertype,'value', pids.pid)) END AS pids
CASE WHEN count(s.id) = 0 THEN '[]'::jsonb ELSE jsonb_agg(DISTINCT jsonb_build_object('id', s.id,'name', s.officialname,'type',s.eosc_datasource_type)) END AS datasources,
CASE WHEN count(pids.pid) = 0 THEN '[]'::jsonb ELSE jsonb_agg(DISTINCT jsonb_build_object('type', pids.issuertype,'value', pids.pid)) END AS pids
FROM
dsm_organizations o
JOIN dsm_service_organization so ON (o.id = so.organization)