Skip to content

Commit

Permalink
Added db migration
Browse files Browse the repository at this point in the history
  • Loading branch information
cgendreau committed Nov 18, 2024
1 parent 6e066f1 commit 42ad21e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ POST /data-export
}
----

Optionally, some functions can be used on columns to create new calculated columns that can then be added to the `columns`.

[source, json]
----
{
"columnFunctions":{"latLong":{"type":"CONVERT_COORDINATES_DD","params":["collectingEvent.eventGeom"]}}
}
----


== Download File

For data exports, the `fileId` is the UUID returned by the export request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public enum FunctionType { CONCAT, CONVERT_COORDINATES_DD }
@Column
private String[] columnAliases;

@Transient
@Type(type = "jsonb")
@Column
private Map<String, FunctionDef> columnFunctions;

@Enumerated(EnumType.STRING)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<include file="db/changelog/migrations/5-Add_name_to_export_table.xml"/>
<include file="db/changelog/migrations/6-Add_type_variables_to_report_template_table.xml"/>
<include file="db/changelog/migrations/7-Add_column_aliases_to_data_export_table.xml"/>
<include file="db/changelog/migrations/8-Add_column_functions_to_data_export_table.xml"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.1" encoding="UTF-8" standalone="no" ?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://local.xsd/dbchangelog-4.4.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">

<changeSet id="8-Add_column_functions_to_data_export_table" context="schema-change" author="cgendreau">
<addColumn tableName="data_export">
<column name="column_functions" type="jsonb"/>
</addColumn>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import ca.gc.aafc.dina.export.api.file.FileController;
import ca.gc.aafc.dina.export.api.testsupport.jsonapi.JsonApiDocuments;
import ca.gc.aafc.dina.testsupport.elasticsearch.ElasticSearchTestUtils;
import ca.gc.aafc.dina.testsupport.jsonapi.JsonAPITestHelper;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand All @@ -32,6 +33,12 @@
import java.util.concurrent.Future;
import javax.inject.Inject;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

@ContextConfiguration(initializers = { ElasticSearchTestContainerInitializer.class })
public class DataExportRepositoryIT extends BaseIntegrationTest {

Expand Down Expand Up @@ -90,6 +97,15 @@ public void testESDatasource() throws IOException {
assertEquals(DataExport.ExportType.TABULAR_DATA, savedDataExportDto.getExportType());
assertEquals("my export", savedDataExportDto.getName());


ObjectMapper IT_OBJECT_MAPPER = new ObjectMapper();

IT_OBJECT_MAPPER.registerModule(new JavaTimeModule());
IT_OBJECT_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
IT_OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);

System.out.println(IT_OBJECT_MAPPER.writeValueAsString(savedDataExportDto));

ResponseEntity<InputStreamResource>
response = fileController.downloadFile(dto.getUuid(), FileController.DownloadType.DATA_EXPORT);

Expand Down Expand Up @@ -117,6 +133,9 @@ public void testESDatasource() throws IOException {
// check that to-many relationships are exported in a similar way of arrays
assertTrue(lines.get(1).contains("project 1;project 2"));

// check that the function is working as expected
assertTrue(lines.get(1).contains("45.424721,-75.695000"));

// delete the export
dataExportRepository.delete(dto.getUuid());
assertThrows(
Expand Down

0 comments on commit 42ad21e

Please sign in to comment.