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
a4d50529
Commit
a4d50529
authored
Dec 12, 2017
by
Maxym Borodenko
Browse files
Crop page as JSON
parent
24a68712
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/servlet/controller/CropController.java
View file @
a4d50529
...
...
@@ -23,6 +23,8 @@ import java.util.List;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.elasticsearch.common.lang3.StringUtils
;
import
org.genesys2.server.model.impl.Crop
;
import
org.genesys2.server.model.impl.CropRule
;
...
...
@@ -42,9 +44,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.ModelMap
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
...
@@ -55,6 +59,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.springframework.web.bind.annotation.ResponseBody
;
@Controller
@RequestMapping
(
"/c"
)
...
...
@@ -91,6 +96,27 @@ public class CropController extends BaseController {
return
"/crop/list"
;
}
@GetMapping
(
value
=
"/"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
@ResponseBody
ObjectNode
statistics
()
{
LOG
.
debug
(
"Fetching statistics of crops."
);
final
ObjectMapper
mapper
=
new
ObjectMapper
();
final
ObjectNode
mainNode
=
mapper
.
createObjectNode
();
final
ArrayNode
arrayNode
=
mapper
.
createArrayNode
();
final
List
<
Crop
>
cropList
=
cropService
.
list
(
getLocale
());
for
(
final
Crop
crop
:
cropList
)
{
final
ObjectNode
objectNode
=
mapper
.
createObjectNode
();
objectNode
.
put
(
"crop"
,
crop
.
getShortName
());
objectNode
.
put
(
"count"
,
genesysService
.
countByCrop
(
crop
));
arrayNode
.
add
(
objectNode
);
}
mainNode
.
set
(
"crops"
,
arrayNode
);
mainNode
.
put
(
"numberOfCountries"
,
statisticsService
.
numberOfCountries
());
mainNode
.
put
(
"numberOfInstitutes"
,
statisticsService
.
numberOfInstitutes
());
mainNode
.
put
(
"numberOfActiveAccessions"
,
statisticsService
.
numberOfActiveAccessions
());
return
mainNode
;
}
@RequestMapping
(
"/{shortName}"
)
public
String
view
(
ModelMap
model
,
@PathVariable
(
value
=
"shortName"
)
String
shortName
)
{
LOG
.
debug
(
"Viewing crop {}"
,
shortName
);
...
...
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