Skip to content

Commit

Permalink
Merge pull request #310 from ozlerhakan/4.4.0
Browse files Browse the repository at this point in the history
Bump 4.4.0
  • Loading branch information
ozlerhakan committed Mar 3, 2024
2 parents 5facb7e + 00f2618 commit 0ee9a3f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
:toclevels: 2

= Poiji
:version: v4.3.0
:branch: 4.3.0
:version: v4.4.0
:branch: 4.4.0

image:https://github.com/ozlerhakan/poiji/actions/workflows/maven.yml/badge.svg["Build Status"] image:https://app.codacy.com/project/badge/Grade/64f7e2cb9e604807b62334a4cfc3952d["Codacy code quality",link="https://www.codacy.com/gh/ozlerhakan/poiji/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ozlerhakan/poiji&utm_campaign=Badge_Grade"]
image:https://codecov.io/gh/ozlerhakan/poiji/branch/{branch}/graph/badge.svg?token=MN6V6xOWBq["Codecov",link="https://codecov.io/gh/ozlerhakan/poiji"] image:https://img.shields.io/badge/apache.poi-5.2.3-brightgreen.svg[] image:https://app.fossa.com/api/projects/git%2Bgithub.com%2Fozlerhakan%2Fpoiji.svg?type=shield["FOSSA Status",link="https://app.fossa.com/projects/git%2Bgithub.com%2Fozlerhakan%2Fpoiji?ref=badge_shield"]
Expand All @@ -25,7 +25,7 @@ In your Maven/Gradle project, first add the corresponding dependency:
<dependency>
<groupId>com.github.ozlerhakan</groupId>
<artifactId>poiji</artifactId>
<version>4.3.0</version>
<version>4.4.0</version>
</dependency>
----

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.ozlerhakan</groupId>
<artifactId>poiji</artifactId>
<version>4.3.0</version>
<version>4.4.0</version>
<packaging>jar</packaging>

<name>poiji</name>
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/com/poiji/exception/HeaderMissingException.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
package com.poiji.exception;

import java.util.Set;

/**
* Exception thrown if namedHeaderMandatory is set in the options, but a header specified in an @ExcelCellName
* is missing in the sheet.
*/
@SuppressWarnings("serial")
public class HeaderMissingException extends PoijiException {
public HeaderMissingException(String message) {

private final Set<Integer> missingExcelCellHeaders;
private final Set<String> missingExcelCellNameHeaders;

public HeaderMissingException(String message, Set<Integer> missingExcelCellHeaders,
Set<String> missingExcelCellNameHeaders) {
super(message);
this.missingExcelCellHeaders = Set.copyOf(missingExcelCellHeaders);
this.missingExcelCellNameHeaders = Set.copyOf(missingExcelCellNameHeaders);
}

public Set<Integer> getMissingExcelCellHeaders() {
return missingExcelCellHeaders;
}

public Set<String> getMissingExcelCellNameHeaders() {
return missingExcelCellNameHeaders;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/poiji/exception/PoijiMultiRowException.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,28 @@ public List<PoijiRowSpecificException> getErrors() {

public static class PoijiRowSpecificException extends RuntimeException {

private final String columnName;
private final String fieldName;
private final Integer rowNum;

public PoijiRowSpecificException(String columnName, String fieldName, Integer rowNum) {
super("Cell value of column '" + columnName + "' is null,"
+ " so cannot be applied to mandatory field '" + fieldName + "'. ;Row " + rowNum);
this.columnName = columnName;
this.fieldName = fieldName;
this.rowNum = rowNum;
}

public String getColumnName() {
return columnName;
}

public String getFieldName() {
return fieldName;
}

public Integer getRowNum() {
return rowNum;
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/poiji/util/AnnotationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static <T> void validateMandatoryNameColumns(PoijiOptions options,
.forEach(missingMessage::append);
message += missingMessage;
}
throw new HeaderMissingException(message);
throw new HeaderMissingException(message, missingExcelCellHeaders, missingExcelCellNameHeaders);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.poiji.bind.Poiji;
import com.poiji.deserialize.model.byname.MandatoryMissingCells;
import com.poiji.exception.PoijiMultiRowException;
import com.poiji.exception.PoijiMultiRowException.PoijiRowSpecificException;
import com.poiji.option.PoijiOptions;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
Expand All @@ -13,14 +14,28 @@
import org.junit.Test;

import java.io.IOException;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

public class MandatoryCellsExceptionTest {

@Test(expected = PoijiMultiRowException.class)
@Test
public void testExcelMandatoryColumn() {
Poiji.fromExcel(createDummyExcel(), MandatoryMissingCells.class, PoijiOptions.PoijiOptionsBuilder
.settings()
.build());
try {
Poiji.fromExcel(createDummyExcel(), MandatoryMissingCells.class, PoijiOptions.PoijiOptionsBuilder
.settings()
.build());
} catch (PoijiMultiRowException e) {
List<PoijiRowSpecificException> errors = e.getErrors();
assertEquals(1, errors.size());
assertEquals("Address", errors.get(0).getColumnName());
assertEquals("address", errors.get(0).getFieldName());
assertEquals((Integer) 1, errors.get(0).getRowNum());
return;
}
fail("Expected exception: " + PoijiMultiRowException.class.getName());
}

private Sheet createDummyExcel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

import java.io.File;
import java.util.Arrays;
import java.util.Set;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

@RunWith(Parameterized.class)
public class MandatoryNamedColumnsExceptionTest {
Expand All @@ -28,10 +32,17 @@ public static Iterable<Object[]> queries() {
});
}

@Test(expected = HeaderMissingException.class)
@Test
public void testExcelMandatoryColumn() {
Poiji.fromExcel(new File(path), PersonByNameWithMissingColumn.class, PoijiOptions.PoijiOptionsBuilder
.settings()
.build());
try {
Poiji.fromExcel(new File(path), PersonByNameWithMissingColumn.class, PoijiOptions.PoijiOptionsBuilder
.settings()
.build());
} catch (HeaderMissingException e) {
assertEquals(Set.of(6), e.getMissingExcelCellHeaders());
assertEquals(Set.of("This column will be missing"), e.getMissingExcelCellNameHeaders());
return;
}
fail("Expected exception: " + HeaderMissingException.class.getName());
}
}

0 comments on commit 0ee9a3f

Please sign in to comment.