Skip to content

Commit

Permalink
Merge branch 'dev' into 30948_ANTLR4_filter_grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
cgendreau committed Mar 12, 2024
2 parents a68f6de + d208b6d commit 2e211a3
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 11 deletions.
16 changes: 13 additions & 3 deletions dina-base-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-base-parent</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
</parent>

<artifactId>dina-base-api</artifactId>
Expand All @@ -27,9 +27,14 @@
<mybatis.version>2.2.2</mybatis.version>
<aafc.search.messaging.version>0.29</aafc.search.messaging.version>
<hypersistence-utils-hibernate-55.version>3.6.1</hypersistence-utils-hibernate-55.version>
<postgresql.version>42.4.3</postgresql.version>

<jsoup.version>1.15.3</jsoup.version>
<commons-io.version>2.15.1</commons-io.version>
<java-uuid-generator.version>4.3.0</java-uuid-generator.version>

<!-- Versions override-->
<postgresql.version>42.4.4</postgresql.version>

</properties>

<dependencies>
Expand Down Expand Up @@ -148,7 +153,7 @@
<dependency>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-test-support</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -167,6 +172,11 @@
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.uuid</groupId>
<artifactId>java-uuid-generator</artifactId>
<version>${java-uuid-generator.version}</version>
</dependency>

<!-- Spring mybatis -->
<dependency>
Expand Down
39 changes: 39 additions & 0 deletions dina-base-api/src/main/java/ca/gc/aafc/dina/util/UUIDHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package ca.gc.aafc.dina.util;

import java.util.UUID;

import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.TimeBasedEpochGenerator;

/**
* Helper class to handle UUID version 7.
*/
public final class UUIDHelper {

private static final TimeBasedEpochGenerator GENERATOR = Generators.timeBasedEpochGenerator();

private UUIDHelper() {
// utility class
}

/**
* thread-safe per TimeBasedEpochGenerator implementation.
* @return
*/
public static UUID generateUUIDv7() {
return GENERATOR.generate();
}

/**
* Checks if the provided UUID is of version 7.
* @param uuid
* @return is provided UUID version 7. If uuid is null false is returned.
*/
public static boolean isUUIDv7(UUID uuid) {
if(uuid == null) {
return false;
}
return uuid.version() == 7;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ca.gc.aafc.dina.util;

import java.util.UUID;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class UUIDHelperTest {

@Test
public void testUUIDHelper() {
UUID uuidv7 = UUIDHelper.generateUUIDv7();

assertTrue(UUIDHelper.isUUIDv7(uuidv7));
assertFalse(UUIDHelper.isUUIDv7(UUID.randomUUID()));
}
}
2 changes: 1 addition & 1 deletion dina-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-base-parent</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
</parent>

<artifactId>dina-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion dina-filter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-base-parent</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
</parent>

<artifactId>dina-filter</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions dina-messaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-base-parent</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
</parent>

<artifactId>dina-messaging</artifactId>
Expand Down Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-test-support</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
<scope>test</scope>
</dependency>

Expand Down
2 changes: 1 addition & 1 deletion dina-search/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-base-parent</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
</parent>

<artifactId>dina-search</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion dina-test-support/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-base-parent</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
</parent>

<artifactId>dina-test-support</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion dina-workbook/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-base-parent</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>
</parent>

<artifactId>dina-workbook</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ca.gc.aafc.dina.workbook;

import java.util.List;

import org.apache.poi.ooxml.POIXMLProperties;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
* Utility to generates Workbook.
*
*/
public final class WorkbookGenerator {

private WorkbookGenerator() {
//utility class
}

/**
* Generate a workbook from a list of column names.
* Use in a try-with-resource.
*
* @param columns columns name
* @return the Workbook object
*/
public static Workbook generate(List<String> columns) {
XSSFWorkbook wb = new XSSFWorkbook();
Sheet sheet1 = wb.createSheet();

// Record in custom properties the original columns
POIXMLProperties.CustomProperties customProp = wb.getProperties().getCustomProperties();
customProp.addProperty("originalColumns", String.join(",", columns));

// Rows are 0 based
Row row = sheet1.createRow(0);

int cellIdx = 0;
for(String columnName: columns) {
row.createCell(cellIdx).setCellValue(columnName);
cellIdx++;
}

return wb;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ca.gc.aafc.dina.workbook;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

import org.apache.poi.ss.usermodel.Workbook;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class WorkbookGeneratorIT {

@Test
public void generate_withColumnName_workbookGenerated() throws IOException {
Path tmpExport = Files.createTempDirectory("generate_withColumnName_workbookGenerated")
.resolve("generatedFile.xlsx");
try (Workbook wb = WorkbookGenerator.generate(List.of("col 1", "col 2"))) {
wb.write(new FileOutputStream(tmpExport.toFile()));
}

try(FileInputStream fis = new FileInputStream(tmpExport.toFile())) {
var result = WorkbookConverter.convertWorkbook(fis);
// check value of the first cell of the first row of the first sheet
assertEquals("col 1", result.get(0).get(0).content()[0]);
}
}
}
4 changes: 4 additions & 0 deletions owasp-suppression.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<notes>no untrusted source</notes>
<cve>CVE-2022-1471</cve>
</suppress>
<suppress>
<notes>no UriComponentsBuilder</notes>
<cve>CVE-2024-22243</cve>
</suppress>
<suppress>
<notes>CVE about Keycloak server</notes>
<cve>CVE-2022-1245</cve>
Expand Down
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.aafc-bicoe</groupId>
<artifactId>dina-base-parent</artifactId>
<version>0.118-SNAPSHOT</version>
<version>0.119-SNAPSHOT</version>

<packaging>pom</packaging>

Expand Down Expand Up @@ -51,6 +51,9 @@
<!-- Common sub-module dependency properties -->
<javax.inject.version>1</javax.inject.version>
<keycloak-starter.version>20.0.5</keycloak-starter.version>

<!-- Versions override-->
<org.springframework.version>5.3.32</org.springframework.version>
<snakeyaml.version>1.33</snakeyaml.version>
<antlr4.version>4.13.0</antlr4.version>

Expand Down

0 comments on commit 2e211a3

Please sign in to comment.