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
bf425918
Commit
bf425918
authored
Aug 04, 2017
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DOI resolver for accessions
parent
02eb36bf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
31 deletions
+116
-31
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
.../org/genesys2/server/service/impl/GenesysServiceImpl.java
+11
-10
src/main/java/org/genesys2/server/servlet/controller/AccessionController.java
...nesys2/server/servlet/controller/AccessionController.java
+31
-4
src/main/java/org/genesys2/server/servlet/controller/DoiController.java
...org/genesys2/server/servlet/controller/DoiController.java
+66
-16
src/main/java/org/genesys2/server/servlet/filter/EnvVariablesFilter.java
...rg/genesys2/server/servlet/filter/EnvVariablesFilter.java
+8
-1
No files found.
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
View file @
bf425918
...
...
@@ -285,9 +285,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public
Accession
getAccession
(
AccessionIdentifier3
aid3
)
throws
NonUniqueAccessionException
{
try
{
Accession
accession
=
accessionRepository
.
findOne
(
aid3
.
getHoldingInstitute
(),
aid3
.
getAccessionName
(),
aid3
.
getGenus
());
if
(
accession
!=
null
)
accession
.
getStoRage
().
size
();
return
accession
;
return
lazyLoadAccession
(
accession
);
}
catch
(
IncorrectResultSizeDataAccessException
e
)
{
LOG
.
error
(
"Duplicate accession name instCode="
+
aid3
.
getHoldingInstitute
()
+
" acceNumb="
+
aid3
.
getAccessionName
()
+
" genus="
+
aid3
.
getGenus
());
throw
new
NonUniqueAccessionException
(
aid3
.
getHoldingInstitute
(),
aid3
.
getAccessionName
(),
aid3
.
getGenus
());
...
...
@@ -298,9 +296,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public
Accession
getAccession
(
String
instCode
,
String
acceNumb
)
throws
NonUniqueAccessionException
{
try
{
Accession
accession
=
accessionRepository
.
findByInstituteCodeAndAccessionName
(
instCode
,
acceNumb
);
if
(
accession
!=
null
)
accession
.
getStoRage
().
size
();
return
accession
;
return
lazyLoadAccession
(
accession
);
}
catch
(
IncorrectResultSizeDataAccessException
e
)
{
LOG
.
error
(
"Duplicate accession name instCode="
+
instCode
+
" acceNumb="
+
acceNumb
);
throw
new
NonUniqueAccessionException
(
instCode
,
acceNumb
);
...
...
@@ -314,9 +310,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
try
{
Accession
accession
=
accessionRepository
.
findOne
(
instCode
,
acceNumb
,
genus
);
if
(
accession
!=
null
)
accession
.
getStoRage
().
size
();
return
accession
;
return
lazyLoadAccession
(
accession
);
}
catch
(
IncorrectResultSizeDataAccessException
e
)
{
LOG
.
error
(
"Duplicate accession name instCode="
+
instCode
+
" acceNumb="
+
acceNumb
);
throw
new
NonUniqueAccessionException
(
instCode
,
acceNumb
);
...
...
@@ -338,7 +332,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
public
Accession
getAccessionByDOI
(
final
String
doi
)
{
return
accessionRepository
.
findByDoi
(
doi
);
Accession
accession
=
accessionRepository
.
findByDoi
(
doi
);
return
lazyLoadAccession
(
accession
);
}
private
Accession
lazyLoadAccession
(
Accession
accession
)
{
if
(
accession
!=
null
)
accession
.
getStoRage
().
size
();
return
accession
;
}
@Override
...
...
src/main/java/org/genesys2/server/servlet/controller/AccessionController.java
View file @
bf425918
...
...
@@ -23,6 +23,8 @@ import java.util.ArrayList;
import
java.util.List
;
import
java.util.UUID
;
import
javax.servlet.http.HttpServletResponse
;
import
org.genesys2.server.filerepository.model.ImageGallery
;
import
org.genesys2.server.filerepository.service.ImageGalleryService
;
import
org.genesys2.server.model.dataset.DS
;
...
...
@@ -46,6 +48,8 @@ import org.genesys2.server.service.impl.NonUniqueAccessionException;
import
org.genesys2.server.service.impl.PDCICalculator
;
import
org.genesys2.spring.ResourceNotFoundException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.ModelMap
;
...
...
@@ -54,8 +58,8 @@ 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
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.web.servlet.ModelAndView
;
import
org.springframework.web.servlet.view.RedirectView
;
@Controller
@RequestMapping
(
"/acn"
)
...
...
@@ -92,6 +96,9 @@ public class AccessionController extends BaseController {
@Autowired
private
DownloadService
downloadService
;
@Value
(
"${base.url}"
)
private
String
baseUrl
;
@RequestMapping
(
value
=
"/id/{accessionId}"
,
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
@ResponseBody
AccessionDetails
viewJson
(
ModelMap
model
,
@PathVariable
(
value
=
"accessionId"
)
long
accessionId
)
{
...
...
@@ -103,12 +110,32 @@ public class AccessionController extends BaseController {
}
@RequestMapping
(
value
=
"/id/{accessionId}"
)
public
String
view
(
ModelMap
model
,
@PathVariable
(
value
=
"accessionId"
)
long
accessionId
)
{
public
ModelAndView
view
(
ModelMap
model
,
@PathVariable
(
value
=
"accessionId"
)
long
accessionId
)
{
_logger
.
debug
(
"Viewing ACN "
+
accessionId
);
final
Accession
accession
=
genesysService
.
getAccession
(
accessionId
);
if
(
accession
==
null
)
{
throw
new
ResourceNotFoundException
();
}
if
(
accession
.
getDoi
()
!=
null
)
{
// Permanent HTTP redirect to the DOI URL
RedirectView
rv
=
new
RedirectView
();
rv
.
setStatusCode
(
HttpStatus
.
MOVED_PERMANENTLY
);
rv
.
setUrl
(
baseUrl
+
"/"
+
accession
.
getDoi
());
return
new
ModelAndView
(
rv
);
}
return
displayAccession
(
model
,
accession
);
}
/**
* Load the details to display full accession details page
*
* @param accession
* @return
*/
public
ModelAndView
displayAccession
(
ModelMap
model
,
Accession
accession
)
{
model
.
addAttribute
(
"accession"
,
accession
);
model
.
addAttribute
(
"accessionNames"
,
genesysService
.
listAccessionNames
(
accession
.
getAccessionId
()));
model
.
addAttribute
(
"accessionAliases"
,
genesysService
.
listAccessionAliases
(
accession
.
getAccessionId
()));
...
...
@@ -173,7 +200,7 @@ public class AccessionController extends BaseController {
model
.
addAttribute
(
"imageGallery"
,
imageGallery
);
}
return
"/accession/details"
;
return
new
ModelAndView
(
"/accession/details"
,
model
)
;
}
@RequestMapping
(
"/{holdingInstitute}/{genus}/{accessionName:.+}"
)
...
...
src/main/java/org/genesys2/server/servlet/controller/DoiController.java
View file @
bf425918
/*
* Copyright 2017 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
;
import
javax.servlet.http.HttpServletRequest
;
import
org.genesys2.server.model.elastic.AccessionDetails
;
import
org.genesys2.server.model.genesys.Accession
;
import
org.genesys2.server.service.GenesysService
;
import
org.genesys2.spring.ResourceNotFoundException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.
web.bind.annotation.PathVariable
;
import
org.springframework.
ui.ModelMap
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.servlet.HandlerMapping
;
import
org.springframework.web.servlet.ModelAndView
;
/**
* View resolver for DOIs handles: Accessions
*
* @author Maxym Borodenko
* @author Matija Obreza
*/
@Controller
public
class
DoiController
extends
BaseController
{
@Autowired
private
GenesysService
genesysService
;
@RequestMapping
(
"/{firstPartDOI:10\\.[0-9]+}/{secondPartDOI:.+}"
)
public
String
view
(
@PathVariable
String
firstPartDOI
,
@PathVariable
String
secondPartDOI
)
{
final
String
doi
=
firstPartDOI
+
"/"
+
secondPartDOI
;
_logger
.
info
(
"Lookup accession by DOI"
);
Accession
accession
=
genesysService
.
getAccessionByDOI
(
doi
);
if
(
accession
==
null
)
{
throw
new
ResourceNotFoundException
();
}
else
{
return
"forward:/acn/id/"
+
accession
.
getId
().
toString
();
}
}
@Autowired
private
GenesysService
genesysService
;
@Autowired
private
AccessionController
accessionController
;
@RequestMapping
(
value
=
"/10.{dummy:[0-9]+}/**"
)
public
ModelAndView
view
(
HttpServletRequest
request
,
ModelMap
model
)
{
final
String
fullpath
=
(
String
)
request
.
getAttribute
(
HandlerMapping
.
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
);
final
String
doi
=
fullpath
.
substring
(
1
);
_logger
.
debug
(
"Lookup accession by DOI="
+
doi
);
Accession
accession
=
genesysService
.
getAccessionByDOI
(
doi
);
if
(
accession
==
null
)
{
throw
new
ResourceNotFoundException
();
}
else
{
return
accessionController
.
displayAccession
(
model
,
accession
);
}
}
@RequestMapping
(
value
=
"/10.{dummy:[0-9]+}/**}"
,
headers
=
{
"Accept: application/json"
},
produces
=
{
MediaType
.
APPLICATION_JSON_VALUE
})
public
@ResponseBody
AccessionDetails
viewJson
(
HttpServletRequest
request
,
ModelMap
model
)
{
final
String
fullpath
=
(
String
)
request
.
getAttribute
(
HandlerMapping
.
PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE
);
final
String
doi
=
fullpath
.
substring
(
1
);
_logger
.
debug
(
"Lookup accession by DOI="
+
doi
);
Accession
accession
=
genesysService
.
getAccessionByDOI
(
doi
);
if
(
accession
==
null
)
{
throw
new
ResourceNotFoundException
();
}
AccessionDetails
ad
=
genesysService
.
getAccessionDetails
(
accession
.
getId
());
if
(
ad
==
null
)
{
throw
new
ResourceNotFoundException
();
}
return
ad
;
}
}
src/main/java/org/genesys2/server/servlet/filter/EnvVariablesFilter.java
View file @
bf425918
...
...
@@ -37,6 +37,9 @@ public class EnvVariablesFilter extends OncePerRequestFilter {
@Value
(
"${cdn.flags.url}"
)
private
String
cdnFlagsUrl
;
@Value
(
"${base.url}"
)
private
String
baseUrl
;
@Override
public
void
afterPropertiesSet
()
throws
ServletException
{
super
.
afterPropertiesSet
();
...
...
@@ -54,7 +57,11 @@ public class EnvVariablesFilter extends OncePerRequestFilter {
if
(
cdnFlagsUrl
!=
null
)
{
request
.
setAttribute
(
"cdnFlagsUrl"
,
cdnFlagsUrl
);
}
if
(
baseUrl
!=
null
)
{
request
.
setAttribute
(
"baseUrl"
,
baseUrl
);
}
filterChain
.
doFilter
(
request
,
response
);
}
...
...
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