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
c1934c92
Commit
c1934c92
authored
May 11, 2020
by
Piotr Gawron
Browse files
list of comments takes into account submaps, removing a comment from submap works
parent
9dfb64e7
Pipeline
#26516
failed with stage
in 12 minutes and 17 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
CHANGELOG
View file @
c1934c92
minerva
(
14.0.12
)
stable
;
urgency
=
medium
*
Bug
fix
:
comments
on
submaps
were
not
visible
(#
1230
)
*
Bug
fix
:
removing
comment
from
submap
did
not
work
--
Piotr
Gawron
<
piotr
.
gawron
@
uni
.
lu
>
Mon
,
11
May
2020
17
:
00
:
00
+
0200
minerva
(
14.0.11
)
stable
;
urgency
=
medium
*
Bug
fix
:
complex
with
no
border
was
inproperly
imported
from
CellDesigner
(#
1198
)
...
...
rest-api/src/main/java/lcsb/mapviewer/api/projects/comments/CommentController.java
View file @
c1934c92
...
...
@@ -47,6 +47,7 @@ public class CommentController extends BaseController {
Authentication
authentication
,
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"columns"
,
defaultValue
=
""
)
String
columns
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
@RequestParam
(
value
=
"removed"
,
defaultValue
=
""
)
String
removed
)
throws
QueryException
{
boolean
isAdmin
=
authentication
.
getAuthorities
()
.
contains
(
new
SimpleGrantedAuthority
(
PrivilegeType
.
IS_ADMIN
.
name
()));
...
...
@@ -56,7 +57,7 @@ public class CommentController extends BaseController {
.
contains
(
new
SimpleGrantedAuthority
(
PrivilegeType
.
READ_PROJECT
.
name
()
+
":"
+
projectId
));
List
<
Map
<
String
,
Object
>>
comments
=
commentController
.
getCommentList
(
projectId
,
columns
,
""
,
""
,
removed
);
projectId
,
columns
,
""
,
""
,
removed
,
modelId
);
if
(!
isAdmin
&&
!
isProjectCurator
)
{
comments
.
forEach
(
comment
->
{
comment
.
remove
(
"author"
);
...
...
@@ -89,10 +90,11 @@ public class CommentController extends BaseController {
public
List
<
Map
<
String
,
Object
>>
getCommentsByReaction
(
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"columns"
,
defaultValue
=
""
)
String
columns
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
@PathVariable
(
value
=
"reactionId"
)
String
reactionId
,
@RequestParam
(
value
=
"removed"
,
defaultValue
=
""
)
String
removed
)
throws
QueryException
{
return
commentController
.
getCommentList
(
projectId
,
columns
,
reactionId
,
ElementIdentifierType
.
REACTION
.
getJsName
(),
removed
);
ElementIdentifierType
.
REACTION
.
getJsName
(),
removed
,
modelId
);
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
@@ -105,9 +107,10 @@ public class CommentController extends BaseController {
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"columns"
,
defaultValue
=
""
)
String
columns
,
@PathVariable
(
value
=
"elementId"
)
String
elementId
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
@RequestParam
(
value
=
"removed"
,
defaultValue
=
""
)
String
removed
)
throws
QueryException
{
return
commentController
.
getCommentList
(
projectId
,
columns
,
elementId
,
ElementIdentifierType
.
ALIAS
.
getJsName
(),
removed
);
projectId
,
columns
,
elementId
,
ElementIdentifierType
.
ALIAS
.
getJsName
(),
removed
,
modelId
);
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
@@ -120,9 +123,10 @@ public class CommentController extends BaseController {
@PathVariable
(
value
=
"projectId"
)
String
projectId
,
@RequestParam
(
value
=
"columns"
,
defaultValue
=
""
)
String
columns
,
@PathVariable
(
value
=
"coordinates"
)
String
coordinates
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
@RequestParam
(
value
=
"removed"
,
defaultValue
=
""
)
String
removed
)
throws
QueryException
{
return
commentController
.
getCommentList
(
projectId
,
columns
,
coordinates
,
ElementIdentifierType
.
POINT
.
getJsName
(),
removed
);
ElementIdentifierType
.
POINT
.
getJsName
(),
removed
,
modelId
);
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
rest-api/src/main/java/lcsb/mapviewer/api/projects/comments/CommentRestImpl.java
View file @
c1934c92
...
...
@@ -15,7 +15,7 @@ import lcsb.mapviewer.common.Configuration;
import
lcsb.mapviewer.common.geometry.PointTransformation
;
import
lcsb.mapviewer.model.Project
;
import
lcsb.mapviewer.model.map.Comment
;
import
lcsb.mapviewer.model.map.model.
Model
;
import
lcsb.mapviewer.model.map.model.
*
;
import
lcsb.mapviewer.model.map.reaction.Reaction
;
import
lcsb.mapviewer.model.map.species.Element
;
import
lcsb.mapviewer.model.user.User
;
...
...
@@ -49,7 +49,7 @@ public class CommentRestImpl extends BaseRestImpl {
public
List
<
Map
<
String
,
Object
>>
getCommentList
(
String
projectId
,
String
columns
,
String
elementId
,
String
elementType
,
String
removed
)
throws
QueryException
{
String
elementType
,
String
removed
,
String
modelId
)
throws
QueryException
{
Project
project
=
getProjectService
().
getProjectByProjectId
(
projectId
);
if
(
project
==
null
)
{
throw
new
ObjectNotFoundException
(
"Project with given id doesn't exist"
);
...
...
@@ -58,7 +58,9 @@ public class CommentRestImpl extends BaseRestImpl {
List
<
Map
<
String
,
Object
>>
result
=
new
ArrayList
<>();
List
<
Comment
>
comments
=
commentService
.
getCommentsByProject
(
project
);
List
<
Model
>
models
=
super
.
getModels
(
projectId
,
modelId
);
List
<
Comment
>
comments
=
commentService
.
getCommentsByModel
(
models
);
for
(
Comment
comment
:
comments
)
{
boolean
reject
=
false
;
if
(!
""
.
equals
(
elementType
))
{
...
...
@@ -246,7 +248,8 @@ public class CommentRestImpl extends BaseRestImpl {
}
public
Map
<
String
,
Object
>
addComment
(
String
projectId
,
String
elementType
,
String
elementId
,
String
name
,
String
email
,
String
content
,
boolean
pinned
,
Point2D
pointCoordinates
,
String
submodelId
,
User
owner
)
String
name
,
String
email
,
String
content
,
boolean
pinned
,
Point2D
pointCoordinates
,
String
submodelId
,
User
owner
)
throws
QueryException
{
Model
model
=
getModelService
().
getLastModelByProjectId
(
projectId
);
if
(
model
==
null
)
{
...
...
@@ -292,9 +295,26 @@ public class CommentRestImpl extends BaseRestImpl {
throw
new
ObjectNotFoundException
(
"Project with given id doesn't exist"
);
}
Comment
comment
=
commentService
.
getCommentById
(
commentId
);
if
(
comment
==
null
||
comment
.
getModelData
().
getProject
().
getId
()
!=
project
.
getId
())
{
if
(
comment
==
null
)
{
throw
new
ObjectNotFoundException
(
"Comment with given id doesn't exist"
);
}
if
(
comment
.
getModelData
().
getProject
()
!=
null
&&
comment
.
getModelData
().
getProject
().
getId
()
!=
project
.
getId
())
{
throw
new
ObjectNotFoundException
(
"Comment with given id doesn't exist"
);
}
boolean
isSubmap
=
false
;
if
(
comment
.
getModelData
().
getProject
()
==
null
)
{
for
(
ModelData
model
:
project
.
getModels
())
{
for
(
ModelSubmodelConnection
submodel
:
model
.
getSubmodels
())
{
if
(
submodel
.
getSubmodel
().
getId
().
equals
(
comment
.
getModelData
().
getId
()))
{
isSubmap
=
true
;
}
}
}
if
(!
isSubmap
)
{
throw
new
ObjectNotFoundException
(
"Comment with given id doesn't exist"
);
}
}
commentService
.
deleteComment
(
comment
,
reason
);
return
okStatus
();
...
...
rest-api/src/test/java/lcsb/mapviewer/api/projects/comments/CommentRestImplTest.java
View file @
c1934c92
...
...
@@ -37,13 +37,13 @@ public class CommentRestImplTest extends RestTestFunctions {
@Test
(
expected
=
QueryException
.
class
)
public
void
testGetForNonExisting
()
throws
Exception
{
_commentRestImpl
.
getCommentList
(
"unk"
,
""
,
""
,
""
,
""
);
_commentRestImpl
.
getCommentList
(
"unk"
,
""
,
""
,
""
,
""
,
"*"
);
}
@Test
public
void
testGetCommentsDependencies
()
throws
Exception
{
CommentRestImpl
commentRestImpl
=
createMockProjectRest
(
"testFiles/model/sample.xml"
);
commentRestImpl
.
getCommentList
(
"sample"
,
""
,
""
,
""
,
""
);
commentRestImpl
.
getCommentList
(
"sample"
,
""
,
""
,
""
,
""
,
"*"
);
Mockito
.
verify
(
commentRestImpl
.
getModelService
(),
times
(
0
)).
getLastModelByProjectId
(
anyString
());
}
...
...
service/src/main/java/lcsb/mapviewer/services/impl/CommentService.java
View file @
c1934c92
...
...
@@ -140,9 +140,9 @@ public class CommentService implements ICommentService {
}
@Override
public
List
<
Comment
>
getCommentsBy
Project
(
Project
project
)
{
public
List
<
Comment
>
getCommentsBy
Model
(
List
<
Model
>
models
)
{
List
<
Comment
>
comments
=
new
ArrayList
<>();
for
(
Model
Data
model
:
project
.
getM
odels
()
)
{
for
(
Model
model
:
m
odels
)
{
List
<
Comment
>
modelComments
=
commentDao
.
getCommentByModel
(
model
,
null
,
null
);
comments
.
addAll
(
modelComments
);
}
...
...
service/src/main/java/lcsb/mapviewer/services/interfaces/ICommentService.java
View file @
c1934c92
...
...
@@ -55,7 +55,7 @@ public interface ICommentService {
void
deleteComment
(
Comment
comment
,
String
reason
);
List
<
Comment
>
getCommentsBy
Project
(
Project
project
);
List
<
Comment
>
getCommentsBy
Model
(
List
<
Model
>
models
);
/**
* Returns number of comments in the system.
...
...
web/src/test/java/lcsb/mapviewer/web/CommentControllerIntegrationTest.java
View file @
c1934c92
...
...
@@ -4,7 +4,6 @@ import static org.junit.Assert.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
request
.
MockMvcRequestBuilders
.*;
import
static
org
.
springframework
.
test
.
web
.
servlet
.
result
.
MockMvcResultMatchers
.
status
;
import
java.awt.geom.Point2D
;
import
java.util.Arrays
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
...
...
@@ -86,7 +85,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments
();
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
Model
()
+
"/"
)
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
...
...
@@ -107,7 +106,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments
();
RequestBuilder
request
=
get
(
"/projects/*/comments/models/"
+
map
.
getId
Model
()
+
"/"
)
RequestBuilder
request
=
get
(
"/projects/*/comments/models/"
+
map
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
...
...
@@ -124,7 +123,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments
();
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
Model
()
+
"/"
)
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
...
...
@@ -159,7 +158,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments
();
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
Model
()
+
"/"
)
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
...
...
@@ -184,7 +183,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
comment
.
setPinned
(
true
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
Model
()
+
"/"
)
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
...
...
@@ -209,7 +208,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
comment
.
setPinned
(
true
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
Model
()
+
"/"
)
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
...
...
@@ -234,7 +233,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
comment
.
setPinned
(
true
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
Model
()
+
"/"
)
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
...
...
@@ -256,7 +255,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
createComments
();
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
Model
()
+
"/"
)
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/"
+
map
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
...
...
@@ -874,6 +873,45 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
.
andExpect
(
status
().
isNotFound
());
}
@Test
public
void
testCommentsOnNonExistingModel
()
throws
Exception
{
createAdmin
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
createComments
();
RequestBuilder
request
=
get
(
"/projects/"
+
TEST_PROJECT
+
"/comments/models/0/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
isNotFound
());
}
@Test
public
void
testRemoveFromSubmap
()
throws
Exception
{
createAdmin
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
MockHttpSession
session
=
createSession
(
TEST_ADMIN_LOGIN
,
TEST_ADMIN_PASSWORD
);
ModelData
submap
=
map
.
getSubmodels
().
iterator
().
next
().
getSubmodel
();
Comment
comment
=
createComment
(
submap
);
commentDao
.
add
(
comment
);
RequestBuilder
request
=
delete
(
"/projects/"
+
TEST_PROJECT
+
"/comments/"
+
comment
.
getId
()
+
"/"
)
.
contentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
)
.
session
(
session
);
mockMvc
.
perform
(
request
)
.
andExpect
(
status
().
is2xxSuccessful
());
assertEquals
(
true
,
comment
.
isDeleted
());
}
private
Comment
createReactionComment
()
{
Comment
comment
=
createComment
(
map
);
comment
.
setTableName
(
reaction
.
getClass
());
...
...
web/src/test/java/lcsb/mapviewer/web/ControllerIntegrationTest.java
View file @
c1934c92
...
...
@@ -38,7 +38,7 @@ import lcsb.mapviewer.model.map.Comment;
import
lcsb.mapviewer.model.map.layout.ColorSchemaType
;
import
lcsb.mapviewer.model.map.layout.Layout
;
import
lcsb.mapviewer.model.map.layout.graphics.Glyph
;
import
lcsb.mapviewer.model.map.model.
ModelData
;
import
lcsb.mapviewer.model.map.model.
*
;
import
lcsb.mapviewer.model.map.reaction.*
;
import
lcsb.mapviewer.model.map.reaction.type.TransportReaction
;
import
lcsb.mapviewer.model.map.species.Element
;
...
...
@@ -248,6 +248,15 @@ abstract public class ControllerIntegrationTest {
product
.
setLine
(
new
PolylineData
(
new
Point2D
.
Double
(
10
,
0
),
new
Point2D
.
Double
(
20
,
0
)));
reaction
.
addProduct
(
product
);
ModelData
submap
=
new
ModelData
();
submap
.
setTileSize
(
256
);
submap
.
setWidth
(
100
);
submap
.
setHeight
(
100
);
ModelSubmodelConnection
submodelConnection
=
new
ModelSubmodelConnection
(
submap
,
SubmodelType
.
UNKNOWN
);
map
.
addSubmodel
(
submodelConnection
);
project
.
addModel
(
map
);
projectDao
.
add
(
project
);
return
project
;
...
...
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