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
611c201d
Commit
611c201d
authored
Mar 19, 2014
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lookup controller and country JSON serializer
parent
3023a192
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
0 deletions
+107
-0
src/main/java/org/genesys2/server/model/impl/Country.java
src/main/java/org/genesys2/server/model/impl/Country.java
+3
-0
src/main/java/org/genesys2/server/servlet/controller/rest/LookupController.java
...sys2/server/servlet/controller/rest/LookupController.java
+76
-0
src/main/java/org/genesys2/server/servlet/controller/rest/serialization/CountrySerializer.java
...vlet/controller/rest/serialization/CountrySerializer.java
+28
-0
No files found.
src/main/java/org/genesys2/server/model/impl/Country.java
View file @
611c201d
...
...
@@ -32,17 +32,20 @@ import javax.persistence.Table;
import
javax.persistence.Transient
;
import
org.genesys2.server.model.BusinessModel
;
import
org.genesys2.server.servlet.controller.rest.serialization.CountrySerializer
;
import
org.hibernate.search.annotations.Field
;
import
org.hibernate.search.annotations.Indexed
;
import
org.hibernate.search.annotations.Store
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.annotation.JsonSerialize
;
@Entity
@Table
(
name
=
"country"
)
// TODO Fix indexer by i18n names!
@Indexed
@JsonSerialize
(
using
=
CountrySerializer
.
class
)
public
class
Country
extends
BusinessModel
{
private
static
final
long
serialVersionUID
=
-
1688723909298769804L
;
...
...
src/main/java/org/genesys2/server/servlet/controller/rest/LookupController.java
0 → 100644
View file @
611c201d
/**
* 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.servlet.controller.rest
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
org.apache.commons.lang3.StringUtils
;
import
org.genesys2.server.model.impl.Country
;
import
org.genesys2.server.service.GenesysService
;
import
org.genesys2.server.service.GeoService
;
import
org.genesys2.server.service.InstituteService
;
import
org.genesys2.server.service.TaxonomyService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
@Controller
@PreAuthorize
(
"isAuthenticated()"
)
@RequestMapping
(
value
=
{
"/api/v0/lookup"
,
"/json/v0/lookup"
})
public
class
LookupController
extends
RestController
{
@Autowired
GenesysService
genesysService
;
@Autowired
InstituteService
instituteService
;
@Autowired
GeoService
geoService
;
@Autowired
TaxonomyService
taxonomyService
;
@RequestMapping
(
value
=
"/orgCty"
,
method
=
{
RequestMethod
.
GET
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
@ResponseBody
Map
<
String
,
String
>
get
(
@RequestParam
(
value
=
"lang"
,
required
=
false
,
defaultValue
=
""
)
String
lang
)
{
Map
<
String
,
String
>
orgCty
=
new
TreeMap
<
String
,
String
>();
List
<
Country
>
list
=
null
;
if
(
StringUtils
.
isNotBlank
(
lang
))
{
Locale
locale
=
new
Locale
(
lang
);
list
=
geoService
.
listAll
(
locale
);
for
(
Country
c
:
list
)
{
orgCty
.
put
(
c
.
getCode3
(),
c
.
getName
(
locale
));
}
}
else
{
list
=
geoService
.
listAll
();
for
(
Country
c
:
list
)
{
orgCty
.
put
(
c
.
getCode3
(),
c
.
getName
());
}
}
return
orgCty
;
}
}
src/main/java/org/genesys2/server/servlet/controller/rest/serialization/CountrySerializer.java
0 → 100644
View file @
611c201d
package
org.genesys2.server.servlet.controller.rest.serialization
;
import
java.io.IOException
;
import
org.genesys2.server.model.impl.Country
;
import
com.fasterxml.jackson.core.JsonGenerator
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonSerializer
;
import
com.fasterxml.jackson.databind.SerializerProvider
;
public
class
CountrySerializer
extends
JsonSerializer
<
Country
>
{
@Override
public
void
serialize
(
Country
country
,
JsonGenerator
jgen
,
SerializerProvider
sp
)
throws
IOException
,
JsonProcessingException
{
if
(
country
==
null
)
{
jgen
.
writeNull
();
}
else
{
jgen
.
writeStartObject
();
jgen
.
writeObjectField
(
"code"
,
country
.
getCode3
());
jgen
.
writeObjectField
(
"name"
,
country
.
getName
());
jgen
.
writeObjectField
(
"refnameId"
,
country
.
getRefnameId
());
jgen
.
writeObjectField
(
"current"
,
country
.
isCurrent
());
jgen
.
writeEndObject
();
}
}
}
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