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
ac1f3411
Commit
ac1f3411
authored
Aug 22, 2019
by
Piotr Gawron
Browse files
proper handling for undefined project id when searching for drugs
parent
d29bceb6
Changes
3
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/projects/drugs/DrugController.java
View file @
ac1f3411
...
...
@@ -8,8 +8,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import
org.springframework.web.bind.annotation.*
;
import
lcsb.mapviewer.annotation.services.DrugSearchException
;
import
lcsb.mapviewer.api.BaseController
;
import
lcsb.mapviewer.api.QueryException
;
import
lcsb.mapviewer.api.*
;
@RestController
@RequestMapping
(
value
=
"/projects/{projectId}/"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
@@ -28,7 +27,7 @@ public class DrugController extends BaseController {
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"columns"
,
defaultValue
=
""
)
String
columns
,
@RequestParam
(
value
=
"query"
,
defaultValue
=
""
)
String
query
,
@RequestParam
(
value
=
"target"
,
defaultValue
=
""
)
String
target
)
throws
QueryException
{
@RequestParam
(
value
=
"target"
,
defaultValue
=
""
)
String
target
)
throws
QueryException
,
ObjectNotFoundException
{
if
(!
query
.
equals
(
""
))
{
return
drugController
.
getDrugsByQuery
(
projectId
,
columns
,
query
);
}
else
if
(
target
.
contains
(
":"
))
{
...
...
@@ -43,7 +42,7 @@ public class DrugController extends BaseController {
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
@GetMapping
(
value
=
"drugs/suggestedQueryList"
)
public
List
<
String
>
getSuggestedQueryList
(
@PathVariable
(
value
=
"projectId"
)
String
projectId
)
throws
DrugSearchException
{
throws
DrugSearchException
,
ObjectNotFoundException
{
return
drugController
.
getSuggestedQueryList
(
projectId
);
}
...
...
rest-api/src/main/java/lcsb/mapviewer/api/projects/drugs/DrugRestImpl.java
View file @
ac1f3411
...
...
@@ -41,10 +41,10 @@ public class DrugRestImpl extends BaseRestImpl {
}
public
List
<
Map
<
String
,
Object
>>
getDrugsByQuery
(
String
projectId
,
String
columns
,
String
query
)
throws
QueryException
{
throws
QueryException
,
ObjectNotFoundException
{
Model
model
=
getModelService
().
getLastModelByProjectId
(
projectId
);
if
(
model
==
null
)
{
throw
new
Query
Exception
(
"Project with given id doesn't exist"
);
throw
new
ObjectNotFound
Exception
(
"Project with given id doesn't exist"
);
}
Project
project
=
getProjectService
().
getProjectByProjectId
(
projectId
);
...
...
@@ -128,10 +128,10 @@ public class DrugRestImpl extends BaseRestImpl {
}
public
List
<
Map
<
String
,
Object
>>
getDrugsByTarget
(
String
projectId
,
String
targetType
,
String
targetId
,
String
columns
)
throws
QueryException
{
String
columns
)
throws
QueryException
,
ObjectNotFoundException
{
Model
model
=
getModelService
().
getLastModelByProjectId
(
projectId
);
if
(
model
==
null
)
{
throw
new
Query
Exception
(
"Project with given id doesn't exist"
);
throw
new
ObjectNotFound
Exception
(
"Project with given id doesn't exist"
);
}
Project
project
=
getProjectService
().
getProjectByProjectId
(
projectId
);
...
...
@@ -176,8 +176,11 @@ public class DrugRestImpl extends BaseRestImpl {
return
targets
;
}
public
List
<
String
>
getSuggestedQueryList
(
String
projectId
)
throws
DrugSearchException
{
public
List
<
String
>
getSuggestedQueryList
(
String
projectId
)
throws
DrugSearchException
,
ObjectNotFoundException
{
Project
project
=
getProjectService
().
getProjectByProjectId
(
projectId
);
if
(
project
==
null
)
{
throw
new
ObjectNotFoundException
(
"Project with given id doesn't exist"
);
}
return
drugService
.
getSuggestedQueryList
(
project
,
project
.
getOrganism
());
}
...
...
web/src/test/java/lcsb/mapviewer/web/DrugControllerIntegrationTest.java
View file @
ac1f3411
...
...
@@ -50,6 +50,30 @@ public class DrugControllerIntegrationTest extends ControllerIntegrationTest {
.
andExpect
(
status
().
is2xxSuccessful
());
}
@Test
public
void
testSearchDrugsInUndefinedProject
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
RequestBuilder
request
=
get
(
"/projects/*/drugs:search?query=xyz"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
isNotFound
());
}
@Test
public
void
testSearchDrugsByTargetInUndefinedProject
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
RequestBuilder
request
=
get
(
"/projects/*/drugs:search?target=ALIAS:123"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
isNotFound
());
}
@Test
public
void
testGetSuggestedList
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
...
...
@@ -62,4 +86,16 @@ public class DrugControllerIntegrationTest extends ControllerIntegrationTest {
.
andExpect
(
status
().
is2xxSuccessful
());
}
@Test
public
void
testGetSuggestedListWithUndefinedProject
()
throws
Exception
{
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
RequestBuilder
request
=
get
(
"/projects/*/drugs/suggestedQueryList"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
isNotFound
());
}
}
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