Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
1362dae5
Commit
1362dae5
authored
Mar 04, 2014
by
Matija Obreza
Browse files
SGSV export format changed (new column "accession_name")
parent
91b3ef3f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/service/worker/SGSVUpdate.java
View file @
1362dae5
...
...
@@ -17,9 +17,6 @@
package
org.genesys2.server.service.worker
;
import
java.io.BufferedReader
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
...
...
@@ -46,7 +43,6 @@ import org.genesys2.server.service.GeoService;
import
org.genesys2.server.service.TaxonomyService
;
import
org.hibernate.exception.ConstraintViolationException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.task.TaskExecutor
;
import
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException
;
import
org.springframework.security.access.prepost.PreAuthorize
;
...
...
@@ -58,15 +54,17 @@ import au.com.bytecode.opencsv.CSVReader;
public
class
SGSVUpdate
{
private
static
final
String
SGSV_DOWNLOAD_URL
=
"http://www.nordgen.org/sgsv/download.php?file=/scope/sgsv/files/sgsv_templates.tab"
;
private
static
final
String
[]
SGSV_HEADERS
=
{
"sgsv_id"
,
"institute_code"
,
"deposit_box_number"
,
"collection_name"
,
"accession_number"
,
"full_scientific_name"
,
"country_of_collection_or_source"
,
"number_of_seeds"
,
"regeneration_month_and_year"
,
"other_accession_designations"
,
"provider_institute_code"
,
"accession_url"
,
"country_code"
,
"country_name"
,
"continent_name"
,
"seeds"
,
"genus"
,
"species_epithet"
,
"species"
,
"taxon_name"
,
"date_of_deposit"
,
"date_of_dataset"
,
"sgsv_template_id"
,
"box_id"
,
"sgsv_taxon_id"
,
"taxon_authority"
,
"infraspesific_epithet"
,
"vernacular_name"
,
"itis_tsn"
,
"sgsv_genus_id"
,
"accession_name"
};
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
SGSVUpdate
.
class
);
private
static
final
int
BATCH_SIZE
=
50
;
@Autowired
private
TaskExecutor
taskExecutor
;
@Value
(
"${download.files.dir}"
)
String
filesPath
;
@Autowired
private
GenesysService
genesysService
;
...
...
@@ -113,25 +111,6 @@ public class SGSVUpdate {
}
}
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
public
void
updateSGSVFile
()
{
// sgsv_templates_20130610.tab
// sgsv_templates_20130502.tab
final
File
file
=
new
File
(
filesPath
,
"sgsv_templates_20130610.tab"
);
FileInputStream
fis
=
null
;
try
{
fis
=
new
FileInputStream
(
file
);
LOG
.
warn
(
"Importing SGSV data from "
+
file
.
getAbsolutePath
());
importSGSVStream
(
fis
,
file
.
getAbsolutePath
());
}
catch
(
final
FileNotFoundException
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
}
catch
(
final
IOException
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
IOUtils
.
closeQuietly
(
fis
);
}
}
private
void
importSGSVStream
(
final
InputStream
str
,
final
String
source
)
throws
IOException
{
int
counter
=
0
;
...
...
@@ -142,42 +121,17 @@ public class SGSVUpdate {
final
String
[]
headers
=
reader
.
readNext
();
LOG
.
debug
(
"Headers: "
+
headers
.
length
);
if
(
headers
.
length
!=
30
)
{
if
(
headers
.
length
!=
SGSV_HEADERS
.
length
)
{
LOG
.
warn
(
"Expected 30 headers, got "
+
headers
.
length
);
return
;
}
for
(
int
i
=
0
;
i
<
SGSV_HEADERS
.
length
;
i
++)
{
if
(!
StringUtils
.
equals
(
headers
[
i
],
SGSV_HEADERS
[
i
]))
{
LOG
.
warn
(
"SGSV template header mismatch pos="
+
i
+
" expected="
+
SGSV_HEADERS
[
i
]
+
" found="
+
headers
[
i
]);
return
;
}
// descriptors[0] = descriptorRepository.findByCode("SGSV_ID");
// descriptors[1] = descriptorRepository.findByCode("INSTCODE");
// descriptors[2] = descriptorRepository.findByCode("SGSV_BOXNO");
// descriptors[3] = descriptorRepository.findByCode("COLLNAME");
// descriptors[4] = descriptorRepository.findByCode("ACCENUMB");
// descriptors[5] = descriptorRepository.findByCode("FULL_SCINAME");
// descriptors[7] = descriptorRepository.findByCode("QTY");
// descriptors[8] =
// descriptorRepository.findByCode("regeneration_month_and_year");
// descriptors[9] = descriptorRepository.findByCode("OTHERNUMB");
// descriptors[10] =
// descriptorRepository.findByCode("provider_institute_code");
// descriptors[12] = descriptorRepository.findByCode("ORIGCTY");
// descriptors[16] = descriptorRepository.findByCode("GENUS");
// descriptors[17] =
// descriptorRepository.findByCode("species_epithet");
// descriptors[17] = descriptorRepository.findByCode("SPECIES");
// descriptors[19] = descriptorRepository.findByCode("TAXON_NAME");
// descriptors[20] =
// descriptorRepository.findByCode("SGSV_DEPOSIT_DATE");
// descriptors[23] = descriptorRepository.findByCode("SGSV_BOXID");
// descriptors[24] =
// descriptorRepository.findByCode("SGSV_TAXONID");
// descriptors[25] =
// descriptorRepository.findByCode("taxon_authority");
// descriptors[26] =
// descriptorRepository.findByCode("infraspesific_epithet");
// descriptors[27] =
// descriptorRepository.findByCode("VERNACULAR_NAME");
// descriptors[29] =
// descriptorRepository.findByCode("SGSV_GENUSID");
}
final
List
<
String
[]>
bulk
=
new
ArrayList
<
String
[]>(
BATCH_SIZE
);
...
...
Write
Preview
Supports
Markdown
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