Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
minerva
core
Commits
8a1d6600
Commit
8a1d6600
authored
Jan 04, 2017
by
Piotr Gawron
Browse files
remove of unused feedback backend functionality
additional small fixes on service layer (security errors were thrown too often) tests fixed
parent
6dba4a2a
Changes
7
Show whitespace changes
Inline
Side-by-side
service/src/main/java/lcsb/mapviewer/services/impl/ModelService.java
View file @
8a1d6600
...
...
@@ -175,7 +175,7 @@ public class ModelService implements IModelService {
// lets copy model - it will access all elements...
new
CopyCommand
(
model
).
execute
();
for
(
ModelData
m:
model
.
getProject
().
getModels
())
{
for
(
ModelData
m
:
model
.
getProject
().
getModels
())
{
new
CopyCommand
(
m
.
getModel
()).
execute
();
}
...
...
@@ -188,10 +188,14 @@ public class ModelService implements IModelService {
}
}
}
if
(!
userService
.
userHasPrivilege
(
token
,
PrivilegeType
.
VIEW_PROJECT
,
model
.
getProject
()))
{
if
(
userService
.
userHasPrivilege
(
token
,
PrivilegeType
.
VIEW_PROJECT
,
model
.
getProject
()))
{
return
model
;
}
else
if
(
userService
.
userHasPrivilege
(
token
,
PrivilegeType
.
ADD_MAP
))
{
return
model
;
}
else
{
logger
.
debug
(
userService
.
getUserByToken
(
token
).
getLogin
());
throw
new
SecurityException
(
"User doesn't have access to project"
);
}
return
model
;
}
@Override
...
...
service/src/main/java/lcsb/mapviewer/services/impl/ProjectService.java
View file @
8a1d6600
...
...
@@ -524,10 +524,13 @@ public class ProjectService implements IProjectService {
@Override
public
ProjectView
getProjectViewById
(
Integer
id
,
AuthenticationToken
token
)
throws
UserAccessException
{
Project
project
=
projectDao
.
getById
(
id
);
if
(!
userService
.
userHasPrivilege
(
token
,
PrivilegeType
.
VIEW_PROJECT
,
project
))
{
if
(
userService
.
userHasPrivilege
(
token
,
PrivilegeType
.
VIEW_PROJECT
,
project
))
{
return
projectViewFactory
.
create
(
project
);
}
else
if
(
userService
.
userHasPrivilege
(
token
,
PrivilegeType
.
ADD_MAP
))
{
return
projectViewFactory
.
create
(
project
);
}
else
{
throw
new
UserAccessException
(
"User cannot access project"
);
}
return
projectViewFactory
.
create
(
project
);
}
/**
...
...
web/src/main/java/lcsb/mapviewer/bean/FeedbackBean.java
View file @
8a1d6600
package
lcsb.mapviewer.bean
;
import
java.awt.geom.Point2D
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -11,29 +10,15 @@ import javax.faces.bean.ViewScoped;
import
javax.faces.event.ActionEvent
;
import
org.apache.log4j.Logger
;
import
org.primefaces.model.map.LatLng
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.common.Pair
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
import
lcsb.mapviewer.common.exception.NotImplementedException
;
import
lcsb.mapviewer.model.Project
;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.model.map.reaction.Modifier
;
import
lcsb.mapviewer.model.map.reaction.Product
;
import
lcsb.mapviewer.model.map.reaction.Reactant
;
import
lcsb.mapviewer.model.map.reaction.Reaction
;
import
lcsb.mapviewer.model.map.species.Element
;
import
lcsb.mapviewer.model.user.PrivilegeType
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.services.interfaces.ICommentService
;
import
lcsb.mapviewer.services.interfaces.ISearchService
;
import
lcsb.mapviewer.services.interfaces.IUserService
;
import
lcsb.mapviewer.services.search.ElementIdentifierDetails
;
import
lcsb.mapviewer.services.search.comment.FullCommentView
;
import
lcsb.mapviewer.services.search.comment.FullCommentViewFactory
;
import
lcsb.mapviewer.services.search.data.ElementIdentifier
;
import
lcsb.mapviewer.services.utils.gmap.CoordinationConverter
;
import
lcsb.mapviewer.services.view.CommentView
;
/**
...
...
@@ -44,23 +29,7 @@ import lcsb.mapviewer.services.view.CommentView;
*/
@ManagedBean
(
name
=
"feedbackMB"
)
@ViewScoped
public
class
FeedbackBean
extends
AbstractMarkerManagerBean
<
FullCommentView
>
implements
Serializable
{
/**
* How many elements to comment should be seen in drop down list on the client
* side.
*/
private
static
final
int
MAX_FEEDBACK_ELEMENTS_AMOUNT
=
5
;
/**
* What's the name of the general comment.
*/
private
static
final
String
GENERAL_POSITION
=
"<General>"
;
/**
* Feedback form on the client side.
*/
private
static
final
String
FEEDBACK_FORM_STRING
=
"feedbackForm"
;
public
class
FeedbackBean
extends
AbstractManagedBean
implements
Serializable
{
/**
*
...
...
@@ -72,56 +41,11 @@ public class FeedbackBean extends AbstractMarkerManagerBean<FullCommentView> imp
*/
private
static
Logger
logger
=
Logger
.
getLogger
(
FeedbackBean
.
class
);
/**
* Element to which we create comment.
*/
private
String
feedbackElement
=
GENERAL_POSITION
;
/**
* List of possible elements to comment (names only).
*/
private
List
<
String
>
feedbackElementStringList
=
new
ArrayList
<>();
/**
* Information if the comment should be visible.
*/
private
boolean
pinned
=
true
;
/**
* Who put a comment.
*/
private
String
name
=
""
;
/**
* Email of a person that comments.
*/
private
String
email
=
""
;
/**
* Content of the comment.
*/
private
String
content
=
""
;
/**
* List of comments available for current project.
*/
private
List
<
CommentView
>
commentList
=
null
;
/**
* Coordinates where comment should be placed.
*/
private
Point2D
lastCommentCoordinates
=
null
;
/**
* List of possible elements to comment.
*/
private
transient
List
<
Object
>
feedbackElementList
=
new
ArrayList
<>();
/**
* Submodel that is currently commented.
*/
private
transient
Model
commentedSubmodel
=
null
;
/**
* Bean used for communication with the client side about the data related to
* users (including information about currently logged user).
...
...
@@ -160,195 +84,6 @@ public class FeedbackBean extends AbstractMarkerManagerBean<FullCommentView> imp
@ManagedProperty
(
value
=
"#{UserService}"
)
private
transient
IUserService
userService
;
/**
* Method invoked by client to send a comment.
*
* @param actionEvent
* event from thefrom the client
*/
public
void
sendFeedback
(
final
ActionEvent
actionEvent
)
{
String
feedbackName
=
getRequestParameter
(
FEEDBACK_FORM_STRING
+
":feedbackName"
);
String
feedbackEmail
=
getRequestParameter
(
FEEDBACK_FORM_STRING
+
":feedbackEmail"
);
String
feedbackContent
=
getRequestParameter
(
FEEDBACK_FORM_STRING
+
":feedbackContent"
);
// find which object we are commenting on
Object
tmp
=
null
;
for
(
Object
object
:
feedbackElementList
)
{
if
(
feedbackElement
.
equals
(
getDescription
(
object
)))
{
tmp
=
object
;
}
}
// add a comment to db
commentService
.
addComment
(
feedbackName
,
feedbackEmail
,
feedbackContent
,
getCurrentTopModel
(),
lastCommentCoordinates
,
tmp
,
pinned
,
commentedSubmodel
);
clearNameAndEmail
();
content
=
""
;
// refresh list of comments on the client side
refreshComments
();
}
/**
* Set default values to {@link #name} and {@link #email}.
*/
private
void
clearNameAndEmail
()
{
if
(
getUserBean
().
getLoggedUser
()
!=
null
)
{
User
user
=
getUserBean
().
getLoggedUser
();
if
(
Configuration
.
ANONYMOUS_LOGIN
.
equals
(
user
.
getLogin
()))
{
name
=
""
;
email
=
""
;
}
else
{
name
=
user
.
getName
()
+
" "
+
user
.
getSurname
();
email
=
user
.
getEmail
();
}
}
}
/**
* Method invoked by client to update list of elements to be commented based
* on coordinates in request params.
*
* @param actionEvent
* event from thefrom the client
*/
public
void
updateCommentList
(
final
ActionEvent
actionEvent
)
{
String
latCoord
=
getRequestParameter
(
"latCoord"
);
String
lngCoord
=
getRequestParameter
(
"lngCoord"
);
String
modelIdentifier
=
getRequestParameter
(
"submodelId"
);
LatLng
latLng
;
double
lat
=
Double
.
parseDouble
(
latCoord
);
double
lng
=
Double
.
parseDouble
(
lngCoord
);
latLng
=
new
LatLng
(
lat
,
lng
);
commentedSubmodel
=
getCurrentTopModel
().
getSubmodelById
(
modelIdentifier
);
CoordinationConverter
cc
=
new
CoordinationConverter
(
commentedSubmodel
);
lastCommentCoordinates
=
cc
.
toPoint
(
latLng
);
feedbackElementList
=
searchService
.
getClosestElements
(
commentedSubmodel
,
lastCommentCoordinates
,
MAX_FEEDBACK_ELEMENTS_AMOUNT
);
feedbackElementStringList
=
new
ArrayList
<
String
>();
feedbackElementStringList
.
add
(
GENERAL_POSITION
);
for
(
Object
object
:
feedbackElementList
)
{
String
desc
=
getDescription
(
object
);
feedbackElementStringList
.
add
(
desc
);
}
}
/**
* Methods returns a list of elements that might be possible commented on
* based on the coordinates.
*
* @return list of closes elements (to the last coordinates of the mouse on
* the map) on the map that can be commoneted on
*/
public
List
<
String
>
getFeedbackElementStringList
()
{
return
feedbackElementStringList
;
}
/**
* This method get a short description of the object to comment.
*
* @param object
* object for which we want a description
* @return short description of the object
*/
public
String
getDescription
(
final
Object
object
)
{
if
(
object
instanceof
Reaction
)
{
return
"Reaction: "
+
((
Reaction
)
object
).
getIdReaction
();
}
else
if
(
object
instanceof
Element
)
{
Element
alias
=
(
Element
)
object
;
return
alias
.
getStringType
()
+
": "
+
alias
.
getName
();
}
else
{
throw
new
InvalidArgumentException
(
"Unknown class type: "
+
object
.
getClass
());
}
}
/**
* Sets list of elements for possible comment objects.
*
* @param feedbackElementStringList
* list of string representation of the elements to be commoneted on
*/
public
void
setFeedbackElementStringList
(
final
List
<
String
>
feedbackElementStringList
)
{
this
.
feedbackElementStringList
=
feedbackElementStringList
;
}
/**
* This method returns a description of the reactants for the selected
* reaction. TODO should be improved
*
* @return description of the reactants for the selected reaction
*/
public
String
getElementDescription1
()
{
// iterate over every potentail element to comment on
for
(
Object
object
:
feedbackElementList
)
{
// check only reactions
if
(
object
instanceof
Reaction
)
{
Reaction
reaction
=
(
Reaction
)
object
;
// with the same description as currently selected
if
(
feedbackElement
.
equals
(
getDescription
(
object
)))
{
String
result
=
"Reactants: "
;
for
(
Reactant
reactant
:
reaction
.
getReactants
())
{
result
+=
reactant
.
getElement
().
getName
()
+
", "
;
}
return
result
;
}
}
}
return
""
;
}
/**
* This method returns a description of the products for the selected
* reaction. TODO should be improved
*
* @return description of the products for the selected reaction
*/
public
String
getElementDescription3
()
{
// iterate over every potential element to comment on
for
(
Object
object
:
feedbackElementList
)
{
// check only reactions
if
(
object
instanceof
Reaction
)
{
Reaction
reaction
=
(
Reaction
)
object
;
// with the same description as currently selected object
if
(
feedbackElement
.
equals
(
getDescription
(
object
)))
{
String
result
=
"Products: "
;
for
(
Product
product
:
reaction
.
getProducts
())
{
result
+=
product
.
getElement
().
getName
()
+
", "
;
}
return
result
;
}
}
}
return
""
;
}
/**
* This method returns a description of the modifiers for the selected
* reaction. TODO should be improved
*
* @return description of the modifiers for the selected reaction
*/
public
String
getElementDescription2
()
{
// iterate over every potential element to comment on
for
(
Object
object
:
feedbackElementList
)
{
// check only reactions
if
(
object
instanceof
Reaction
)
{
Reaction
reaction
=
(
Reaction
)
object
;
// with the same description as currently selected object
if
(
feedbackElement
.
equals
(
getDescription
(
object
)))
{
String
result
=
"Modifiers: "
;
for
(
Modifier
modifier
:
reaction
.
getModifiers
())
{
result
+=
modifier
.
getElement
().
getName
()
+
", "
;
}
return
result
;
}
}
}
return
""
;
}
/**
* Method called to remove comment from the map.
*
...
...
@@ -368,7 +103,7 @@ public class FeedbackBean extends AbstractMarkerManagerBean<FullCommentView> imp
}
catch
(
InvalidArgumentException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
refreshComment
s
();
refreshComment
List
();
}
/**
...
...
@@ -409,25 +144,6 @@ public class FeedbackBean extends AbstractMarkerManagerBean<FullCommentView> imp
@Override
public
void
clear
()
{
setCommentList
(
new
ArrayList
<>());
clearResults
();
refreshDataInJavascript
();
}
/**
* @return the feedbackElement
* @see #feedbackElement
*/
public
String
getFeedbackElement
()
{
return
feedbackElement
;
}
/**
* @param feedbackElement
* the feedbackElement to set
* @see #feedbackElement
*/
public
void
setFeedbackElement
(
String
feedbackElement
)
{
this
.
feedbackElement
=
feedbackElement
;
}
/**
...
...
@@ -498,74 +214,6 @@ public class FeedbackBean extends AbstractMarkerManagerBean<FullCommentView> imp
this
.
userService
=
userService
;
}
/**
* @return the pinned
* @see #pinned
*/
public
boolean
isPinned
()
{
return
pinned
;
}
/**
* @param pinned
* the pinned to set
* @see #pinned
*/
public
void
setPinned
(
boolean
pinned
)
{
this
.
pinned
=
pinned
;
}
/**
* @return the name
* @see #name
*/
public
String
getName
()
{
return
name
;
}
/**
* @param name
* the name to set
* @see #name
*/
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
/**
* @return the email
* @see #email
*/
public
String
getEmail
()
{
return
email
;
}
/**
* @param email
* the email to set
* @see #email
*/
public
void
setEmail
(
String
email
)
{
this
.
email
=
email
;
}
/**
* @return the content
* @see #content
*/
public
String
getContent
()
{
return
content
;
}
/**
* @param content
* the content to set
* @see #content
*/
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
/**
* @return the commentList
* @see #commentList
...
...
@@ -586,42 +234,6 @@ public class FeedbackBean extends AbstractMarkerManagerBean<FullCommentView> imp
this
.
commentList
=
commentList
;
}
@Override
public
void
init
()
{
clearNameAndEmail
();
}
/**
* Refresh list of comments to be visualized.
*/
protected
void
refreshComments
()
{
clearResults
();
for
(
FullCommentView
marker
:
commentService
.
getCommentMarkers
(
getCurrentTopModel
()))
{
addResult
(
marker
);
}
refreshDataInJavascript
();
}
@Override
protected
List
<
ElementIdentifier
>
getLightElementsForSearchResult
(
FullCommentView
view
)
{
return
new
FullCommentViewFactory
().
searchResultToElementIdentifier
(
view
,
getCurrentTopModel
());
}
@Override
protected
ElementIdentifierDetails
getElementInformationForResult
(
ElementIdentifier
element
,
FullCommentView
result
)
{
throw
new
NotImplementedException
();
}
@Override
protected
List
<
Pair
<
String
,
ElementIdentifierDetails
>>
getElementInformationForResult
(
ElementIdentifier
element
)
{
List
<
Pair
<
String
,
ElementIdentifierDetails
>>
result
=
new
ArrayList
<>();
int
counter
=
0
;
for
(
ElementIdentifierDetails
detail
:
commentService
.
getElementInformationForResult
(
element
,
getCurrentTopModel
()))
{
result
.
add
(
new
Pair
<
String
,
ElementIdentifierDetails
>(
""
+
(
counter
++),
detail
));
}
return
result
;
}
/**
* Returns currently browsed map.
*
...
...
@@ -658,4 +270,9 @@ public class FeedbackBean extends AbstractMarkerManagerBean<FullCommentView> imp
this
.
mapBean
=
mapBean
;
}
@Override
public
void
init
()
{
clear
();
}
}
web/src/main/java/lcsb/mapviewer/bean/ProjectBean.java
View file @
8a1d6600
...
...
@@ -740,7 +740,7 @@ public class ProjectBean extends AbstractManagedBean implements Serializable {
logger
.
debug
(
"Selected project was set to: "
+
this
.
selectedProject
.
getProjectId
());
}
catch
(
PropertyVetoException
e
)
{
this
.
selectedProject
=
oldValue
;
sendError
(
e
.
getMessage
());
sendError
(
e
.
getMessage
()
,
e
);
}
}
...
...
web/src/test/java/lcsb/mapviewer/bean/DrugBeanTest.java
View file @
8a1d6600
...
...
@@ -12,7 +12,6 @@ import org.junit.After;
import
org.junit.Before
;
import
org.junit.Test
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.common.Pair
;
import
lcsb.mapviewer.converter.ConverterParams
;
import
lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser
;
...
...
@@ -20,7 +19,6 @@ import lcsb.mapviewer.model.Project;
import
lcsb.mapviewer.model.map.model.Model
;
import
lcsb.mapviewer.services.search.ElementIdentifierDetails
;
import
lcsb.mapviewer.services.search.data.ElementIdentifier
;
import
lcsb.mapviewer.services.view.AuthenticationToken
;
public
class
DrugBeanTest
extends
WebTestFunctions
{
...
...
@@ -39,15 +37,15 @@ public class DrugBeanTest extends WebTestFunctions {
// commit at the end of the test case
dbUtils
.
createSessionForCurrentThread
();
Project
p
=
projectService
.
getProjectByProjectId
(
projectId
,
t
oken
);
Project
p
=
projectService
.
getProjectByProjectId
(
projectId
,
adminT
oken
);
if
(
p
!=
null
)
{
projectService
.
removeProject
(
p
,
null
,
false
,
t
oken
);
projectService
.
removeProject
(
p
,
null
,
false
,
adminT
oken
);
}
}
@After
public
void
tearDown
()
throws
Exception
{
Project
p
=
projectService
.
getProjectByProjectId
(
projectId
,
t
oken
);
Project
p
=
projectService
.
getProjectByProjectId
(
projectId
,
adminT
oken
);
if
(
p
!=
null
)
{
projectService
.
removeProject
(
p
,
null
,
false
,
adminToken
);
}
...
...
@@ -86,10 +84,13 @@ public class DrugBeanTest extends WebTestFunctions {
projectDao
.
refresh
(
project
);
model
=
project
.
getModels
().
iterator
().
next
().
getModel
();
getUserBean
().
setAuthenticationToken
(
adminToken
);
// set current map
getMapBean
().
setCurrentMapId
(
project
.
getProjectId
());
List
<
Pair
<
String
,
ElementIdentifierDetails
>>
result
=
drugBean
.
getElementInformationForResult
(
new
ElementIdentifier
(
model
.
getElementByElementId
(
"sa2"
),
""
));
List
<
Pair
<
String
,
ElementIdentifierDetails
>>
result
=
drugBean
.
getElementInformationForResult
(
new
ElementIdentifier
(
model
.
getElementByElementId
(
"sa2"
),
""
));
assertTrue
(
result
.
size
()
>
0
);
...
...
web/src/test/java/lcsb/mapviewer/bean/LayoutBeanTest.java
View file @
8a1d6600
...
...
@@ -14,6 +14,7 @@ import org.junit.Before;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
lcsb.mapviewer.common.Configuration
;
import
lcsb.mapviewer.converter.ConverterParams
;
import
lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser
;
import
lcsb.mapviewer.model.Project
;
...
...
@@ -23,6 +24,7 @@ import lcsb.mapviewer.model.map.model.Model;
import
lcsb.mapviewer.model.user.BasicPrivilege
;
import
lcsb.mapviewer.model.user.ObjectPrivilege
;
import
lcsb.mapviewer.model.user.PrivilegeType
;
import
lcsb.mapviewer.model.user.User
;
import
lcsb.mapviewer.persist.dao.map.LayoutDao
;
import
lcsb.mapviewer.services.view.ProjectView
;
...
...
@@ -56,7 +58,7 @@ public class LayoutBeanTest extends WebTestFunctions {
createUser
();
Project
p
=
projectService
.
getProjectByProjectId
(
projectId
,
t
oken
);
Project
p
=
projectService
.
getProjectByProjectId
(
projectId
,
adminT
oken
);
if
(
p
!=
null
)
{
projectService
.
removeProject
(
p
,
null
,
false
,
adminToken
);
}
...
...
@@ -67,7 +69,7 @@ public class LayoutBeanTest extends WebTestFunctions {
public
void
tearDown
()
throws
Exception
{
userDao
.
delete
(
user
);