-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kadioglumf/csv-reader
feat: add csv reader.
- Loading branch information
Showing
24 changed files
with
476 additions
and
258 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
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 |
---|---|---|
@@ -1,27 +1,9 @@ | ||
package com.kadioglumf; | ||
|
||
import com.kadioglumf.dto.excel.TestExcelDto; | ||
import com.kadioglumf.enums.FileExtension; | ||
import com.kadioglumf.service.ReaderService; | ||
import org.apache.commons.io.FilenameUtils; | ||
import org.springframework.context.i18n.LocaleContextHolder; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class Main { | ||
|
||
|
||
|
||
public static void main(String[] args) throws Exception { | ||
LocaleContextHolder.setLocale(new Locale("tr", "TR")); | ||
|
||
File file = new File(System.getProperty("user.dir") + "/src/main/resources/test.xlsx"); | ||
ReaderService readerService = new ReaderService(); | ||
|
||
List<TestExcelDto> list = readerService.readFile(TestExcelDto.class, new FileInputStream(file), FilenameUtils.getExtension(file.getName()), true); | ||
list.forEach(System.out::println); | ||
public static void main(String[] args) { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/main/java/com/kadioglumf/annotations/csv/CsvColumn.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,16 @@ | ||
package com.kadioglumf.annotations.csv; | ||
|
||
import com.kadioglumf.cellprocessor.CellProcessor; | ||
import com.kadioglumf.cellprocessor.StringCell; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.FIELD}) | ||
public @interface CsvColumn { | ||
int columnIndex(); | ||
Class<? extends CellProcessor> cellProcessor() default StringCell.class; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/kadioglumf/annotations/csv/ExportCsvSettings.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,13 @@ | ||
package com.kadioglumf.annotations.csv; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ExportCsvSettings { | ||
char quoteChar() default '"'; | ||
char delimiterChar() default ','; | ||
String endOfLineSymbols() default "\r\n"; | ||
boolean isFirstRowHeader() default true; | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/kadioglumf/annotations/excel/ExportExcelSettings.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,14 @@ | ||
package com.kadioglumf.annotations.excel; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Documented | ||
@Target({ElementType.TYPE}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ExportExcelSettings { | ||
boolean isFirstRowHeader() default true; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/kadioglumf/cellprocessor/CellProcessor.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,6 @@ | ||
package com.kadioglumf.cellprocessor; | ||
|
||
public interface CellProcessor { | ||
|
||
Object execute(Object var1, Class<?> targetType); | ||
} |
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,14 @@ | ||
package com.kadioglumf.cellprocessor; | ||
|
||
import com.kadioglumf.util.DateUtils; | ||
|
||
public class DateCell implements CellProcessor { | ||
|
||
@Override | ||
public Object execute(Object var1, Class<?> targetType) { | ||
if (var1 == null) { | ||
return null; | ||
} | ||
return DateUtils.parseStringToDateFormatted(targetType, String.valueOf(var1)); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/kadioglumf/cellprocessor/NumberCell.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,23 @@ | ||
package com.kadioglumf.cellprocessor; | ||
|
||
import com.kadioglumf.util.NumberUtils; | ||
|
||
import java.text.ParseException; | ||
|
||
public class NumberCell implements CellProcessor { | ||
|
||
|
||
@Override | ||
public Object execute(Object var1, Class<?> targetType) { | ||
if (var1 == null) { | ||
return null; | ||
} | ||
|
||
try { | ||
return NumberUtils.parseNumericValue(String.valueOf(var1), targetType); | ||
} | ||
catch (ParseException ex) { | ||
throw new RuntimeException(); //TODO | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/kadioglumf/cellprocessor/StringCell.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,13 @@ | ||
package com.kadioglumf.cellprocessor; | ||
|
||
public class StringCell implements CellProcessor { | ||
|
||
|
||
@Override | ||
public Object execute(Object var1, Class<?> targetType) { | ||
if (var1 == null) { | ||
return null; | ||
} | ||
return String.valueOf(var1); | ||
} | ||
} |
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,17 @@ | ||
package com.kadioglumf.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.io.Serializable; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Tuple<T, V> implements Serializable { | ||
private transient T first; | ||
private transient V second; | ||
} |
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
Oops, something went wrong.