Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
09e2b39f
Commit
09e2b39f
authored
Jul 22, 2021
by
Piotr Gawron
Browse files
IMeshService implemented
parent
b9f1ed7b
Changes
7
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/mesh/MeshController.java
View file @
09e2b39f
package
lcsb.mapviewer.api.mesh
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
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.RestController
;
import
lcsb.mapviewer.annotation.data.MeSH
;
import
lcsb.mapviewer.annotation.services.annotators.AnnotatorException
;
import
lcsb.mapviewer.api.BaseController
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.MiriamType
;
import
lcsb.mapviewer.services.ObjectNotFoundException
;
import
lcsb.mapviewer.services.interfaces.IMeshService
;
@RestController
@RequestMapping
(
value
=
"/api/mesh"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
@@ -21,16 +29,26 @@ public class MeshController extends BaseController {
@SuppressWarnings
(
"unused"
)
private
Logger
logger
=
LogManager
.
getLogger
();
private
Mesh
RestImpl
meshRest
;
private
I
Mesh
Service
meshService
;
@Autowired
public
MeshController
(
Mesh
RestImpl
meshRest
)
{
this
.
mesh
Rest
=
meshRest
;
public
MeshController
(
I
Mesh
Service
meshService
)
{
this
.
mesh
Service
=
meshService
;
}
@GetMapping
(
value
=
"/{id:.+}"
)
public
Map
<
String
,
Object
>
getMesh
(
@PathVariable
(
value
=
"id"
)
String
id
)
throws
AnnotatorException
,
ObjectNotFoundException
{
return
meshRest
.
getMesh
(
id
);
MeSH
mesh
=
meshService
.
getMesh
(
new
MiriamData
(
MiriamType
.
MESH_2012
,
id
));
if
(
mesh
==
null
)
{
throw
new
ObjectNotFoundException
(
"Object not found: "
+
id
);
}
Map
<
String
,
Object
>
result
=
new
TreeMap
<>();
result
.
put
(
"name"
,
mesh
.
getName
());
result
.
put
(
"id"
,
mesh
.
getMeSHId
());
result
.
put
(
"description"
,
mesh
.
getDescription
());
result
.
put
(
"synonyms"
,
mesh
.
getSynonyms
());
return
result
;
}
}
\ No newline at end of file
rest-api/src/test/java/lcsb/mapviewer/api/AllRestTests.java
View file @
09e2b39f
...
...
@@ -4,13 +4,11 @@ import org.junit.runner.RunWith;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
lcsb.mapviewer.api.mesh.AllMeshTests
;
import
lcsb.mapviewer.api.projects.AllProjectTests
;
import
lcsb.mapviewer.api.users.AllUserTests
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
AllMeshTests
.
class
,
AllProjectTests
.
class
,
AllUserTests
.
class
,
})
...
...
rest-api/src/test/java/lcsb/mapviewer/api/mesh/AllMeshTests.java
deleted
100644 → 0
View file @
b9f1ed7b
package
lcsb.mapviewer.api.mesh
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
MeshRestImplTest
.
class
})
public
class
AllMeshTests
{
}
rest-api/src/test/java/lcsb/mapviewer/api/mesh/MeshRestImplTest.java
deleted
100644 → 0
View file @
b9f1ed7b
package
lcsb.mapviewer.api.mesh
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.util.Map
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lcsb.mapviewer.annotation.services.annotators.AnnotatorException
;
import
lcsb.mapviewer.api.RestTestFunctions
;
import
lcsb.mapviewer.services.ObjectNotFoundException
;
public
class
MeshRestImplTest
extends
RestTestFunctions
{
Logger
logger
=
LogManager
.
getLogger
();
@Autowired
MeshRestImpl
meshRestImpl
;
@Test
public
void
test
()
throws
ObjectNotFoundException
,
AnnotatorException
{
Map
<
String
,
Object
>
result
=
meshRestImpl
.
getMesh
(
"D010300"
);
assertNotNull
(
result
);
String
name
=
(
String
)
result
.
get
(
"name"
);
assertTrue
(
name
.
toLowerCase
().
contains
(
"parkinson"
));
}
}
rest-api
/src/main/java/lcsb/mapviewer/
api/mesh/MeshRestImpl
.java
→
service
/src/main/java/lcsb/mapviewer/
services/impl/MeshService
.java
View file @
09e2b39f
package
lcsb.mapviewer.
api.mesh
;
package
lcsb.mapviewer.
services.impl
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -12,39 +7,23 @@ import org.springframework.transaction.annotation.Transactional;
import
lcsb.mapviewer.annotation.data.MeSH
;
import
lcsb.mapviewer.annotation.services.MeSHParser
;
import
lcsb.mapviewer.annotation.services.annotators.AnnotatorException
;
import
lcsb.mapviewer.api.BaseRestImpl
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.MiriamType
;
import
lcsb.mapviewer.services.ObjectNotFoundException
;
import
lcsb.mapviewer.services.interfaces.IMeshService
;
@Transactional
@Service
public
class
MeshRestImpl
extends
BaseRestImpl
{
/**
* Default class logger.
*/
@SuppressWarnings
(
"unused"
)
private
Logger
logger
=
LogManager
.
getLogger
();
public
class
MeshService
implements
IMeshService
{
private
MeSHParser
meSHParser
;
@Autowired
public
Mesh
RestImpl
(
MeSHParser
meSHParser
)
{
public
Mesh
Service
(
MeSHParser
meSHParser
)
{
this
.
meSHParser
=
meSHParser
;
}
public
Map
<
String
,
Object
>
getMesh
(
String
id
)
throws
AnnotatorException
,
ObjectNotFoundException
{
MeSH
mesh
=
meSHParser
.
getMeSH
(
new
MiriamData
(
MiriamType
.
MESH_2012
,
id
));
if
(
mesh
==
null
)
{
throw
new
ObjectNotFoundException
(
"Object not found: "
+
id
);
}
Map
<
String
,
Object
>
result
=
new
TreeMap
<>();
result
.
put
(
"name"
,
mesh
.
getName
());
result
.
put
(
"id"
,
mesh
.
getMeSHId
());
result
.
put
(
"description"
,
mesh
.
getDescription
());
result
.
put
(
"synonyms"
,
mesh
.
getSynonyms
());
return
result
;
@Override
public
MeSH
getMesh
(
MiriamData
meshID
)
throws
AnnotatorException
{
return
meSHParser
.
getMeSH
(
meshID
);
}
}
service/src/main/java/lcsb/mapviewer/services/interfaces/IMeshService.java
0 → 100644
View file @
09e2b39f
package
lcsb.mapviewer.services.interfaces
;
import
lcsb.mapviewer.annotation.data.MeSH
;
import
lcsb.mapviewer.annotation.services.annotators.AnnotatorException
;
import
lcsb.mapviewer.model.map.MiriamData
;
public
interface
IMeshService
{
MeSH
getMesh
(
MiriamData
miriamData
)
throws
AnnotatorException
;
}
web/src/test/java/lcsb/mapviewer/web/MeshControllerIntegrationTest.java
View file @
09e2b39f
package
lcsb.mapviewer.web
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
MockMvcRestDocumentation
.
document
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.
get
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.
fieldWithPath
;
...
...
@@ -8,18 +9,29 @@ import static org.springframework.restdocs.request.RequestDocumentation.paramete
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.
pathParameters
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.util.Map
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.junit.*
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.web.servlet.RequestBuilder
;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
public
class
MeshControllerIntegrationTest
extends
ControllerIntegrationTest
{
Logger
logger
=
LogManager
.
getLogger
();
@Autowired
private
ObjectMapper
objectMapper
;
@Before
public
void
setup
()
{
}
...
...
@@ -31,9 +43,9 @@ public class MeshControllerIntegrationTest extends ControllerIntegrationTest {
@Test
public
void
testGetTaxonomies
()
throws
Exception
{
RequestBuilder
request
=
get
(
"/api/mesh/{meshId}"
,
"D0
02095
"
);
RequestBuilder
request
=
get
(
"/api/mesh/{meshId}"
,
"D0
10300
"
);
mockMvc
.
perform
(
request
)
String
response
=
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"mesh/get_mesh"
,
pathParameters
(
parameterWithName
(
"meshId"
).
description
(
"mesh id"
)),
responseFields
(
...
...
@@ -49,7 +61,14 @@ public class MeshControllerIntegrationTest extends ControllerIntegrationTest {
fieldWithPath
(
"id"
)
.
description
(
"mesh id"
)
.
type
(
"string"
))))
.
andExpect
(
status
().
is2xxSuccessful
());
.
andExpect
(
status
().
is2xxSuccessful
())
.
andReturn
().
getResponse
().
getContentAsString
();
Map
<
String
,
Object
>
result
=
objectMapper
.
readValue
(
response
,
new
TypeReference
<
Map
<
String
,
Object
>>()
{
});
String
name
=
(
String
)
result
.
get
(
"name"
);
assertTrue
(
name
.
toLowerCase
().
contains
(
"parkinson"
));
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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