Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
Uploader
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Uploader
Commits
9f7eb593
Commit
9f7eb593
authored
Jun 29, 2018
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Open Ms Access as a file source
parent
f87b137c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
211 additions
and
10 deletions
+211
-10
anno-gui/pom.xml
anno-gui/pom.xml
+1
-1
anno-gui/src/main/java/org/genesys2/anno/gui/AppWindow.java
anno-gui/src/main/java/org/genesys2/anno/gui/AppWindow.java
+2
-9
anno-gui/src/main/java/org/genesys2/anno/gui/SpringConfig.java
...gui/src/main/java/org/genesys2/anno/gui/SpringConfig.java
+2
-0
anno-gui/src/main/java/org/genesys2/anno/parser/MsAccessDataSourceParser.java
...va/org/genesys2/anno/parser/MsAccessDataSourceParser.java
+109
-0
anno-gui/src/main/java/org/genesys2/anno/parser/MsAccessRowReader.java
...main/java/org/genesys2/anno/parser/MsAccessRowReader.java
+97
-0
No files found.
anno-gui/pom.xml
View file @
9f7eb593
...
...
@@ -164,7 +164,7 @@
<dependency>
<groupId>
com.healthmarketscience.jackcess
</groupId>
<artifactId>
jackcess
</artifactId>
<version>
2.1.
4
</version>
<version>
2.1.
6
</version>
</dependency>
<dependency>
<groupId>
org.hsqldb
</groupId>
...
...
anno-gui/src/main/java/org/genesys2/anno/gui/AppWindow.java
View file @
9f7eb593
...
...
@@ -316,13 +316,6 @@ public class AppWindow {
threadPool
.
shutdown
();
}
public
static
boolean
isMac
()
{
if
(
System
.
getProperty
(
"os.name"
).
equals
(
"Mac OS X"
))
{
return
true
;
}
return
false
;
}
/**
* Create contents of the window.
*/
...
...
@@ -833,8 +826,8 @@ public class AppWindow {
public
void
addSourceFile
()
{
FileDialog
fd
=
new
FileDialog
(
shlGenesysMagic
,
SWT
.
MULTI
);
fd
.
setFilterNames
(
new
String
[]
{
"Supported source files"
,
"Excel files"
,
"CSV files"
});
fd
.
setFilterExtensions
(
new
String
[]
{
"*.xlsx;*.xls;*.csv;*.tab
"
,
"*.xlsx;*.xls"
,
"*.csv;*.ta
b"
});
fd
.
setFilterNames
(
new
String
[]
{
"Supported source files"
,
"Excel files"
,
"CSV files"
,
"MS Access"
});
fd
.
setFilterExtensions
(
new
String
[]
{
"*.xlsx;*.xls;*.csv;*.tab
;*.accdb"
,
"*.xlsx;*.xls"
,
"*.csv;*.tab"
,
"*.accd
b"
});
String
response
=
fd
.
open
();
if
(
response
!=
null
)
{
...
...
anno-gui/src/main/java/org/genesys2/anno/gui/SpringConfig.java
View file @
9f7eb593
...
...
@@ -30,6 +30,7 @@ import org.genesys2.anno.model.JdbcDrivers;
import
org.genesys2.anno.model.OAuthSettings
;
import
org.genesys2.anno.model.Settings
;
import
org.genesys2.anno.parser.CsvDataSourceParser
;
import
org.genesys2.anno.parser.MsAccessDataSourceParser
;
import
org.genesys2.anno.parser.XlsxDataSourceParser
;
import
org.genesys2.anno.reader.JDBCRowReader
;
import
org.genesys2.anno.util.ConnectionUtils
;
...
...
@@ -65,6 +66,7 @@ public class SpringConfig {
DataSourceLoaderImpl
dataSourceLoader
=
new
DataSourceLoaderImpl
();
dataSourceLoader
.
registerParser
(
new
XlsxDataSourceParser
());
dataSourceLoader
.
registerParser
(
new
CsvDataSourceParser
());
dataSourceLoader
.
registerParser
(
new
MsAccessDataSourceParser
());
return
dataSourceLoader
;
}
...
...
anno-gui/src/main/java/org/genesys2/anno/parser/MsAccessDataSourceParser.java
0 → 100644
View file @
9f7eb593
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys2.anno.parser
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.genesys2.anno.gui.DataSourceSheet
;
import
org.genesys2.anno.gui.IDataSourceSheet
;
import
org.genesys2.anno.gui.UnsupportedDataFormatException
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.healthmarketscience.jackcess.Cursor
;
import
com.healthmarketscience.jackcess.Database
;
import
com.healthmarketscience.jackcess.DatabaseBuilder
;
import
com.healthmarketscience.jackcess.Row
;
import
com.healthmarketscience.jackcess.Table
;
/**
* The MsAccess DataSourceParser.
*
* @author Matija Obreza
*/
public
class
MsAccessDataSourceParser
extends
BasicDataSourceParser
{
private
static
final
Logger
_log
=
LoggerFactory
.
getLogger
(
MsAccessDataSourceParser
.
class
);
private
final
String
[]
supportedExtensions
=
new
String
[]
{
".accdb"
};
@Override
public
String
[]
getSupportedExtensions
()
{
return
supportedExtensions
;
}
@Override
public
Collection
<?
extends
DataSourceSheet
>
findSheets
(
File
sourceFile
)
throws
UnsupportedDataFormatException
{
try
{
try
(
Database
db
=
DatabaseBuilder
.
open
(
sourceFile
))
{
_log
.
debug
(
"CHARSET: "
+
db
.
getCharset
());
db
.
getTableNames
().
stream
().
forEach
(
tableName
->
System
.
out
.
println
(
"Table: "
+
tableName
));
return
db
.
getTableNames
().
stream
().
sorted
().
map
(
tableName
->
{
DataSourceSheet
sheetDataSource
=
new
DataSourceSheet
(
sourceFile
);
sheetDataSource
.
setSheetName
(
tableName
);
_log
.
debug
(
"Creating sheet for table {}"
,
tableName
);
return
sheetDataSource
;
}).
collect
(
Collectors
.
toList
());
}
}
catch
(
Throwable
e
)
{
throw
new
UnsupportedDataFormatException
(
e
.
getMessage
(),
e
);
}
}
@Override
public
List
<
Object
[]>
loadRows
(
IDataSourceSheet
dataSourceSheet
,
int
maxRows
,
int
startAt
)
throws
UnsupportedDataFormatException
,
FileNotFoundException
,
IOException
{
File
sourceFile
=
dataSourceSheet
.
getSourceFile
();
String
sheetName
=
dataSourceSheet
.
getSheetName
();
_log
.
debug
(
"Reading {} from {}"
,
sheetName
,
sourceFile
);
List
<
Object
[]>
rows
=
new
ArrayList
<
Object
[]>(
maxRows
);
try
{
try
(
Database
db
=
DatabaseBuilder
.
open
(
sourceFile
))
{
_log
.
debug
(
"CHARSET: "
+
db
.
getCharset
());
Table
table
=
db
.
getTable
(
sheetName
);
rows
.
add
(
table
.
getColumns
().
stream
().
map
(
column
->
column
.
getName
()).
toArray
());
Cursor
cursor
=
table
.
getDefaultCursor
();
cursor
.
moveNextRows
(
startAt
);
for
(
int
pos
=
maxRows
;
pos
>
0
;
pos
--)
{
Row
r
=
cursor
.
getNextRow
();
if
(
r
!=
null
)
{
rows
.
add
(
r
.
values
().
toArray
());
}
}
}
return
rows
;
}
catch
(
Throwable
e
)
{
throw
new
UnsupportedDataFormatException
(
e
.
getMessage
(),
e
);
}
}
@Override
public
RowReader
createRowReader
(
IDataSourceSheet
dataSourceSheet
)
throws
UnsupportedDataFormatException
,
IOException
{
File
sourceFile
=
dataSourceSheet
.
getSourceFile
();
String
sheetName
=
dataSourceSheet
.
getSheetName
();
return
new
MsAccessRowReader
(
sourceFile
,
sheetName
);
}
}
anno-gui/src/main/java/org/genesys2/anno/parser/MsAccessRowReader.java
0 → 100644
View file @
9f7eb593
/*
* Copyright 2018 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.genesys2.anno.parser
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.healthmarketscience.jackcess.Cursor
;
import
com.healthmarketscience.jackcess.Database
;
import
com.healthmarketscience.jackcess.DatabaseBuilder
;
import
com.healthmarketscience.jackcess.Row
;
import
com.healthmarketscience.jackcess.Table
;
/**
* The Ms Access RowReader.
*
* @author Matija Obreza
*/
public
class
MsAccessRowReader
implements
RowReader
{
private
static
final
Logger
_log
=
LoggerFactory
.
getLogger
(
MsAccessRowReader
.
class
);
private
Database
db
;
private
Table
table
;
private
Cursor
cursor
;
/**
* Instantiates a new ms access row reader.
*
* @param sourceFile
* the source file
* @param sheetName
* the sheet name
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public
MsAccessRowReader
(
File
sourceFile
,
String
sheetName
)
throws
IOException
{
this
.
db
=
DatabaseBuilder
.
open
(
sourceFile
);
_log
.
debug
(
"CHARSET: "
+
db
.
getCharset
());
this
.
table
=
db
.
getTable
(
sheetName
);
this
.
cursor
=
table
.
getDefaultCursor
();
}
/// This is called in case data starts beyond 1st row
@Override
public
void
setSkipRows
(
int
skipRows
)
{
_log
.
info
(
"Skipping rows {}"
,
skipRows
);
cursor
.
reset
();
// try {
// cursor.moveNextRows(skipRows);
// } catch (IOException e) {
// _log.error("Could not skip rows", e);
// }
}
@Override
public
int
getRowCount
()
{
return
table
.
getRowCount
();
}
@Override
public
void
close
()
throws
IOException
{
db
.
close
();
}
@Override
public
List
<
Object
[]>
readRows
(
int
rowsToRead
)
throws
IOException
{
List
<
Object
[]>
rows
=
new
ArrayList
<
Object
[]>(
rowsToRead
);
int
rowCount
=
0
;
while
((
rowCount
<
rowsToRead
)
&&
cursor
.
moveToNextRow
())
{
rowCount
++;
Row
r
=
cursor
.
getCurrentRow
();
if
(
r
!=
null
)
{
rows
.
add
(
r
.
values
().
toArray
());
}
}
return
rows
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment