SQLDISTINCT
This commit is contained in:
parent
e5a9ee0b21
commit
383fc49908
|
@ -42,6 +42,8 @@ public class FunderService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private MongoLoggerClient mongoLoggerClient;
|
private MongoLoggerClient mongoLoggerClient;
|
||||||
|
|
||||||
|
private File tempDir;
|
||||||
|
|
||||||
private File tempFile;
|
private File tempFile;
|
||||||
|
|
||||||
private final DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
private final DateTimeFormatter DATEFORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
@ -50,7 +52,10 @@ public class FunderService {
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
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);
|
deleteFile(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +76,7 @@ public class FunderService {
|
||||||
mapper.registerModule(new JavaTimeModule());
|
mapper.registerModule(new JavaTimeModule());
|
||||||
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
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());
|
log.info("Generating funders file: " + tmp.getAbsolutePath());
|
||||||
|
|
||||||
|
@ -80,7 +85,7 @@ public class FunderService {
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (final FunderDbEntry funder : funderRepository.findAll()) {
|
for (final FunderDbEntry funder : funderRepository.findAll()) {
|
||||||
log.info(" - adding: " + funder.getId());
|
log.info(" - adding: " + funder.getId());
|
||||||
// addAggregationHistory(funder);
|
addAggregationHistory(funder);
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
|
@ -123,6 +128,7 @@ public class FunderService {
|
||||||
.distinct()
|
.distinct()
|
||||||
.map(s -> LocalDate.parse(s, DATEFORMATTER))
|
.map(s -> LocalDate.parse(s, DATEFORMATTER))
|
||||||
.sorted(Comparator.reverseOrder())
|
.sorted(Comparator.reverseOrder())
|
||||||
|
.limit(10)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
funder.setAggregationDates(dates);
|
funder.setAggregationDates(dates);
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
ALTER TABLE dsm_organizations ADD COLUMN registered_funder boolean;
|
ALTER TABLE dsm_organizations ADD COLUMN registered_funder boolean;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- TODO OCCORRE METTERE DELLE DISTINCT
|
|
||||||
|
|
||||||
CREATE VIEW funders_view AS SELECT
|
CREATE VIEW funders_view AS SELECT
|
||||||
o.id AS id,
|
o.id AS id,
|
||||||
o.legalshortname AS legalshortname,
|
o.legalshortname AS legalshortname,
|
||||||
|
@ -13,8 +9,8 @@ CREATE VIEW funders_view AS SELECT
|
||||||
o.country AS country,
|
o.country AS country,
|
||||||
o.dateofcollection AS registrationdate,
|
o.dateofcollection AS registrationdate,
|
||||||
o.registered_funder AS registered,
|
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(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(jsonb_build_object('type', pids.issuertype,'value', pids.pid)) END AS pids
|
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
|
FROM
|
||||||
dsm_organizations o
|
dsm_organizations o
|
||||||
JOIN dsm_service_organization so ON (o.id = so.organization)
|
JOIN dsm_service_organization so ON (o.id = so.organization)
|
||||||
|
|
Loading…
Reference in New Issue