-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into 30948_ANTLR4_filter_grammar
- Loading branch information
Showing
13 changed files
with
164 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
dina-base-api/src/main/java/ca/gc/aafc/dina/util/UUIDHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
dina-base-api/src/test/java/ca/gc/aafc/dina/util/UUIDHelperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
dina-workbook/src/main/java/ca/gc/aafc/dina/workbook/WorkbookGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
dina-workbook/src/test/java/ca/gc/aafc/dina/workbook/WorkbookGeneratorIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters