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
57a0e4e6
Commit
57a0e4e6
authored
Oct 07, 2015
by
Matija Obreza
Browse files
URL Shortener cleanup, parameter check, license info
parent
c9489362
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/service/UrlShortenerService.java
View file @
57a0e4e6
/**
* Copyright 2015 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.service
;
import
java.net.URL
;
public
interface
UrlShortenerService
{
String
reduceUrl
(
String
fullUrl
);
String
shortenUrl
(
URL
url
);
}
src/main/java/org/genesys2/server/service/impl/GoogleURLShortener.java
View file @
57a0e4e6
/**
* Copyright 2015 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.service.impl
;
import
org.genesys2.server.service.UrlShortenerService
;
...
...
@@ -9,6 +25,7 @@ import org.springframework.social.support.ClientHttpRequestFactorySelector;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
java.net.URL
;
import
java.util.*
;
@Component
...
...
@@ -32,10 +49,10 @@ public class GoogleURLShortener implements UrlShortenerService {
}
@Override
public
String
reduceUrl
(
String
longU
rl
)
{
public
String
shortenUrl
(
URL
u
rl
)
{
Map
<
String
,
String
>
request
=
new
HashMap
<
String
,
String
>();
request
.
put
(
"longUrl"
,
longUrl
);
request
.
put
(
"longUrl"
,
url
.
toString
()
);
LinkedHashMap
<
String
,
String
>
shortUrl
=
restTemplate
.
postForObject
(
googleUrlShortener
+
"?key="
+
apiKey
,
request
,
LinkedHashMap
.
class
);
return
shortUrl
.
get
(
"id"
);
...
...
src/main/java/org/genesys2/server/servlet/controller/ExplorerController.java
View file @
57a0e4e6
/**
* Copyright 201
4
Global Crop Diversity Trust
* Copyright 201
5
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.
...
...
@@ -41,7 +41,15 @@ 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.impl.Crop
;
import
org.genesys2.server.service.*
;
import
org.genesys2.server.service.CropService
;
import
org.genesys2.server.service.DownloadService
;
import
org.genesys2.server.service.ElasticService
;
import
org.genesys2.server.service.FilterConstants
;
import
org.genesys2.server.service.GenesysFilterService
;
import
org.genesys2.server.service.GenesysService
;
import
org.genesys2.server.service.MappingService
;
import
org.genesys2.server.service.TraitService
;
import
org.genesys2.server.service.UrlShortenerService
;
import
org.genesys2.server.service.impl.FilterHandler
;
import
org.genesys2.server.service.impl.FilterHandler.AppliedFilter
;
import
org.genesys2.server.service.impl.FilterHandler.AppliedFilters
;
...
...
@@ -103,9 +111,6 @@ public class ExplorerController extends BaseController {
@Value
(
"${base.url}"
)
private
String
baseUrl
;
@Value
(
"${browse.url}"
)
private
String
browsePath
;
/**
* Redirect to /explore/c/{shortName} if parameter 'crop' is provided
*/
...
...
@@ -530,18 +535,22 @@ public class ExplorerController extends BaseController {
model
.
addAttribute
(
"statsSampStat"
,
elasticService
.
termStatisticsAuto
(
appliedFilters
,
FilterConstants
.
SAMPSTAT
,
30
));
}
@RequestMapping
(
value
=
"/explore/
getBriefURL
"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@RequestMapping
(
value
=
"/explore/
shorten-url
"
,
method
=
RequestMethod
.
POST
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
@ResponseBody
public
String
getBriefURL
(
@RequestParam
(
value
=
"filter"
,
required
=
false
,
defaultValue
=
""
)
String
filter
)
throws
IOException
,
URISyntaxException
{
public
Object
getBriefURL
(
@RequestParam
(
value
=
"filter"
,
required
=
false
,
defaultValue
=
""
)
String
jsonFilter
,
@RequestParam
(
value
=
"page"
,
required
=
false
,
defaultValue
=
"1"
)
int
page
)
throws
IOException
,
URISyntaxException
{
AppliedFilters
appliedFilters
=
mapper
.
readValue
(
jsonFilter
,
AppliedFilters
.
class
);
URI
longUrl
=
new
URIBuilder
(
baseUrl
)
.
setPath
(
browsePath
)
.
addParameter
(
"filter"
,
filter
)
URI
longUrl
=
new
URIBuilder
(
baseUrl
).
setPath
(
"/explore"
).
addParameter
(
"filter"
,
appliedFilters
.
toString
()).
addParameter
(
"page"
,
Integer
.
toString
(
page
))
.
build
();
String
shortUrl
=
urlShortenerService
.
reduce
Url
(
longUrl
.
to
String
());
final
String
short
ened
Url
=
urlShortenerService
.
shorten
Url
(
longUrl
.
to
URL
());
return
"{\"shortUrl\":\""
+
shortUrl
+
"\"}"
;
return
new
Object
()
{
@SuppressWarnings
(
"unused"
)
public
String
shortUrl
=
shortenedUrl
;
};
}
}
src/main/resources/spring/spring.properties
View file @
57a0e4e6
...
...
@@ -34,7 +34,6 @@ hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
google.api.key
=
AIzaSyBEvPuc8j5ps5GDQ3tdnTJaffKhfOdxFVc
google.url.shortener
=
https://www.googleapis.com/urlshortener/v1/url
browse.url
=
/explore
c3p0.acquireIncrement
=
1
c3p0.minPoolSize
=
1
...
...
src/main/webapp/WEB-INF/jsp/accession/explore.jsp
View file @
57a0e4e6
...
...
@@ -434,9 +434,9 @@
$
(
"
#menuShareLink
"
).
on
(
"
click
"
,
function
()
{
$
.
ajax
({
type
:
'
POST
'
,
url
:
'
/explore/
getBriefURL
'
,
url
:
'
/explore/
shorten-url
'
,
data
:
{
'
filter
'
:
JSON
.
stringify
(
jsonData
)
'
page
'
:
$
{
pagedData
.
number
+
1
},
'
filter
'
:
JSON
.
stringify
(
jsonData
)
},
success
:
function
(
response
)
{
var
inp
=
$
(
"
#shortLink
"
);
...
...
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