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
0995fe1a
Commit
0995fe1a
authored
Sep 03, 2019
by
Piotr Gawron
Browse files
comment has owner assigned
parent
681fb6f4
Changes
6
Hide whitespace changes
Inline
Side-by-side
rest-api/src/main/java/lcsb/mapviewer/api/projects/comments/CommentController.java
View file @
0995fe1a
...
...
@@ -17,6 +17,8 @@ import org.springframework.web.bind.annotation.*;
import
lcsb.mapviewer.api.*
;
import
lcsb.mapviewer.model.security.PrivilegeType
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.services.interfaces.IUserService
;
@RestController
@RequestMapping
(
value
=
"/projects/{projectId}/comments"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
...
...
@@ -26,9 +28,12 @@ public class CommentController extends BaseController {
private
CommentRestImpl
commentController
;
private
IUserService
userService
;
@Autowired
public
CommentController
(
CommentRestImpl
commentController
)
{
public
CommentController
(
CommentRestImpl
commentController
,
IUserService
userService
)
{
this
.
commentController
=
commentController
;
this
.
userService
=
userService
;
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
@@ -129,10 +134,12 @@ public class CommentController extends BaseController {
@RequestParam
(
value
=
"content"
)
String
content
,
@RequestParam
(
value
=
"pinned"
,
defaultValue
=
"true"
)
String
pinned
,
@RequestParam
(
value
=
"coordinates"
)
String
coordinates
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
)
throws
QueryException
{
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
Authentication
authentication
)
throws
QueryException
{
Point2D
pointCoordinates
=
parseCoordinates
(
coordinates
);
User
user
=
userService
.
getUserByLogin
(
authentication
.
getName
());
return
commentController
.
addComment
(
projectId
,
ElementIdentifierType
.
ALIAS
.
getJsName
(),
elementId
,
name
,
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
);
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
,
user
);
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
@@ -145,10 +152,11 @@ public class CommentController extends BaseController {
@RequestParam
(
value
=
"content"
)
String
content
,
@RequestParam
(
value
=
"pinned"
,
defaultValue
=
"true"
)
String
pinned
,
@RequestParam
(
value
=
"coordinates"
)
String
coordinates
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
)
throws
QueryException
{
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
Authentication
authentication
)
throws
QueryException
{
Point2D
pointCoordinates
=
parseCoordinates
(
coordinates
);
User
user
=
userService
.
getUserByLogin
(
authentication
.
getName
());
return
commentController
.
addComment
(
projectId
,
ElementIdentifierType
.
REACTION
.
getJsName
(),
reactionId
,
name
,
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
);
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
,
user
);
}
@PreAuthorize
(
"hasAnyAuthority('IS_ADMIN', 'READ_PROJECT:' + #projectId)"
)
...
...
@@ -160,10 +168,11 @@ public class CommentController extends BaseController {
@RequestParam
(
value
=
"content"
)
String
content
,
@RequestParam
(
value
=
"pinned"
,
defaultValue
=
"true"
)
String
pinned
,
@PathVariable
(
value
=
"coordinates"
)
String
coordinates
,
@PathVariable
(
value
=
"modelId"
)
String
modelId
)
throws
QueryException
{
@PathVariable
(
value
=
"modelId"
)
String
modelId
,
Authentication
authentication
)
throws
QueryException
{
Point2D
pointCoordinates
=
parseCoordinates
(
coordinates
);
User
user
=
userService
.
getUserByLogin
(
authentication
.
getName
());
return
commentController
.
addComment
(
projectId
,
ElementIdentifierType
.
POINT
.
getJsName
(),
coordinates
,
name
,
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
);
email
,
content
,
pinned
.
toLowerCase
().
equals
(
"true"
),
pointCoordinates
,
modelId
,
user
);
}
private
Point2D
parseCoordinates
(
String
coordinates
)
throws
QueryException
{
...
...
rest-api/src/main/java/lcsb/mapviewer/api/projects/comments/CommentRestImpl.java
View file @
0995fe1a
...
...
@@ -18,6 +18,7 @@ import lcsb.mapviewer.model.map.Comment;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.model.map.reaction.Reaction
;
import
lcsb.mapviewer.model.map.species.Element
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.persist.dao.map.ReactionDao
;
import
lcsb.mapviewer.persist.dao.map.species.ElementDao
;
import
lcsb.mapviewer.services.interfaces.ICommentService
;
...
...
@@ -245,7 +246,7 @@ 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
)
String
name
,
String
email
,
String
content
,
boolean
pinned
,
Point2D
pointCoordinates
,
String
submodelId
,
User
owner
)
throws
QueryException
{
Model
model
=
getModelService
().
getLastModelByProjectId
(
projectId
);
if
(
model
==
null
)
{
...
...
@@ -280,7 +281,7 @@ public class CommentRestImpl extends BaseRestImpl {
}
Comment
comment
=
commentService
.
addComment
(
name
,
email
,
content
,
pointCoordinates
,
commentedObject
,
pinned
,
submodel
);
submodel
,
owner
);
return
preparedComment
(
comment
,
createCommentColumnSet
(
""
));
}
...
...
service/src/main/java/lcsb/mapviewer/services/impl/CommentService.java
View file @
0995fe1a
...
...
@@ -76,7 +76,7 @@ public class CommentService implements ICommentService {
@Override
public
Comment
addComment
(
String
name
,
String
email
,
String
content
,
Point2D
coordinates
,
Object
object
,
boolean
pinned
,
Model
submodel
)
{
boolean
pinned
,
Model
submodel
,
User
owner
)
{
Comment
comment
=
new
Comment
();
comment
.
setName
(
name
);
comment
.
setEmail
(
email
);
...
...
@@ -87,7 +87,7 @@ public class CommentService implements ICommentService {
comment
.
setTableName
(
object
.
getClass
());
comment
.
setTableId
(
ObjectUtils
.
getIdOfObject
(
object
));
}
comment
.
setUser
(
null
);
comment
.
setUser
(
owner
);
comment
.
setPinned
(
pinned
);
commentDao
.
add
(
comment
);
...
...
service/src/main/java/lcsb/mapviewer/services/interfaces/ICommentService.java
View file @
0995fe1a
...
...
@@ -38,7 +38,7 @@ public interface ICommentService {
* @return comment object created based on the data provided as parameters
*/
Comment
addComment
(
String
name
,
String
email
,
String
content
,
Point2D
coordinates
,
Object
object
,
boolean
pinned
,
Model
submodel
);
boolean
pinned
,
Model
submodel
,
User
owner
);
/**
* This method remove comment. Comment is not removed from the system, only
...
...
service/src/test/java/lcsb/mapviewer/services/impl/CommentServiceTest.java
View file @
0995fe1a
...
...
@@ -64,11 +64,11 @@ public class CommentServiceTest extends ServiceTestFunctions {
@Test
public
void
testGetAgregatedComments
()
throws
Exception
{
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Conteneta 1"
,
new
Point2D
.
Double
(
0
,
1
),
alias
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetb 2"
,
new
Point2D
.
Double
(
0
,
2
),
alias
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 3"
,
new
Point2D
.
Double
(
0
,
3
),
alias2
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 4"
,
new
Point2D
.
Double
(
0
,
4
),
null
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 5"
,
new
Point2D
.
Double
(
0
,
5
),
null
,
false
,
model
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Conteneta 1"
,
new
Point2D
.
Double
(
0
,
1
),
alias
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetb 2"
,
new
Point2D
.
Double
(
0
,
2
),
alias
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 3"
,
new
Point2D
.
Double
(
0
,
3
),
alias2
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 4"
,
new
Point2D
.
Double
(
0
,
4
),
null
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
commentService
.
addComment
(
"John Doe"
,
"a@a.pl"
,
"Contenetc 5"
,
new
Point2D
.
Double
(
0
,
5
),
null
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
CommentService
service
=
new
CommentService
(
null
,
null
,
null
,
null
);
service
.
setCommentDao
(
commentDao
);
List
<
List
<
Comment
>>
comments
=
service
.
getAgregatedComments
(
model
,
null
);
...
...
@@ -89,7 +89,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
@Test
public
void
testAddComment
()
throws
Exception
{
long
counter
=
commentService
.
getCommentCount
();
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
null
,
false
,
model
);
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
null
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
long
counter2
=
commentService
.
getCommentCount
();
assertEquals
(
counter
+
1
,
counter2
);
commentDao
.
delete
(
feedback
);
...
...
@@ -99,7 +99,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
public
void
testAddCommentForReaction
()
throws
Exception
{
long
counter
=
commentService
.
getCommentCount
();
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
model
.
getReactions
().
iterator
().
next
(),
false
,
model
);
model
.
getReactions
().
iterator
().
next
(),
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
long
counter2
=
commentService
.
getCommentCount
();
assertEquals
(
counter
+
1
,
counter2
);
commentDao
.
delete
(
feedback
);
...
...
@@ -109,7 +109,7 @@ public class CommentServiceTest extends ServiceTestFunctions {
public
void
testAddCommentForAlias
()
throws
Exception
{
Element
alias
=
model
.
getElementByElementId
(
"sa1"
);
long
counter
=
commentService
.
getCommentCount
();
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
alias
,
false
,
model
);
Comment
feedback
=
commentService
.
addComment
(
"a"
,
"b"
,
"c"
,
new
Point2D
.
Double
(
0
,
0
),
alias
,
false
,
model
,
userDao
.
getUserByLogin
(
ADMIN_BUILT_IN_LOGIN
)
);
long
counter2
=
commentService
.
getCommentCount
();
assertEquals
(
counter
+
1
,
counter2
);
commentDao
.
delete
(
feedback
);
...
...
web/src/test/java/lcsb/mapviewer/web/CommentControllerIntegrationTest.java
View file @
0995fe1a
...
...
@@ -40,6 +40,8 @@ import lcsb.mapviewer.services.interfaces.IUserService;
@Rollback
public
class
CommentControllerIntegrationTest
extends
ControllerIntegrationTest
{
Logger
logger
=
LogManager
.
getLogger
();
private
static
final
String
TEST_PROJECT
=
"test_project"
;
private
static
final
String
TEST_USER_PASSWORD
=
"test_user_pass"
;
private
static
final
String
TEST_USER_LOGIN
=
"test_user"
;
...
...
@@ -47,10 +49,10 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
private
static
final
String
TEST_CURATOR_LOGIN
=
"test_curator"
;
private
static
final
String
TEST_ADMIN_PASSWORD
=
"test_admin"
;
private
static
final
String
TEST_ADMIN_LOGIN
=
"test_admin"
;
Logger
logger
=
LogManager
.
getLogger
();
private
ModelData
map
;
private
Reaction
reaction
;
private
Element
element
;
private
Project
project
;
@Autowired
private
CommentDao
commentDao
;
...
...
@@ -63,7 +65,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Before
public
void
setup
()
{
Project
project
=
createProject
(
TEST_PROJECT
);
project
=
createProject
(
TEST_PROJECT
);
project
.
setOwner
(
userService
.
getUserByLogin
(
BUILT_IN_TEST_ADMIN_LOGIN
));
map
=
project
.
getModels
().
iterator
().
next
();
reaction
=
map
.
getReactions
().
iterator
().
next
();
...
...
@@ -318,7 +320,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test
public
void
testRemoveAsOwner
()
throws
Exception
{
User
user
=
create
Curato
r
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
User
user
=
create
Use
r
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
,
project
);
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
...
...
@@ -599,7 +601,7 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
@Test
public
void
testAddElementCommentAsUserWithAccess
()
throws
Exception
{
createUser
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
,
map
.
getProject
());
User
user
=
createUser
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
,
map
.
getProject
());
MockHttpSession
session
=
createSession
(
TEST_USER_LOGIN
,
TEST_USER_PASSWORD
);
...
...
@@ -621,6 +623,9 @@ public class CommentControllerIntegrationTest extends ControllerIntegrationTest
.
andExpect
(
status
().
is2xxSuccessful
());
assertEquals
(
1
,
commentDao
.
getCommentByModel
(
map
,
null
,
null
).
size
());
Comment
comment
=
commentDao
.
getCommentByModel
(
map
,
null
,
null
).
get
(
0
);
assertEquals
(
"Owner of the comment wasn't set properly"
,
user
,
comment
.
getUser
());
}
@Test
...
...
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