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
04ede25e
Commit
04ede25e
authored
Oct 19, 2015
by
Matija Obreza
Browse files
FAO Regions cleanup
parent
c0b364eb
Changes
8
Hide whitespace changes
Inline
Side-by-side
TODO.md
View file @
04ede25e
...
...
@@ -14,7 +14,7 @@
-
Use DS to hold results of calculation, similar to worldclim DS
-
Re-calculation needs to happen after any update to Accession or AccessionRelated (same as ES update)
-
PDCI dataset is downloadable as Excel
(
for selected accessions
)
-
PDCI dataset is downloadable as Excel
: this works on institute level, but not
for selected accessions
-
WorldClim dataset is downloadable as Excel (for selected accessions)
# TODO Accession Lists
...
...
src/main/java/org/genesys2/server/model/impl/GeoRegion.java
View file @
04ede25e
package
org.genesys2.server.model.impl
;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
import
java.util.Locale
;
import
javax.persistence.Cacheable
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.FetchType
;
...
...
@@ -22,6 +25,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@Entity
@Table
(
name
=
"georegion"
)
@Cacheable
public
class
GeoRegion
extends
VersionedModel
{
private
static
final
long
serialVersionUID
=
-
1L
;
...
...
@@ -114,4 +118,13 @@ public class GeoRegion extends VersionedModel {
return
this
.
nameJ
!=
null
&&
this
.
nameJ
.
has
(
locale
.
getLanguage
())
?
this
.
nameJ
.
get
(
locale
.
getLanguage
()).
textValue
()
:
this
.
name
;
}
public
static
void
sort
(
List
<
GeoRegion
>
all
,
Locale
locale
)
{
Collections
.
sort
(
all
,
new
Comparator
<
GeoRegion
>()
{
@Override
public
int
compare
(
GeoRegion
o1
,
GeoRegion
o2
)
{
return
o1
.
getName
(
locale
).
compareTo
(
o2
.
getName
(
locale
));
}
});
}
}
\ No newline at end of file
src/main/java/org/genesys2/server/persistence/domain/GeoRegionRepository.java
View file @
04ede25e
...
...
@@ -8,7 +8,7 @@ import org.springframework.data.jpa.repository.Query;
public
interface
GeoRegionRepository
extends
JpaRepository
<
GeoRegion
,
Long
>{
@Query
(
"select distinct gr from GeoRegion gr where gr.isoCode = ?1"
)
GeoRegion
find
e
ByIsoCode
(
String
isoCode
);
GeoRegion
findByIsoCode
(
String
isoCode
);
@Query
(
"select c.region from Country c where c = ?1"
)
GeoRegion
findByCountry
(
Country
country
);
...
...
src/main/java/org/genesys2/server/service/impl/GeoRegionServiceImpl.java
View file @
04ede25e
...
...
@@ -37,17 +37,19 @@ public class GeoRegionServiceImpl implements GeoRegionService {
@Override
public
GeoRegion
find
(
String
regionIsoCode
)
{
GeoRegion
geoRegion
=
geoRegionRepository
.
find
e
ByIsoCode
(
regionIsoCode
);
GeoRegion
geoRegion
=
geoRegionRepository
.
findByIsoCode
(
regionIsoCode
);
geoRegion
.
getCountries
().
size
();
return
geoRegion
;
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
save
(
GeoRegion
geoRegion
)
{
geoRegionRepository
.
save
(
geoRegion
);
}
@Override
@Transactional
(
readOnly
=
false
)
public
void
delete
(
GeoRegion
geoRegion
)
{
geoRegionRepository
.
delete
(
geoRegion
);
}
...
...
@@ -121,7 +123,8 @@ public class GeoRegionServiceImpl implements GeoRegionService {
private
boolean
isChild
(
GeoRegion
region
,
String
parentIsoCode
)
{
return
region
.
getParentRegion
()
!=
null
&&
(
region
.
getParentRegion
().
getIsoCode
().
equals
(
parentIsoCode
)
||
isChild
(
region
.
getParentRegion
(),
parentIsoCode
));
return
region
.
getParentRegion
()
!=
null
&&
(
region
.
getParentRegion
().
getIsoCode
().
equals
(
parentIsoCode
)
||
isChild
(
region
.
getParentRegion
(),
parentIsoCode
));
}
}
src/main/java/org/genesys2/server/servlet/controller/GeoRegionController.java
View file @
04ede25e
package
org.genesys2.server.servlet.controller
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
org.genesys2.server.model.impl.Country
;
import
org.genesys2.server.model.impl.GeoRegion
;
import
org.genesys2.server.persistence.domain.CountryRepository
;
import
org.genesys2.server.service.GeoRegionService
;
import
org.genesys2.spring.ResourceNotFoundException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.ModelMap
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
java.util.List
;
@Controller
@RequestMapping
(
"/geo/regions"
)
...
...
@@ -37,40 +39,23 @@ public class GeoRegionController extends BaseController {
if
(
geoRegion
==
null
)
{
_logger
.
error
(
"Can't find region for region code "
+
code
);
return
"redirect:/geo/regions"
;
throw
new
ResourceNotFoundException
(
"Can't find region for region code "
+
code
)
;
}
if
(
geoRegion
.
getCountries
().
size
()==
0
){
_logger
.
info
(
"Redirect for geoRegion "
+
geoRegion
.
getName
()
+
" to the list page"
);
return
"redirect:/geo/regions/list/"
+
code
;
}
List
<
Country
>
countryList
=
geoRegion
.
getCountries
();
List
<
Country
>
countryList
=
geoRegion
.
getCountries
().
stream
().
filter
(
country
->
isCurrent
(
country
)).
collect
(
Collectors
.
toList
());
Country
.
sort
(
countryList
,
getLocale
());
model
.
addAttribute
(
"region"
,
geoRegion
);
List
<
GeoRegion
>
subRegions
=
geoRegionService
.
getChildren
(
geoRegion
.
getIsoCode
());
GeoRegion
.
sort
(
subRegions
,
getLocale
());
model
.
addAttribute
(
"subRegions"
,
subRegions
);
model
.
addAttribute
(
"countries"
,
countryList
);
model
.
addAttribute
(
"parent"
,
geoRegion
.
getParentRegion
().
getIsoCode
());
return
"/region/region"
;
}
@RequestMapping
(
"/list/{isoCode}"
)
public
String
viewRegionList
(
ModelMap
model
,
@PathVariable
(
value
=
"isoCode"
)
String
code
)
{
GeoRegion
geoRegion
=
geoRegionService
.
find
(
code
);
if
(
geoRegion
==
null
)
{
_logger
.
error
(
"Can't find region for region code "
+
code
);
return
"redirect:/geo/regions"
;
}
if
(
geoRegion
.
getCountries
().
size
()
>
0
)
{
_logger
.
info
(
"Redirect for geoRegion "
+
geoRegion
.
getName
()
+
" to the region page"
);
return
"redirect:/geo/regions"
;
}
model
.
addAttribute
(
"isoCode"
,
code
);
return
"/region/index"
;
}
private
boolean
isCurrent
(
Country
country
)
{
return
country
.
isCurrent
();
}
}
src/main/resources/content/language.properties
View file @
04ede25e
...
...
@@ -726,7 +726,10 @@ userlist.disconnect=Disconnect list
userlist.update-list
=
Save updated list
userlist.make-new-list
=
Create new list
region.page.list.title
=
R
egions
#
region.page.list.intro =
region.page.show.parent
=
Show parent region
region.page.list.title
=
FAO Geographical r
egions
region.page.list.intro
=
FAO Geographical regions lists below allow you to access the data about accessions collected or maintained in the region.
region.page.show.parent
=
Show parent region
{0}
region.page.show.world
=
Show all world regions
region.countries-in-region
=
List of countries in {0}
region.regions-in-region
=
FAO Regions in {0}
region.show-all-regions
=
List all FAO regions
src/main/webapp/WEB-INF/jsp/region/index.jsp
View file @
04ede25e
...
...
@@ -10,17 +10,8 @@
<cms:informative
-h1 title="region.page.list.title" fancy="true" info="region.page.list.intro"
/>
<c:set
var=
"url"
value=
"/${pageContext.response.locale}/json/v0/geo/regions${not empty isoCode? '/'.concat(isoCode) :''}"
/>
<h4>
<c:if
test=
"
${
not
empty
isoCode
}
"
>
<a
href=
"
<c:url
value=
"/geo/regions"
/>
"
><span
class=
"glyphicon glyphicon-eye-open"
></span><span><spring:message
code=
"region.page.show.world"
/></span></a>
</c:if>
</h4>
<div
class=
"main-col-header clearfix"
>
<div
class=
"nav-header pull-left"
>
<div
id=
"regionTree"
></div>
</div>
</div>
<div
id=
"regionTree"
></div>
<content
tag=
"javascript"
>
<%--<script src="<c:url value="/html/js/jstree.min.js" />"></script>--%>
...
...
src/main/webapp/WEB-INF/jsp/region/region.jsp
View file @
04ede25e
...
...
@@ -4,20 +4,44 @@
<html>
<head>
<title><
spring:message
code=
"country.page.list.title"
/></title>
<title><
c:out
value=
"
${
region
.
getName
(
pageContext
.
response
.
locale
)
}
"
/></title>
</head>
<body>
<cms:informative
-h1 title="country.page.list.title" fancy="true" info="country.page.list.intro"
/>
<h1>
<c:out
value=
"
${
region
.
getName
(
pageContext
.
response
.
locale
)
}
"
/>
</h1>
<h4>
<a
href=
"
<c:url
value=
"/geo/regions/${parent}"
/>
"
><span
class=
"glyphicon glyphicon-eye-open"
></span><span><spring:message
code=
"region.page.show.parent"
/></span></a>
</h4>
<div
class=
"results main-col-header"
>
<h4>
<a
class=
"btn btn-default"
href=
"
<c:url
value=
"/geo/regions"
/>
"
><spring:message
code=
"region.show-all-regions"
/></a>
<c:if
test=
"
${
region
.
parentRegion
ne
null
}
"
>
<a
class=
"btn btn-default"
href=
"
<c:url
value=
"/geo/regions/${region.parentRegion.isoCode}"
/>
"
>
<span
class=
"glyphicon glyphicon-eye-open"
></span>
<span>
<spring:message
code=
"region.page.show.parent"
arguments=
"
${
region
.
parentRegion
.
getName
(
pageContext
.
response
.
locale
)
}
"
/>
</span>
</a>
</c:if>
</h4>
</div>
<ul
class=
"funny-list"
>
<c:forEach
items=
"
${
countries
}
"
var=
"country"
varStatus=
"status"
>
<li
class=
"${status.count % 2 == 0 ? 'even' : 'odd'}"
><a
class=
"show ${not country.current ? 'disabled' : ''}"
href=
"
<c:url
value=
"/geo/${country.code3}"
/>
"
><c:out
value=
"
${
country
.
getName
(
pageContext
.
response
.
locale
)
}
"
/></a></li>
</c:forEach>
</ul>
<c:if
test=
"
${
subRegions
ne
null
and
subRegions
.
size
()
gt
0
}
"
>
<h3><spring:message
code=
"region.regions-in-region"
arguments=
"
${
region
.
getName
(
pageContext
.
response
.
locale
)
}
"
/></h3>
<ul
class=
"funny-list"
>
<c:forEach
items=
"
${
subRegions
}
"
var=
"subRegion"
varStatus=
"status"
>
<li
class=
"${status.count % 2 == 0 ? 'even' : 'odd'}"
><a
class=
"show"
href=
"
<c:url
value=
"/geo/regions/${subRegion.isoCode}"
/>
"
><c:out
value=
"
${
subRegion
.
getName
(
pageContext
.
response
.
locale
)
}
"
/></a></li>
</c:forEach>
</ul>
</c:if>
<c:if
test=
"
${
countries
ne
null
and
countries
.
size
()
gt
0
}
"
>
<h3><spring:message
code=
"region.countries-in-region"
arguments=
"
${
region
.
getName
(
pageContext
.
response
.
locale
)
}
"
/></h3>
<ul
class=
"funny-list"
>
<c:forEach
items=
"
${
countries
}
"
var=
"country"
varStatus=
"status"
>
<li
class=
"${status.count % 2 == 0 ? 'even' : 'odd'}"
><a
class=
"show ${not country.current ? 'disabled' : ''}"
href=
"
<c:url
value=
"/geo/${country.code3}"
/>
"
><c:out
value=
"
${
country
.
getName
(
pageContext
.
response
.
locale
)
}
"
/></a></li>
</c:forEach>
</ul>
</c:if>
</body>
</html>
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