Skip to content

Commit 48810c1

Browse files
committed
'xlsx' output foemat
2 parents 907fbbc + e7aefb2 commit 48810c1

File tree

7 files changed

+90
-17
lines changed

7 files changed

+90
-17
lines changed

.github/workflows/build_maven_package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
# SonarCloud access token should be generated from https://sonarcloud.io/account/security/
6464
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
6565
- name: Build and analyze
66-
run: mvn -B clean install org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -P coverage,full,metadata,sonarfugerit -DgithubParam1=%TEST_GITHUB_USER% -DgithubParam2=%TEST_GITHUB_PASS%
66+
run: mvn -B clean install org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -P coverage,full,metadata,sonarfugerit
6767
env:
6868
# Needed to get some information about the pull request, if any
6969
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- 'xlsx' output foemat (simple specify xlsx extension for file path)
13+
1014
## [1.0.0] - 2024-02-19
1115

1216
### Changed

src/main/java/org/fugerit/java/github/issue/export/GithubIssueExport.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.poi.ss.usermodel.CellStyle;
2525
import org.apache.poi.ss.usermodel.Sheet;
2626
import org.apache.poi.ss.usermodel.Workbook;
27+
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
2728
import org.fugerit.java.core.cfg.ConfigException;
2829
import org.fugerit.java.core.cli.ArgUtils;
2930
import org.fugerit.java.core.function.SafeFunction;
@@ -327,20 +328,20 @@ public static Object buildModel( String data, Class c ) throws JsonProcessingExc
327328
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
328329
return objectMapper.readValue( data , c );
329330
}
330-
331-
public static String getValue( Object val ) {
332-
String res = null;
333-
if ( val != null ) {
334-
res = String.valueOf( val );
331+
332+
private static Workbook createReport( String fileName ) {
333+
if ( fileName.toLowerCase().endsWith( "xlsx" ) ) {
334+
return new XSSFWorkbook();
335+
} else {
336+
return new HSSFWorkbook();
335337
}
336-
return res;
337338
}
338-
339+
339340
private static void handleExcel( GithubIssueInfo info, List<List<String>> lines ) {
340341
SafeFunction.apply( () -> {
341342
String xlsFile = info.getProperty( ARG_XLSFILE );
342343
try ( FileOutputStream fos = new FileOutputStream( new File( xlsFile ) );
343-
Workbook workbook = new HSSFWorkbook() ) {
344+
Workbook workbook = createReport( xlsFile ) ) {
344345
Sheet sheet = workbook.createSheet( "Report github issue" );
345346
CellStyle headerStyle = PoiHelper.getHeaderStyle( workbook );
346347
String lang = info.getProperty( ARG_LANG );

src/main/java/org/fugerit/java/github/issue/export/helper/PoiHelper.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public class PoiHelper {
2020

2121
private PoiHelper() {}
2222

23+
/*
24+
* https://support.microsoft.com/en-gb/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3
25+
*/
26+
public static final int MAX_XLS_CELL_LENGTH = 32767;
27+
2328
/*
2429
* Use with caution, bad performance
2530
*/
@@ -41,18 +46,20 @@ public static CellStyle getHeaderStyle( Workbook workbook ) {
4146
return style;
4247
}
4348

49+
public static String prepareCell( String currentCell ) {
50+
if ( "null".equalsIgnoreCase( currentCell ) ) {
51+
currentCell = "";
52+
} else if ( currentCell.length() > MAX_XLS_CELL_LENGTH ) {
53+
currentCell = currentCell.substring( 0, 32000 )+"[...]";
54+
}
55+
return currentCell;
56+
}
57+
4458
public static void addRow( String[] values, int index, Sheet sheet, CellStyle style) {
4559
Row row = sheet.createRow( index );
4660
for ( int k=0; k<values.length; k++ ) {
4761
Cell cell = row.createCell( k );
48-
String currentCell = values[k];
49-
if ( currentCell.length() > 32767 ) {
50-
currentCell = currentCell.substring( 0, 32000 )+" [...]";
51-
}
52-
if ( currentCell == null || "null".equalsIgnoreCase( currentCell ) ) {
53-
currentCell = "";
54-
}
55-
cell.setCellValue( currentCell );
62+
cell.setCellValue( prepareCell( values[k] ) );
5663
if ( style != null ) {
5764
cell.setCellStyle( style );
5865
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package test.org.fugerit.java.github.issue.export;
2+
3+
import java.sql.Date;
4+
import java.text.ParseException;
5+
import java.util.Locale;
6+
7+
import org.fugerit.java.github.issue.export.helper.FormatHelper;
8+
import org.junit.Assert;
9+
import org.junit.Test;
10+
11+
public class TestFormatHelper {
12+
13+
@Test
14+
public void testDate() throws ParseException {
15+
String checkDate = "2024-01-01";
16+
String checkDateRes = "01/01/2024 00:00";
17+
String fd = FormatHelper.formatDate( Date.valueOf( checkDate ) , Locale.ENGLISH.getLanguage() );
18+
Assert.assertEquals( checkDateRes , fd);
19+
}
20+
21+
}

src/test/java/test/org/fugerit/java/github/issue/export/TestGithubIssueExportMain.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ public void testCommandLineAlt() {
6161
GithubIssueExportMain.main(args);
6262
Assert.assertTrue( outputFile.exists() );
6363
}
64+
65+
@Test
66+
public void testCommandLineAltXlsx() {
67+
File outputFile = new File( "target", "report.xlsx" );
68+
List<String> params = new ArrayList<>(
69+
Arrays.asList( ArgUtils.getArgString( GithubIssueExportMain.ARG_GUI ), BooleanUtils.BOOLEAN_FALSE,
70+
ArgUtils.getArgString( GithubIssueExport.ARG_OWNER ), "fugerit-org",
71+
ArgUtils.getArgString( GithubIssueExport.ARG_REPO ), "github-issue-export",
72+
ArgUtils.getArgString( GithubIssueExport.ARG_XLSFILE ), outputFile.getAbsolutePath(),
73+
ArgUtils.getArgString( GithubIssueExportMain.ARG_COPY_RES ), "target" )
74+
);
75+
this.checkUser(params);
76+
String[] args = params.toArray( new String[0] );
77+
GithubIssueExportMain.main(args);
78+
Assert.assertTrue( outputFile.exists() );
79+
}
6480

6581
@Test
6682
public void testHel() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package test.org.fugerit.java.github.issue.export;
2+
3+
import org.fugerit.java.github.issue.export.helper.PoiHelper;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
public class TestPoiHelper {
8+
9+
private static final String PAD = "ABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGHABCDEFGH ";
10+
11+
@Test
12+
public void testPrepareCell() {
13+
StringBuffer buffer = new StringBuffer();
14+
int length = 0;
15+
while ( length < PoiHelper.MAX_XLS_CELL_LENGTH ) {
16+
buffer.append( PAD );
17+
length+= PAD.length();
18+
}
19+
String currentCell = PoiHelper.prepareCell( buffer.toString() );
20+
Assert.assertTrue( currentCell.indexOf( "[...]" ) > 0 );
21+
Assert.assertEquals( "" , PoiHelper.prepareCell( "null" ) );
22+
}
23+
24+
}

0 commit comments

Comments
 (0)