Skip to content
GitLab
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
b52fcf56
Commit
b52fcf56
authored
Feb 27, 2014
by
Matija Obreza
Browse files
Taxonomy to Taxonomy2
parent
9a9f0cbc
Changes
17
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/listener/sample/TaxonomyUpgrade.java
0 → 100644
View file @
b52fcf56
/**
* Copyright 2014 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.server.listener.sample
;
import
java.util.List
;
import
java.util.concurrent.atomic.AtomicLong
;
import
org.genesys2.server.listener.RunAsAdminListener
;
import
org.genesys2.server.model.genesys.Taxonomy
;
import
org.genesys2.server.model.genesys.Taxonomy2
;
import
org.genesys2.server.persistence.domain.GenesysLowlevelRepository
;
import
org.genesys2.server.service.GenesysService
;
import
org.genesys2.server.service.TaxonomyService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* Upgrades taxonomy1 to taxonomy2
*
* @author mobreza
*/
@Component
public
class
TaxonomyUpgrade
extends
RunAsAdminListener
{
@Autowired
GenesysService
genesysService
;
@Autowired
GenesysLowlevelRepository
genesysLowlevelRepository
;
@Autowired
TaxonomyService
taxonomyService
;
@Override
public
void
init
()
throws
Exception
{
_logger
.
info
(
"Checking if default content exists"
);
long
count
=
taxonomyService
.
countTaxonomy2
();
_logger
.
warn
(
"Taxonomy2 count="
+
count
);
if
(
count
!=
0
)
{
_logger
.
warn
(
"Not changing taxonomy2"
);
return
;
}
final
AtomicLong
counter
=
new
AtomicLong
(
0
);
List
<
Taxonomy
>
oldTaxa
=
taxonomyService
.
findAll
();
for
(
Taxonomy
t1
:
oldTaxa
)
{
String
genus
=
t1
.
getGenus
();
String
species
=
t1
.
getSpecies
();
String
spAuthor
=
null
;
String
subtaxa
=
null
;
String
subtAuthor
=
null
;
// Make new taxonomy
Taxonomy2
t2
=
taxonomyService
.
ensureTaxonomy2
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
// Update all accessions
count
=
taxonomyService
.
upgradeTaxonomy
(
t1
,
t2
);
_logger
.
info
(
"Upgraded "
+
t1
+
" to "
+
t2
+
" on accessions="
+
count
);
}
_logger
.
warn
(
"Updated Taxonomy2 count="
+
counter
);
}
}
src/main/java/org/genesys2/server/model/genesys/Accession.java
View file @
b52fcf56
...
...
@@ -97,7 +97,7 @@ public class Accession extends VersionedAuditedModel {
private
Boolean
mlsStatus
;
@Column
(
name
=
"taxGenus"
,
nullable
=
true
)
private
l
ong
taxGenus
;
private
L
ong
taxGenus
;
@Column
(
name
=
"taxSpecies"
,
nullable
=
true
)
private
Long
taxSpecies
;
...
...
@@ -237,7 +237,8 @@ public class Accession extends VersionedAuditedModel {
return
taxGenus
;
}
public
void
setTaxGenus
(
long
taxGenus
)
{
// TODO Must be long
public
void
setTaxGenus
(
Long
taxGenus
)
{
this
.
taxGenus
=
taxGenus
;
}
...
...
src/main/java/org/genesys2/server/model/genesys/Taxonomy2.java
View file @
b52fcf56
...
...
@@ -21,6 +21,7 @@ import java.text.MessageFormat;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Lob
;
import
javax.persistence.PrePersist
;
import
javax.persistence.Table
;
import
javax.persistence.UniqueConstraint
;
...
...
@@ -54,13 +55,18 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
@Lob
private
String
taxonName
;
private
l
ong
taxGenus
;
private
L
ong
taxGenus
;
private
Long
taxSpecies
;
// @OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "taxonomy")
// private List<CropTaxonomy> cropTaxonomies;
@PrePersist
private
void
prePersist
()
{
this
.
taxonName
=
getTaxonName
();
}
public
String
getGenus
()
{
return
this
.
genus
;
}
...
...
@@ -91,7 +97,7 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
public
void
setTaxonName
(
String
taxonName
)
{
// Ignore what they provide
taxonName
=
getTaxonName
();
this
.
taxonName
=
getTaxonName
();
}
// public List<CropTaxonomy> getCropTaxonomies() {
...
...
@@ -130,11 +136,11 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
return
taxonomy
==
null
?
false
:
taxonomy
.
getId
().
equals
(
id
);
}
public
l
ong
getTaxGenus
()
{
public
L
ong
getTaxGenus
()
{
return
this
.
taxGenus
;
}
public
void
setTaxGenus
(
l
ong
taxGenus
)
{
public
void
setTaxGenus
(
L
ong
taxGenus
)
{
this
.
taxGenus
=
taxGenus
;
}
...
...
@@ -148,7 +154,7 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
@Override
public
String
toString
()
{
return
MessageFormat
.
format
(
"Tax id={0} taxonName="
,
id
,
getTaxonName
());
return
MessageFormat
.
format
(
"Tax id={0} taxonName=
{1}
"
,
id
,
getTaxonName
());
}
}
src/main/java/org/genesys2/server/model/impl/CropRule.java
View file @
b52fcf56
...
...
@@ -35,7 +35,7 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
* @author mobreza
*/
@Entity
@Table
(
name
=
"croprule"
,
uniqueConstraints
=
{
@UniqueConstraint
(
columnNames
=
{
"cropId"
,
"genus"
,
"species"
})
})
@Table
(
name
=
"croprule"
,
uniqueConstraints
=
{
@UniqueConstraint
(
columnNames
=
{
"cropId"
,
"genus"
,
"species"
,
"subtaxa"
})
})
@JsonSerialize
(
using
=
CropRuleSerializer
.
class
)
public
class
CropRule
extends
BusinessModel
{
private
static
final
long
serialVersionUID
=
-
2336100072991067193L
;
...
...
@@ -46,8 +46,11 @@ public class CropRule extends BusinessModel {
@Column
(
nullable
=
false
,
length
=
100
)
private
String
genus
;
@Column
@Column
(
nullable
=
true
,
length
=
100
)
private
String
species
;
@Column
(
nullable
=
true
,
length
=
100
)
private
String
subtaxa
;
@ManyToOne
(
cascade
=
{},
fetch
=
FetchType
.
EAGER
,
optional
=
false
)
@JoinColumn
(
name
=
"cropId"
)
...
...
@@ -76,6 +79,14 @@ public class CropRule extends BusinessModel {
public
void
setSpecies
(
String
species
)
{
this
.
species
=
species
;
}
public
String
getSubtaxa
()
{
return
subtaxa
;
}
public
void
setSubtaxa
(
String
subtaxa
)
{
this
.
subtaxa
=
subtaxa
;
}
public
Crop
getCrop
()
{
return
crop
;
...
...
src/main/java/org/genesys2/server/persistence/domain/AccessionRepository.java
View file @
b52fcf56
...
...
@@ -21,7 +21,7 @@ import java.util.List;
import
java.util.Set
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.genesys.Taxonomy
;
import
org.genesys2.server.model.genesys.Taxonomy
2
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
...
...
@@ -41,6 +41,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query
(
countQuery
=
"select count(*) from accession a where a.taxGenus = ?1"
)
Page
<
Accession
>
findByTaxGenus
(
long
taxonomyId
,
Pageable
pageable
);
@Query
(
countQuery
=
"select count(*) from accession a where a.taxSpecies = ?1"
)
Page
<
Accession
>
findByTaxSpecies
(
long
taxSpecies
,
Pageable
pageable
);
List
<
Accession
>
findByInstitute
(
FaoInstitute
institute
);
@Query
(
"select count(a) from Accession a where a.institute = ?1"
)
...
...
@@ -90,12 +93,12 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query
(
"from Accession a where a.id in ( ?1 )"
)
List
<
Accession
>
listById
(
Collection
<
Long
>
accessionIds
,
Sort
sort
);
Page
<
Accession
>
findByInstituteAndTaxonomy
(
FaoInstitute
institute
,
Taxonomy
taxonomy
,
Pageable
pageable
);
Page
<
Accession
>
findByInstituteAndTaxonomy
(
FaoInstitute
institute
,
Taxonomy
2
taxonomy
,
Pageable
pageable
);
Page
<
Accession
>
findByTaxonomy
(
Taxonomy
taxonomy
,
Pageable
pageable
);
Page
<
Accession
>
findByTaxonomy
(
Taxonomy
2
taxonomy
,
Pageable
pageable
);
@Query
(
"select a from Accession a where a.taxonomy in ( ?1 )"
)
Page
<
Accession
>
findByTaxonomy
(
Collection
<
Taxonomy
>
taxonomies
,
Pageable
pageable
);
Page
<
Accession
>
findByTaxonomy
(
Collection
<
Taxonomy
2
>
taxonomies
,
Pageable
pageable
);
Accession
findByInstituteCodeAndAccessionName
(
String
instCode
,
String
accessionName
);
...
...
@@ -109,4 +112,6 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query
(
"update Accession a set a.inSvalbard = true where a in ?1"
)
void
setInSvalbard
(
List
<
Accession
>
matching
);
Page
<
Accession
>
findByInstituteAndTaxSpecies
(
FaoInstitute
institute
,
long
taxSpecies
,
Pageable
pageable
);
}
src/main/java/org/genesys2/server/persistence/domain/CropTaxonomyRepository.java
View file @
b52fcf56
...
...
@@ -39,6 +39,7 @@ public interface CropTaxonomyRepository extends JpaRepository<CropTaxonomy, Long
Page
<
CropTaxonomy
>
findByCrop
(
Crop
crop
,
Pageable
pageable
);
// TODO FIXME todo
@Query
(
"select distinct t from CropTaxonomy ct inner join ct.taxonomy t where ct.crop = ?1"
)
List
<
Taxonomy
>
findTaxonomiesByCrop
(
Crop
crop
);
...
...
src/main/java/org/genesys2/server/persistence/domain/GenesysLowlevelRepository.java
View file @
b52fcf56
...
...
@@ -51,4 +51,5 @@ public interface GenesysLowlevelRepository {
void
listAccessionsAccenames
(
RowCallbackHandler
rowCallbackHandler
);
void
listAccessionsAlias
(
RowCallbackHandler
rowCallbackHandler
);
}
src/main/java/org/genesys2/server/persistence/domain/Taxonomy2Repository.java
View file @
b52fcf56
...
...
@@ -31,6 +31,5 @@ public interface Taxonomy2Repository extends JpaRepository<Taxonomy2, Long> {
@Query
(
"select distinct t.taxonName from Taxonomy2 t where t.taxonName like ?1"
)
List
<
String
>
autocompleteTaxonomy
(
String
term
,
Pageable
page
);
@Query
(
"select t from Taxonomy2 t where t.genus=?1 and t.species=?2 and t.spAuthor=?3 and t.subtaxa=?4 and t.subtAuthor=?5"
)
Taxonomy2
findOne
(
String
genus
,
String
species
,
String
spAuthor
,
String
subtaxa
,
String
subtAuthor
);
Taxonomy2
findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor
(
String
genus
,
String
species
,
String
spAuthor
,
String
subtaxa
,
String
subtAuthor
);
}
src/main/java/org/genesys2/server/persistence/domain/TaxonomyRepository.java
View file @
b52fcf56
...
...
@@ -19,8 +19,10 @@ package org.genesys2.server.persistence.domain;
import
java.util.List
;
import
org.genesys2.server.model.genesys.Taxonomy
;
import
org.genesys2.server.model.genesys.Taxonomy2
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
public
interface
TaxonomyRepository
extends
JpaRepository
<
Taxonomy
,
Long
>
{
...
...
@@ -35,4 +37,8 @@ public interface TaxonomyRepository extends JpaRepository<Taxonomy, Long> {
@Query
(
"select distinct t.taxonName from Taxonomy t where t.taxonName like ?1"
)
List
<
String
>
autocompleteTaxonomy
(
String
term
,
Pageable
page
);
@Modifying
@Query
(
"update Accession a set a.taxonomy=?2, a.taxGenus=?3, a.taxSpecies=?4 where a.taxonomy1 = ?1"
)
int
upgrade
(
Taxonomy
t1
,
Taxonomy2
t2
,
Long
taxGenus
,
Long
taxSpecies
);
}
src/main/java/org/genesys2/server/service/GenesysService.java
View file @
b52fcf56
...
...
@@ -34,7 +34,6 @@ import org.genesys2.server.model.genesys.ExperimentTrait;
import
org.genesys2.server.model.genesys.Metadata
;
import
org.genesys2.server.model.genesys.Method
;
import
org.genesys2.server.model.genesys.SvalbardData
;
import
org.genesys2.server.model.genesys.Taxonomy
;
import
org.genesys2.server.model.impl.AccessionIdentifier3
;
import
org.genesys2.server.model.impl.Country
;
import
org.genesys2.server.model.impl.Crop
;
...
...
@@ -103,9 +102,9 @@ public interface GenesysService {
// Page<Object[]> statisticsCropByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page
<
Accession
>
listAccessionsByInstituteAnd
Taxonomy
(
FaoInstitute
institute
,
Taxonomy
taxonomy
,
Pageable
pageable
);
Page
<
Accession
>
listAccessionsByInstituteAnd
Species
(
FaoInstitute
institute
,
long
taxSpecies
,
Pageable
pageable
);
Page
<
Accession
>
listAccessionsByTax
onomy
(
Taxonomy
taxonomy
,
Pageable
pageable
);
Page
<
Accession
>
listAccessionsByTax
Species
(
long
taxSpeciesId
,
Pageable
pageable
);
Page
<
Accession
>
listAccessionsByGenus
(
String
genus
,
Pageable
pageable
);
...
...
src/main/java/org/genesys2/server/service/TaxonomyService.java
View file @
b52fcf56
...
...
@@ -25,9 +25,8 @@ public interface TaxonomyService {
Taxonomy
get
(
String
genus
,
String
species
);
Taxonomy
ensureTaxonomy
(
String
genus
,
String
species
);
// , String
// fullTaxa);
Taxonomy
ensureTaxonomy
(
String
genus
,
String
species
);
List
<
String
>
autocompleteGenus
(
String
term
);
List
<
String
>
autocompleteTaxonomy
(
String
term
);
...
...
@@ -38,4 +37,10 @@ public interface TaxonomyService {
Taxonomy2
ensureTaxonomy2
(
String
genus
,
String
species
,
String
spAuthor
,
String
subtaxa
,
String
subtAuthor
);
long
countTaxonomy2
();
List
<
Taxonomy
>
findAll
();
long
upgradeTaxonomy
(
Taxonomy
t1
,
Taxonomy2
t2
);
}
src/main/java/org/genesys2/server/service/impl/GenesysFilterServiceImpl.java
View file @
b52fcf56
...
...
@@ -70,6 +70,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
@Service
@Transactional
(
readOnly
=
true
)
// FIXME TODO Change taxonomy to taxonomy2
public
class
GenesysFilterServiceImpl
implements
GenesysFilterService
{
private
static
final
Log
LOG
=
LogFactory
.
getLog
(
GenesysFilterServiceImpl
.
class
);
...
...
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
View file @
b52fcf56
...
...
@@ -53,7 +53,7 @@ import org.genesys2.server.model.genesys.Method;
import
org.genesys2.server.model.genesys.Parameter
;
import
org.genesys2.server.model.genesys.ParameterCategory
;
import
org.genesys2.server.model.genesys.SvalbardData
;
import
org.genesys2.server.model.genesys.Taxonomy
;
import
org.genesys2.server.model.genesys.Taxonomy
2
;
import
org.genesys2.server.model.genesys.TraitCode
;
import
org.genesys2.server.model.impl.AccessionIdentifier3
;
import
org.genesys2.server.model.impl.Country
;
...
...
@@ -367,13 +367,13 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
}
@Override
public
Page
<
Accession
>
listAccessionsByInstituteAnd
Taxonomy
(
FaoInstitute
institute
,
Taxonomy
taxonomy
,
Pageable
pageable
)
{
return
accessionRepository
.
findByInstituteAndTax
onomy
(
institute
,
tax
onomy
,
pageable
);
public
Page
<
Accession
>
listAccessionsByInstituteAnd
Species
(
FaoInstitute
institute
,
long
taxSpecies
,
Pageable
pageable
)
{
return
accessionRepository
.
findByInstituteAndTax
Species
(
institute
,
tax
Species
,
pageable
);
}
@Override
public
Page
<
Accession
>
listAccessionsByTax
onomy
(
Taxonomy
taxonomy
,
Pageable
pageable
)
{
return
accessionRepository
.
findByTax
onomy
(
taxonomy
,
pageable
);
public
Page
<
Accession
>
listAccessionsByTax
Species
(
long
taxSpecies
,
Pageable
pageable
)
{
return
accessionRepository
.
findByTax
Species
(
taxSpecies
,
pageable
);
}
@Override
...
...
@@ -389,7 +389,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
public
Page
<
Accession
>
listAccessionsByCrop
(
Crop
crop
,
Pageable
pageable
)
{
List
<
Taxonomy
>
taxonomies
=
cropTaxonomyRepository
.
findTaxonomiesByCrop
(
crop
);
List
<
Taxonomy
2
>
taxonomies
=
null
;
// FIXME TODO
cropTaxonomyRepository.findTaxonomiesByCrop(crop);
if
(
taxonomies
==
null
||
taxonomies
.
size
()
==
0
)
{
return
null
;
}
...
...
src/main/java/org/genesys2/server/service/impl/TaxonomyServiceImpl.java
View file @
b52fcf56
...
...
@@ -19,6 +19,7 @@ package org.genesys2.server.service.impl;
import
java.util.List
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang3.text.WordUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.genesys2.server.model.genesys.Taxonomy
;
...
...
@@ -39,6 +40,7 @@ public class TaxonomyServiceImpl implements TaxonomyService {
@Autowired
private
TaxonomyRepository
taxonomyRepository
;
@Autowired
private
Taxonomy2Repository
taxonomy2Repository
;
@Override
...
...
@@ -62,14 +64,16 @@ public class TaxonomyServiceImpl implements TaxonomyService {
Taxonomy
taxonomy
=
taxonomyRepository
.
getByGenusAndSpecies
(
genus
,
species
);
if
(
taxonomy
==
null
)
{
taxonomy
=
new
Taxonomy
();
LOG
.
warn
(
"Inserting "
+
genus
+
" "
+
species
);
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Inserting "
+
genus
+
" "
+
species
);
taxonomy
.
setGenus
(
genus
);
taxonomy
.
setSpecies
(
species
);
taxonomy
.
setTaxonName
((
genus
+
" "
+
StringUtils
.
defaultIfEmpty
(
species
,
""
)).
trim
());
try
{
taxonomyRepository
.
save
(
taxonomy
);
LOG
.
warn
(
"Inserted new:"
+
taxonomy
);
LOG
.
info
(
"Inserted new:"
+
taxonomy
);
// TODO Should update crop taxonomy lists?
...
...
@@ -91,16 +95,36 @@ public class TaxonomyServiceImpl implements TaxonomyService {
}
@Override
// @Transactional(noRollbackFor = AssertionFailure.class)
@Transactional
public
Taxonomy2
ensureTaxonomy2
(
String
genus
,
String
species
,
String
spAuthor
,
String
subtaxa
,
String
subtAuthor
)
{
if
(
species
==
null
&&
spAuthor
!=
null
)
{
if
(
StringUtils
.
isBlank
(
genus
))
{
throw
new
RuntimeException
(
"Genus can't be blank"
);
}
// Capitalize
genus
=
WordUtils
.
capitalizeFully
(
genus
);
species
=
StringUtils
.
defaultIfBlank
(
species
,
"sp."
);
species
=
species
.
toLowerCase
();
spAuthor
=
StringUtils
.
defaultIfBlank
(
spAuthor
,
null
);
subtaxa
=
StringUtils
.
defaultIfBlank
(
subtaxa
,
null
);
if
(
subtaxa
!=
null
)
subtaxa
=
subtaxa
.
toLowerCase
();
subtAuthor
=
StringUtils
.
defaultIfBlank
(
subtAuthor
,
null
);
if
(
StringUtils
.
equalsIgnoreCase
(
species
.
trim
(),
"sp"
))
{
species
=
"sp."
;
}
if
(
subtaxa
==
null
&&
subtAuthor
!=
null
)
{
if
(
StringUtils
.
isNotBlank
(
species
)
&&
!
StringUtils
.
equals
(
species
,
"sp."
)
&&
StringUtils
.
isBlank
(
subtaxa
))
{
subtaxa
=
"subsp."
;
}
Taxonomy2
existing
=
taxonomy2Repository
.
find
One
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
Taxonomy2
existing
=
taxonomy2Repository
.
find
ByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
if
(
existing
==
null
)
{
return
internalEnsure
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
}
...
...
@@ -108,12 +132,26 @@ 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
))
{
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
);
}
// Loop it a bit if required
for
(
int
i
=
5
;
i
>
0
;
i
--)
{
Taxonomy2
taxonomy
=
taxonomy2Repository
.
findOne
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
Taxonomy2
taxonomy
=
null
;
try
{
taxonomy
=
taxonomy2Repository
.
findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor
(
genus
,
species
,
spAuthor
,
subtaxa
,
subtAuthor
);
}
catch
(
Throwable
e
)
{
// is null
e
.
printStackTrace
();
}
if
(
taxonomy
==
null
)
{
taxonomy
=
new
Taxonomy2
();
LOG
.
warn
(
"Inserting new taxonomy"
);
taxonomy
.
setGenus
(
genus
);
taxonomy
.
setSpecies
(
species
);
taxonomy
.
setSpAuthor
(
spAuthor
);
...
...
@@ -121,35 +159,31 @@ public class TaxonomyServiceImpl implements TaxonomyService {
taxonomy
.
setSubtAuthor
(
subtAuthor
);
try
{
taxonomy
=
taxonomy2Repository
.
save
(
taxonomy
);
LOG
.
warn
(
"Inserted new:"
+
taxonomy
);
if
(!
StringUtils
.
equals
(
species
,
"sp."
)
&&
spAuthor
!=
null
&&
subtaxa
!=
null
&&
subtAuthor
!=
null
)
{
Taxonomy2
genusTaxa
=
internalEnsure
(
genus
,
"sp."
,
null
,
null
,
null
);
if
(
genusTaxa
!=
null
)
{
taxonomy
.
setTaxGenus
(
genusTaxa
.
getId
());
if
(
species
!=
null
&&
subtaxa
!=
null
&&
!
StringUtils
.
equals
(
subtaxa
,
"subsp."
)
&&
subtAuthor
!=
null
)
{
Taxonomy2
speciesTaxa
=
internalEnsure
(
genus
,
species
,
null
,
"subsp."
,
null
);
taxonomy
.
setTaxSpecies
(
speciesTaxa
.
getId
());
}
else
{
// No species taxonomy
}
}
else
{
taxonomy
=
taxonomy2Repository
.
save
(
taxonomy
);
taxonomy
.
setTaxGenus
(
taxonomy
.
getId
());
}
if
(
speciesTaxa
!=
null
)
{
taxonomy
.
setTaxSpecies
(
speciesTaxa
.
getId
());
}
else
{
taxonomy
=
taxonomy2Repository
.
save
(
taxonomy
);
taxonomy
.
setTaxSpecies
(
taxonomy
.
getId
());
}
taxonomy
=
taxonomy2Repository
.
save
(
taxonomy
);
// TODO Should update crop taxonomy lists?
return
taxonomy
;
}
catch
(
Throwable
e
)
{
LOG
.
warn
(
"Error "
+
e
.
getMessage
()
+
" :"
+
taxonomy
);
continue
;
}
}
return
taxonomy
;
}
// Should not get here!
...
...
@@ -158,11 +192,29 @@ public class TaxonomyServiceImpl implements TaxonomyService {
@Override
public
long
getTaxonomy2Id
(
String
genus
)
{
return
taxonomy2Repository
.
find
One
(
genus
,
"sp."
,
null
,
null
,
null
).
getId
();
return
taxonomy2Repository
.
find
ByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor
(
genus
,
"sp."
,
null
,
null
,
null
).
getId
();
}
@Override
public
long
getTaxonomy2Id
(
String
genus
,
String
species
)
{
return
taxonomy2Repository
.
findOne
(
genus
,
species
,
null
,
"subsp."
,
null
).
getId
();
Taxonomy2
tax
=
taxonomy2Repository
.
findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor
(
genus
,
species
,
null
,
"subsp."
,
null
);
System
.
err
.
println
(
"tax2="
+
tax
);
return
tax
.
getId
();
}
@Override
public
long
countTaxonomy2
()
{
return
taxonomy2Repository
.
count
();
}
@Override
public
List
<
Taxonomy
>
findAll
()
{
return
taxonomyRepository
.
findAll
();
}
@Override
@Transactional
public
long
upgradeTaxonomy
(
Taxonomy
t1
,
Taxonomy2
t2
)
{
return
taxonomyRepository
.
upgrade
(
t1
,
t2
,
t2
.
getTaxGenus
(),
t2
.
getTaxSpecies
());
}
}
src/main/java/org/genesys2/server/servlet/controller/AccessionController.java
View file @
b52fcf56
...
...
@@ -20,7 +20,6 @@ import java.util.HashMap;
import
java.util.List
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.model.genesys.Taxonomy
;
import
org.genesys2.server.model.impl.FaoInstitute
;
import
org.genesys2.server.service.CropService
;
import
org.genesys2.server.service.GenesysService
;
...
...
@@ -159,22 +158,19 @@ public class AccessionController extends BaseController {
@RequestParam
(
value
=
"page"
,
required
=
false
,
defaultValue
=
"1"
)
int
page
)
{
// Taxonomy
Taxonomy
taxonomy
=
taxonomyService
.
get
(
genus
,
species
);
long
taxSpeciesId
=
taxonomyService
.
get
Taxonomy2Id
(
genus
,
species
);
HashMap
<
Object
,
Object
>
filters
=
new
HashMap
<
Object
,
Object
>();
model
.
addAttribute
(
"filters"
,
filters
);
_logger
.
debug
(
"Got "
+
taxonomy
);
filters
.
put
(
"filter.taxonomy"
,
taxonomy
);
filters
.
put
(
"filter.taxonomy"
,
taxSpeciesId
);
Page
<
Accession
>
accessions
=
genesysService
.
listAccessionsByTax
onomy
(
taxonomy
,
new
PageRequest
(
page
-
1
,
50
,
new
Sort
(
"accessionName"
)));
Page
<
Accession
>
accessions
=
genesysService
.
listAccessionsByTax
Species
(
taxSpeciesId
,
new
PageRequest
(
page
-
1
,
50
,
new
Sort
(
"accessionName"
)));
_logger
.
info
(
"Got: "
+
accessions
);
model
.
addAttribute
(
"pagedData"
,
accessions
);
if
(
taxonomy
!=
null
)
{