diff --git a/build/libs/.gradle/2.13/taskArtifacts/cache.properties b/build/libs/.gradle/2.13/taskArtifacts/cache.properties new file mode 100644 index 0000000..d4ba7e9 --- /dev/null +++ b/build/libs/.gradle/2.13/taskArtifacts/cache.properties @@ -0,0 +1 @@ +#Mon May 29 17:23:29 MSK 2017 diff --git a/build/libs/excel2db.properties b/build/libs/excel2db.properties new file mode 100644 index 0000000..48cd326 --- /dev/null +++ b/build/libs/excel2db.properties @@ -0,0 +1,17 @@ +# names of input tables +input.files=test.xlsx + +# db implementation classes + +# postgres section +# dbConnectionImplenentation=excel2db.service.impl.DBConnectionPostgresImpl +# oracle section +dbConnectionImplenentation=excel2db.service.impl.DBConnectionOracleImpl + +# postgres connection parameters +db.server=localhost +db.database=excel2db +db.port=5433 +db.user=postgres +db.password=postgres + diff --git a/build/resources/main/excel2db.properties b/build/resources/main/excel2db.properties index a045761..48cd326 100644 --- a/build/resources/main/excel2db.properties +++ b/build/resources/main/excel2db.properties @@ -1,5 +1,5 @@ # names of input tables -input.files=test.xls +input.files=test.xlsx # db implementation classes diff --git a/src/main/java/excel2db/excel2db.java b/src/main/java/excel2db/excel2db.java index 3907c37..2198634 100644 --- a/src/main/java/excel2db/excel2db.java +++ b/src/main/java/excel2db/excel2db.java @@ -3,6 +3,8 @@ import java.io.File; import java.sql.Connection; import java.sql.SQLException; +import java.util.HashSet; +import java.util.concurrent.TimeUnit; import excel2db.ApplicationException; import excel2db.service.CreateTable; @@ -65,7 +67,6 @@ public static void main(String[] args) { try { - //for profiling, to launch the VisualVM first, // then start the application by pressing the Enter //System.in.read(); @@ -75,19 +76,36 @@ public static void main(String[] args) { taskExecutor = (ThreadPoolTaskExecutor) context.getBean("taskExecutor"); + //check if the file list is not empty + HashSet fileList = app.generateFileList.generateFileList(); + if (fileList == null){ + throw new Exception("File list is empty in property file"); + //logger.error("Empty file list"); + } + //this way we call methods for objects that is already initialized by the Spring app.dbConnection.establishDBConnection(); // iterate through file name values in properties file, // for each file start a new thread - for (String fileNameValue : app.generateFileList.generateFileList()) { + for (String fileNameValue : fileList) { + File fileName = new File(fileNameValue); - taskExecutor.execute(new Excel2dbTask(app, fileName)); + //check if the file really exists + if (fileName.exists() == false) { + logger.error("The file " + fileNameValue + " doesn't exist"); + } else { + taskExecutor.execute(new Excel2dbTask(app, fileName)); + } + } + //TODO : This is just as a workaround to wait till the thread has been really started + //TODO : Need to use the ScheduledThreadPoolExecutor to customize delays on starting threads + TimeUnit.SECONDS.sleep(1); // Wait until all threads are finished logger.info("Waiting until active threads exist"); - while (excel2db.taskExecutor.getActiveCount() != 0) { + while (taskExecutor.getActiveCount() != 0) { } logger.info("All threads are inactive"); diff --git a/src/main/java/excel2db/service/impl/GenerateFileListImpl.java b/src/main/java/excel2db/service/impl/GenerateFileListImpl.java index d9632c7..314200a 100644 --- a/src/main/java/excel2db/service/impl/GenerateFileListImpl.java +++ b/src/main/java/excel2db/service/impl/GenerateFileListImpl.java @@ -15,11 +15,12 @@ public class GenerateFileListImpl implements GenerateFileList { @Override public HashSet generateFileList() { - String[] fileNameArray = inputFilesList.split(","); - - // hash set to eliminate duplicates - HashSet fileList = new HashSet<>(Arrays.asList(fileNameArray)); - + HashSet fileList = null; + if (!inputFilesList.isEmpty()) { + String[] fileNameArray = inputFilesList.split(","); + // hash set to eliminate duplicates + fileList = new HashSet<>(Arrays.asList(fileNameArray)); + } return fileList; } diff --git a/src/main/resources/excel2db.properties b/src/main/resources/excel2db.properties index a045761..48cd326 100644 --- a/src/main/resources/excel2db.properties +++ b/src/main/resources/excel2db.properties @@ -1,5 +1,5 @@ # names of input tables -input.files=test.xls +input.files=test.xlsx # db implementation classes diff --git a/src/test/java/InitInputFilesImplTest.java b/src/test/java/InitInputFilesImplTest.java index 958bfe8..c2dd7f1 100644 --- a/src/test/java/InitInputFilesImplTest.java +++ b/src/test/java/InitInputFilesImplTest.java @@ -37,10 +37,10 @@ public void testInitInputFilesImpl() throws Exception { excel2db app = (excel2db) context.getBean("excel2db"); //executing the test - File fileName = new File(app.initConstants.workingDir + "/test.xls"); + File fileName = new File(app.initConstants.workingDir + "/test.xlsx"); //here we should initialize the sheet object - assertEquals("UnitTestSheet", app.initInputFiles.initInputFiles(fileName).getSheetName()); + assertEquals("TestSheet", app.initInputFiles.initInputFiles(fileName).getSheetName()); } diff --git a/src/test/java/PopulateTablePostgresImplTest.java b/src/test/java/PopulateTablePostgresImplTest.java index 7ae689b..9865300 100644 --- a/src/test/java/PopulateTablePostgresImplTest.java +++ b/src/test/java/PopulateTablePostgresImplTest.java @@ -34,14 +34,14 @@ public void testPopulateTable() throws Exception { excel2db app = (excel2db) context.getBean("excel2db"); //executing the test - File fileName = new File(app.initConstants.workingDir + "/test.xls"); + File fileName = new File(app.initConstants.workingDir + "/test.xlsx"); sheet = app.initInputFiles.initInputFiles(fileName); app.dbConnection.establishDBConnection(); app.createTable.createTable(sheet, "testTable"); //here we should initialize the sheet object Integer numOfProcessedRows = app.populateTable.populateTable(sheet, "testTable"); - assertEquals(Integer.valueOf(9), numOfProcessedRows); + assertEquals(Integer.valueOf(2), numOfProcessedRows); } } \ No newline at end of file