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
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
45
Issues
45
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
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
Genesys Backend
Commits
5fd05216
Commit
5fd05216
authored
Feb 27, 2014
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TaxonomyService does not enforce 'subsp.', upgrade will include subtaxa
parent
498dc684
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
10 deletions
+118
-10
src/main/java/org/genesys2/server/listener/sample/TaxonomyUpgrade.java
.../org/genesys2/server/listener/sample/TaxonomyUpgrade.java
+9
-1
src/main/java/org/genesys2/server/service/impl/TaxonomyServiceImpl.java
...org/genesys2/server/service/impl/TaxonomyServiceImpl.java
+4
-9
src/test/java/org/genesys2/server/test/TaxonomyEnsureTest.java
...est/java/org/genesys2/server/test/TaxonomyEnsureTest.java
+105
-0
No files found.
src/main/java/org/genesys2/server/listener/sample/TaxonomyUpgrade.java
View file @
5fd05216
...
...
@@ -68,13 +68,21 @@ public class TaxonomyUpgrade extends RunAsAdminListener {
continue
;
}
String
species
=
t1
.
getSpecies
();
String
spAuthor
=
null
;
String
subtaxa
=
null
;
String
subtAuthor
=
null
;
String
x
=
genus
+
' '
+
species
;
if
(
t1
.
getTaxonName
().
startsWith
(
x
))
{
String
foo
=
t1
.
getTaxonName
().
substring
(
x
.
length
()).
trim
();
if
(
StringUtils
.
isNotBlank
(
foo
))
{
subtaxa
=
foo
;
}
}
// Make new taxonomy
Taxonomy2
t2
=
taxonomyService
.
ensureTaxonomy2
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
counter
.
incrementAndGet
();
// Update all accessions
count
=
taxonomyService
.
upgradeTaxonomy
(
t1
,
t2
);
...
...
src/main/java/org/genesys2/server/service/impl/TaxonomyServiceImpl.java
View file @
5fd05216
...
...
@@ -125,10 +125,6 @@ public class TaxonomyServiceImpl implements TaxonomyService {
species
=
"sp."
;
}
if
(
StringUtils
.
isNotBlank
(
species
)
&&
!
StringUtils
.
equals
(
species
,
"sp."
)
&&
StringUtils
.
isBlank
(
subtaxa
))
{
subtaxa
=
"subsp."
;
}
Taxonomy2
existing
=
taxonomy2Repository
.
findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
if
(
existing
==
null
)
{
return
internalEnsure
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
...
...
@@ -139,11 +135,11 @@ public class TaxonomyServiceImpl implements TaxonomyService {
private
synchronized
Taxonomy2
internalEnsure
(
String
genus
,
String
species
,
String
spAuthor
,
String
subtaxa
,
String
subtAuthor
)
{
Taxonomy2
genusTaxa
=
null
;
Taxonomy2
speciesTaxa
=
null
;
if
(
species
!=
null
&&
!
StringUtils
.
equals
(
species
,
"sp."
)
&&
(
subtaxa
!=
null
||
spAuthor
!=
null
||
subtAuthor
!=
null
))
{
if
(
!
StringUtils
.
equals
(
species
,
"sp."
)
||
(
subtaxa
!=
null
||
spAuthor
!=
null
||
subtAuthor
!=
null
))
{
genusTaxa
=
internalEnsure
(
genus
,
"sp."
,
null
,
null
,
null
);
}
if
(
species
!=
null
&&
!
StringUtils
.
equals
(
species
,
"sp."
)
&&
!
StringUtils
.
equals
(
subtaxa
,
"subsp."
)
&&
spAuthor
!=
null
&&
subtAuthor
!=
null
)
{
speciesTaxa
=
internalEnsure
(
genus
,
species
,
null
,
"subsp."
,
null
);
if
(
!
StringUtils
.
equals
(
species
,
"sp."
)
&&
(
subtaxa
!=
null
||
spAuthor
!=
null
||
subtAuthor
!=
null
)
)
{
speciesTaxa
=
internalEnsure
(
genus
,
species
,
null
,
null
,
null
);
}
// Loop it a bit if required
...
...
@@ -202,8 +198,7 @@ public class TaxonomyServiceImpl implements TaxonomyService {
@Override
public
long
getTaxonomy2Id
(
String
genus
,
String
species
)
{
Taxonomy2
tax
=
taxonomy2Repository
.
findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor
(
genus
,
species
,
null
,
"subsp."
,
null
);
System
.
err
.
println
(
"tax2="
+
tax
);
Taxonomy2
tax
=
taxonomy2Repository
.
findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor
(
genus
,
species
,
null
,
null
,
null
);
return
tax
.
getId
();
}
...
...
src/test/java/org/genesys2/server/test/TaxonomyEnsureTest.java
0 → 100644
View file @
5fd05216
package
org.genesys2.server.test
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
org.apache.commons.lang.StringUtils
;
import
org.genesys2.server.model.genesys.Taxonomy2
;
import
org.genesys2.server.service.TaxonomyService
;
import
org.genesys2.server.service.impl.TaxonomyServiceImpl
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
classes
=
TaxonomyEnsureTest
.
Config
.
class
,
initializers
=
PropertyPlacholderInitializer
.
class
)
public
class
TaxonomyEnsureTest
{
@Import
(
JpaDataConfig
.
class
)
public
static
class
Config
{
@Bean
public
TaxonomyService
taxonomyService
()
{
return
new
TaxonomyServiceImpl
();
}
}
// use it without @Scheduled
@Autowired
private
TaxonomyService
taxonomyService
;
@Test
public
void
testSubstr
()
{
String
genus
=
"Aaaa"
;
String
species
=
"bbbb"
;
String
taxonName
=
"Aaaa bbbb fb."
;
String
x
=
genus
+
' '
+
species
;
assertTrue
(
taxonName
.
startsWith
(
x
));
if
(
taxonName
.
startsWith
(
x
))
{
String
subtaxa
=
taxonName
.
substring
(
x
.
length
()).
trim
();
assertTrue
(
StringUtils
.
isNotBlank
(
subtaxa
));
assertTrue
(
"fb."
.
equals
(
subtaxa
));
}
}
@Test
public
void
testEnsure1
()
{
try
{
Taxonomy2
tax
=
taxonomyService
.
ensureTaxonomy2
(
"Aaaaa"
,
"bbbb"
,
null
,
"alfalfa"
,
null
);
assertTrue
(
"id missing"
,
tax
.
getId
()
!=
null
);
assertTrue
(
"taxGenus should not be null"
,
tax
.
getTaxGenus
()
!=
null
);
assertTrue
(
"taxSpecies should not be null"
,
tax
.
getTaxSpecies
()
!=
null
);
assertTrue
(
"taxGenus should not be this"
,
!
tax
.
getTaxGenus
().
equals
(
tax
.
getId
()));
assertTrue
(
"taxSpecies should not be this"
,
!
tax
.
getTaxSpecies
().
equals
(
tax
.
getId
()));
assertTrue
(
"taxSpecies should not match taxGenus"
,
!
tax
.
getTaxSpecies
().
equals
(
tax
.
getTaxGenus
()));
Taxonomy2
taxGenus
=
taxonomyService
.
get
(
tax
.
getTaxGenus
());
assertTrue
(
"taxGenus should have species=sp. and not "
+
taxGenus
.
getSpecies
(),
taxGenus
.
getSpecies
().
equals
(
"sp."
));
Taxonomy2
taxSpecies
=
taxonomyService
.
get
(
tax
.
getTaxSpecies
());
assertTrue
(
"taxSpecies should have species=bbbb and not "
+
taxSpecies
.
getSpecies
(),
taxSpecies
.
getSpecies
().
equals
(
tax
.
getSpecies
()));
}
catch
(
Exception
e
)
{
fail
(
"This should not have any exceptions!"
);
}
}
@Test
public
void
testNullSpecies
()
{
try
{
Taxonomy2
tax
=
taxonomyService
.
ensureTaxonomy2
(
"Aaaaa"
,
null
,
null
,
null
,
null
);
assertTrue
(
"id missing"
,
tax
.
getId
()
!=
null
);
assertTrue
(
"taxGenus should not be null"
,
tax
.
getTaxGenus
()
!=
null
);
assertTrue
(
"taxSpecies should not be null"
,
tax
.
getTaxSpecies
()
!=
null
);
assertTrue
(
"taxGenus must be this"
,
tax
.
getTaxGenus
().
equals
(
tax
.
getId
()));
assertTrue
(
"taxSpecies must be this"
,
tax
.
getTaxSpecies
().
equals
(
tax
.
getId
()));
assertTrue
(
"taxSpecies should match taxGenus"
,
tax
.
getTaxSpecies
().
equals
(
tax
.
getTaxGenus
()));
}
catch
(
Exception
e
)
{
fail
(
"This should not have any exceptions!"
);
}
}
@Test
public
void
testSpSpecies
()
{
try
{
Taxonomy2
tax
=
taxonomyService
.
ensureTaxonomy2
(
"Aaaaa"
,
"sp"
,
null
,
null
,
null
);
assertTrue
(
"id missing"
,
tax
.
getId
()
!=
null
);
assertTrue
(
"species must be sp."
,
tax
.
getSpecies
().
equals
(
"sp."
));
assertTrue
(
"taxGenus should not be null"
,
tax
.
getTaxGenus
()
!=
null
);
assertTrue
(
"taxSpecies should not be null"
,
tax
.
getTaxSpecies
()
!=
null
);
assertTrue
(
"taxGenus must be this"
,
tax
.
getTaxGenus
().
equals
(
tax
.
getId
()));
assertTrue
(
"taxSpecies must be this"
,
tax
.
getTaxSpecies
().
equals
(
tax
.
getId
()));
assertTrue
(
"taxSpecies should match taxGenus"
,
tax
.
getTaxSpecies
().
equals
(
tax
.
getTaxGenus
()));
}
catch
(
Exception
e
)
{
fail
(
"This should not have any exceptions!"
);
}
}
}
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