Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
307a98eb
Commit
307a98eb
authored
Feb 18, 2020
by
Piotr Gawron
Browse files
documentation for get chemicals API calls
parent
f14e1dd1
Changes
5
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/projects/chemicals/ChemicalRestImpl.java
View file @
307a98eb
...
...
@@ -140,14 +140,7 @@ public class ChemicalRestImpl extends BaseRestImpl {
protected
Set
<
String
>
createChemicalColumnSet
(
String
columns
)
{
Set
<
String
>
columnsSet
=
new
LinkedHashSet
<>();
if
(
columns
.
equals
(
""
))
{
columnsSet
.
add
(
"name"
);
columnsSet
.
add
(
"references"
);
columnsSet
.
add
(
"description"
);
columnsSet
.
add
(
"synonyms"
);
columnsSet
.
add
(
"id"
);
columnsSet
.
add
(
"directEvidenceReferences"
);
columnsSet
.
add
(
"directEvidence"
);
columnsSet
.
add
(
"targets"
);
columnsSet
.
addAll
(
getAvailableChemicalColumns
());
}
else
{
columnsSet
.
addAll
(
Arrays
.
asList
(
columns
.
split
(
","
)));
}
...
...
@@ -210,4 +203,17 @@ public class ChemicalRestImpl extends BaseRestImpl {
}
return
chemicalParser
.
getSuggestedQueryList
(
project
,
project
.
getDisease
());
}
public
List
<
String
>
getAvailableChemicalColumns
()
{
List
<
String
>
result
=
new
ArrayList
<>();
result
.
add
(
"name"
);
result
.
add
(
"references"
);
result
.
add
(
"description"
);
result
.
add
(
"synonyms"
);
result
.
add
(
"id"
);
result
.
add
(
"directEvidenceReferences"
);
result
.
add
(
"directEvidence"
);
result
.
add
(
"targets"
);
return
result
;
}
}
web/src/main/asciidoc/projects/project_chemicals.adoc
0 → 100644
View file @
307a98eb
= Rest API Documentation - Project chemicals
Piotr Gawron
v{project-version} {build-time}
:toc: left
:sectnums:
== Get chemical
Returns chemicals data with project related connections.
=== CURL sample
include::{snippets}/projects/project_chemicals/search_by_query/curl-request.adoc[]
=== Path Parameters
include::{snippets}/projects/project_chemicals/search_by_query/path-parameters.adoc[]
=== Response Fields
include::{snippets}/projects/project_chemicals/search_by_query/response-fields.adoc[]
=== Sample Response
include::{snippets}/projects/project_chemicals/search_by_query/response-body.adoc[]
== Get suggested chemical queries
Get list of suggested chemical queries in the context of the project.
=== CURL sample
include::{snippets}/projects/project_chemicals/suggested_query_list/curl-request.adoc[]
=== Path Parameters
include::{snippets}/projects/project_chemicals/suggested_query_list/path-parameters.adoc[]
=== Response Fields
include::{snippets}/projects/project_chemicals/suggested_query_list/response-fields.adoc[]
=== Sample Response
include::{snippets}/projects/project_chemicals/suggested_query_list/response-body.adoc[]
web/src/test/java/lcsb/mapviewer/web/ChemicalControllerIntegrationTest.java
View file @
307a98eb
package
lcsb.mapviewer.web
;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.
get
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
MockMvcRestDocumentation
.
document
;
import
static
org
.
springframework
.
restdocs
.
mockmvc
.
RestDocumentationRequestBuilders
.
get
;
import
static
org
.
springframework
.
restdocs
.
payload
.
PayloadDocumentation
.*;
import
static
org
.
springframework
.
restdocs
.
request
.
RequestDocumentation
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.mock.web.MockHttpSession
;
import
org.springframework.restdocs.payload.ResponseFieldsSnippet
;
import
org.springframework.restdocs.request.RequestParametersSnippet
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.ActiveProfiles
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.web.servlet.RequestBuilder
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.google.gson.JsonParser
;
import
lcsb.mapviewer.api.projects.chemicals.ChemicalRestImpl
;
import
lcsb.mapviewer.model.Project
;
import
lcsb.mapviewer.model.map.MiriamData
;
import
lcsb.mapviewer.model.map.MiriamType
;
import
lcsb.mapviewer.services.interfaces.IProjectService
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@Transactional
@Rollback
@ActiveProfiles
(
"ctdTestProfile"
)
public
class
ChemicalControllerIntegrationTest
extends
ControllerIntegrationTest
{
Logger
logger
=
LogManager
.
getLogger
();
private
static
String
TEST_PROJECT
=
"TEST_PROJECT"
;
private
static
String
TEST_PROJECT2
=
"TEST_PROJECT2"
;
@SuppressWarnings
(
"unused"
)
private
Logger
logger
=
LogManager
.
getLogger
();
@Autowired
private
ChemicalRestImpl
chemicalRestImpl
;
@Autowired
private
IProjectService
projectService
;
@Before
public
void
setup
()
{
assumeTrue
(
"DAPI credentials are not provided"
,
isDapiConfigurationAvailable
());
createProject
(
TEST_PROJECT
);
}
@Test
public
void
testSearchChemicalsInProjectUrl
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
BUILT_IN_TEST_ADMIN_LOGIN
,
BUILT_IN_TEST_ADMIN_PASSWORD
);
RequestBuilder
request
=
get
(
"/projects/{projectId}/chemicals:search
"
,
BUILT_IN
_PROJECT
)
RequestBuilder
request
=
get
(
"/projects/{projectId}/chemicals:search
?query=stilbene oxide"
,
TEST
_PROJECT
)
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"projects/project_chemicals/search_by_query"
,
pathParameters
(
parameterWithName
(
"projectId"
).
description
(
"project identifier"
)),
getChemicalFilter
(),
listOfChemicalsFields
()))
.
andExpect
(
status
().
is2xxSuccessful
());
}
@Test
public
void
testGetSuggestedList
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
BUILT_IN_TEST_ADMIN_LOGIN
,
BUILT_IN_TEST_ADMIN_PASSWORD
);
MiriamData
bloodLossDisease
=
new
MiriamData
(
MiriamType
.
MESH_2012
,
"D016063"
);
Project
project
=
createEmptyProject
(
TEST_PROJECT2
);
project
.
setDisease
(
bloodLossDisease
);
projectService
.
updateProject
(
project
);
RequestBuilder
request
=
get
(
"/projects/{projectId}/chemicals/suggestedQueryList"
,
TEST_PROJECT2
)
.
session
(
session
);
String
content
=
mockMvc
.
perform
(
request
)
.
andDo
(
document
(
"projects/project_chemicals/suggested_query_list"
,
pathParameters
(
parameterWithName
(
"projectId"
).
description
(
"project identifier"
)),
responseFields
(
fieldWithPath
(
"[]"
)
.
description
(
"list of suggested chemical queries"
)
.
type
(
"Array<String>"
))))
.
andExpect
(
status
().
is2xxSuccessful
())
.
andReturn
().
getResponse
().
getContentAsString
();
int
elements
=
new
JsonParser
()
.
parse
(
content
)
.
getAsJsonArray
().
size
();
assertTrue
(
elements
>
0
);
}
private
RequestParametersSnippet
getChemicalFilter
()
{
return
requestParameters
(
parameterWithName
(
"columns"
)
.
description
(
"set of columns (all by default). Available options: "
+
StringUtils
.
join
(
chemicalRestImpl
.
getAvailableChemicalColumns
(),
", "
))
.
optional
(),
parameterWithName
(
"query"
)
.
description
(
"name of chemical that we are searching for"
)
.
optional
(),
parameterWithName
(
"target"
)
.
description
(
"target element that we are searching for in format TYPE:ID"
)
.
optional
());
}
private
ResponseFieldsSnippet
listOfChemicalsFields
()
{
return
responseFields
(
subsectionWithPath
(
"[].id"
)
.
description
(
"identifier of the chemical"
)
.
type
(
"Object"
),
fieldWithPath
(
"[].name"
)
.
description
(
"name"
)
.
type
(
"string"
),
fieldWithPath
(
"[].description"
)
.
description
(
"description"
)
.
type
(
"string"
),
fieldWithPath
(
"[].synonyms"
)
.
description
(
"list of synonyms"
)
.
type
(
"Array<String>"
),
subsectionWithPath
(
"[].references"
)
.
description
(
"list of references"
)
.
type
(
"Array<Reference>"
),
fieldWithPath
(
"[].targets"
)
.
description
(
"list of targets"
)
.
type
(
"Array<Target>"
),
fieldWithPath
(
"[].targets[].name"
)
.
description
(
"target name"
)
.
type
(
"string"
),
subsectionWithPath
(
"[].targets[].references"
)
.
description
(
"list of target references"
)
.
type
(
"Array<Reference>"
),
subsectionWithPath
(
"[].targets[].targetElements"
)
.
description
(
"list of elements on the map associated with this target"
)
.
type
(
"Array<Object>"
),
subsectionWithPath
(
"[].targets[].targetParticipants"
)
.
description
(
"list of identifiers associated with this target"
)
.
type
(
"Array<Object>"
),
fieldWithPath
(
"[].directEvidence"
)
.
description
(
"direct evidence"
)
.
type
(
"string"
),
subsectionWithPath
(
"[].directEvidenceReferences"
)
.
description
(
"list of references"
)
.
type
(
"Array<Reference>"
));
}
@Test
public
void
testSearchChemicalsInAsteriskProjectId
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
BUILT_IN_TEST_ADMIN_LOGIN
,
BUILT_IN_TEST_ADMIN_PASSWORD
);
...
...
web/src/test/java/lcsb/mapviewer/web/ControllerIntegrationTest.java
View file @
307a98eb
...
...
@@ -45,8 +45,7 @@ import lcsb.mapviewer.model.map.layout.Layout;
import
lcsb.mapviewer.model.map.model.ModelData
;
import
lcsb.mapviewer.model.map.reaction.*
;
import
lcsb.mapviewer.model.map.reaction.type.TransportReaction
;
import
lcsb.mapviewer.model.map.species.Element
;
import
lcsb.mapviewer.model.map.species.GenericProtein
;
import
lcsb.mapviewer.model.map.species.*
;
import
lcsb.mapviewer.model.security.PrivilegeType
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.persist.DbUtils
;
...
...
@@ -107,6 +106,9 @@ abstract public class ControllerIntegrationTest {
private
ExecutorService
executorService
;
private
String
dapiLogin
;
private
String
dapiPassword
;
@PostConstruct
public
void
construct
()
{
mockMvc
=
MockMvcBuilders
.
webAppContextSetup
(
context
)
...
...
@@ -156,6 +158,13 @@ abstract public class ControllerIntegrationTest {
public
final
void
_setUp
()
throws
Exception
{
MinervaLoggerAppender
.
unregisterLogEventStorage
(
appender
);
appender
=
MinervaLoggerAppender
.
createAppender
();
dapiLogin
=
System
.
getenv
(
"DAPI_TEST_LOGIN"
);
dapiPassword
=
System
.
getenv
(
"DAPI_TEST_PASSWORD"
);
}
protected
boolean
isDapiConfigurationAvailable
()
{
return
dapiLogin
!=
null
&&
dapiPassword
!=
null
;
}
@After
...
...
@@ -264,6 +273,7 @@ abstract public class ControllerIntegrationTest {
reaction
.
addMiriamData
(
new
MiriamData
(
MiriamType
.
PUBMED
,
"28725475"
));
map
.
addReaction
(
reaction
);
Element
element
=
new
GenericProtein
(
"p1"
);
element
.
setName
(
"GSTA4"
);
element
.
setWidth
(
100.0
);
element
.
setHeight
(
20.0
);
element
.
setX
(
10
);
...
...
@@ -271,11 +281,20 @@ abstract public class ControllerIntegrationTest {
element
.
setZ
(
2
);
map
.
addElement
(
element
);
Reactant
reactant
=
new
Reactant
(
element
);
Element
element2
=
new
SimpleMolecule
(
"s2"
);
element2
.
setName
(
"water"
);
element2
.
setWidth
(
100.0
);
element2
.
setHeight
(
20.0
);
element2
.
setX
(
10
);
element2
.
setX
(
20
);
element2
.
setZ
(
2
);
map
.
addElement
(
element2
);
Reactant
reactant
=
new
Reactant
(
element2
);
reactant
.
setLine
(
new
PolylineData
(
new
Point2D
.
Double
(
10
,
0
),
new
Point2D
.
Double
(
0
,
0
)));
reaction
.
addReactant
(
reactant
);
Product
product
=
new
Product
(
element
);
Product
product
=
new
Product
(
element
2
);
product
.
setLine
(
new
PolylineData
(
new
Point2D
.
Double
(
10
,
0
),
new
Point2D
.
Double
(
20
,
0
)));
reaction
.
addProduct
(
product
);
...
...
@@ -284,6 +303,37 @@ abstract public class ControllerIntegrationTest {
return
project
;
}
protected
Project
createEmptyProject
(
String
projectId
)
{
Project
project
=
new
Project
(
projectId
);
project
.
setOwner
(
userService
.
getUserByLogin
(
BUILT_IN_TEST_ADMIN_LOGIN
));
project
.
setDirectory
(
"289b78b436176091ad900020c933c544"
);
project
.
setName
(
"Test Disease"
);
try
{
project
.
setInputData
(
createFile
(
Files
.
readAllBytes
(
Paths
.
get
(
"./src/test/resources/generic.xml"
)),
userService
.
getUserByLogin
(
BUILT_IN_TEST_ADMIN_LOGIN
)));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
ModelData
map
=
new
ModelData
();
map
.
setName
(
"map_name"
);
map
.
setTileSize
(
256
);
map
.
setWidth
(
100
);
map
.
setHeight
(
100
);
Element
element
=
new
GenericProtein
(
"p1"
);
element
.
setName
(
"PTI"
);
element
.
setWidth
(
100.0
);
element
.
setHeight
(
20.0
);
element
.
setX
(
10
);
element
.
setX
(
20
);
element
.
setZ
(
2
);
map
.
addElement
(
element
);
project
.
addModel
(
map
);
projectDao
.
add
(
project
);
return
project
;
}
protected
UploadedFileEntry
createFile
(
String
content
,
User
user
)
{
return
createFile
(
content
.
getBytes
(),
user
);
}
...
...
web/src/test/java/lcsb/mapviewer/web/CtdDapiConfiguration.java
0 → 100644
View file @
307a98eb
package
lcsb.mapviewer.web
;
import
org.mockito.Mockito
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.*
;
import
lcsb.mapviewer.annotation.services.dapi.*
;
@Profile
(
"ctdTestProfile"
)
@Configuration
public
class
CtdDapiConfiguration
{
@Autowired
private
DapiConnector
dapiConnector
;
private
String
dapiLogin
;
private
String
dapiPassword
;
public
CtdDapiConfiguration
()
{
dapiLogin
=
System
.
getenv
(
"DAPI_TEST_LOGIN"
);
dapiPassword
=
System
.
getenv
(
"DAPI_TEST_PASSWORD"
);
}
@Bean
@Primary
public
DapiConnector
dapiConnector
()
throws
DapiConnectionException
{
DapiConnectorImpl
mock
=
(
DapiConnectorImpl
)
Mockito
.
spy
(
dapiConnector
);
Mockito
.
doReturn
(
true
).
when
(
mock
).
isValidConnection
();
Mockito
.
doReturn
(
dapiLogin
).
when
(
mock
).
getDapiLogin
();
Mockito
.
doReturn
(
dapiPassword
).
when
(
mock
).
getDapiPassword
();
return
mock
;
}
}
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