Skip to content
Snippets Groups Projects
Commit 1db14cee authored by Piotr Gawron's avatar Piotr Gawron
Browse files

unused CommentView removed

parent 36fd3fd1
No related branches found
No related tags found
1 merge request!207Resolve "remove unused JSF code"
Showing
with 0 additions and 681 deletions
......@@ -13,8 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import lcsb.mapviewer.common.ObjectUtils;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidClassException;
import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.Comment;
......@@ -31,15 +29,9 @@ import lcsb.mapviewer.services.interfaces.ICommentService;
import lcsb.mapviewer.services.interfaces.IConfigurationService;
import lcsb.mapviewer.services.interfaces.IModelService;
import lcsb.mapviewer.services.interfaces.IUserService;
import lcsb.mapviewer.services.search.ElementIdentifierDetails;
import lcsb.mapviewer.services.search.comment.CommentDetails;
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.search.data.ElementIdentifier.ElementIdentifierType;
import lcsb.mapviewer.services.utils.EmailSender;
import lcsb.mapviewer.services.view.CommentView;
import lcsb.mapviewer.services.view.CommentViewFactory;
/**
* This class is responsible for all services connected with comments
......@@ -87,12 +79,6 @@ public class CommentService implements ICommentService {
@Autowired
private IConfigurationService configurationService;
/**
* Factory object used for creation fo {@link CommentView} objects.
*/
@Autowired
private CommentViewFactory commentViewFactory;
@Override
public Comment addComment(String name, String email, String content, Model model, Point2D coordinates, Object object,
boolean pinned, Model submodel) {
......@@ -188,23 +174,6 @@ public class CommentService implements ICommentService {
}
}
@Override
public List<CommentView> getCommentsByMap(Model model, String token) throws SecurityException {
boolean editComments = userService.userHasPrivilege(token, PrivilegeType.EDIT_COMMENTS_PROJECT, model.getProject());
boolean viewProject = userService.userHasPrivilege(token, PrivilegeType.VIEW_PROJECT, model.getProject());
if (!editComments && !viewProject) {
throw new UserAccessException("You have no privileges to see comments for given project");
}
List<Comment> comments = commentDao.getCommentByModel(model, null, null);
List<CommentView> commentList = new ArrayList<>();
for (Comment comment : comments) {
CommentView row = commentViewFactory.create(comment, model);
commentList.add(row);
}
return commentList;
}
@Override
public long getCommentCount() {
return commentDao.getCount();
......@@ -306,12 +275,6 @@ public class CommentService implements ICommentService {
return result;
}
@Override
public List<FullCommentView> getCommentMarkers(Model model) {
List<List<Comment>> comments = getAgregatedComments(model, true);
return agregatedCommentsIntoMarker(comments, model);
}
@Override
public void removeCommentsForModel(ModelData model) {
List<Comment> comments = commentDao.getCommentByModel(model, null, null);
......@@ -320,67 +283,6 @@ public class CommentService implements ICommentService {
}
}
/**
* Returns {@link CommentDetails detailed information} about comments for a
* specified element.
*
* @param element
* element for which we are looking for detailed information
* @param model
* model where we are looking for the information
* @return {@link CommentDetails detailed information} about comments for a
* specified element
*/
public List<ElementIdentifierDetails> getElementInformationForResult(ElementIdentifier element, Model model) {
// TODO refactor!!!!
// it's slow...
List<FullCommentView> comments = getCommentMarkers(model);
List<ElementIdentifierDetails> result = new ArrayList<>();
if (ElementIdentifierType.REACTION.getJsName().equalsIgnoreCase(element.getType())) {
for (FullCommentView comment : comments) {
if (Reaction.class.equals(comment.getType())) {
if (comment.getIdObject().equals(element.getObjectId())
&& comment.getModelId().equals(element.getModelId())) {
for (Pair<String, String> c : comment.getComments()) {
result.add(new CommentDetails(c.getLeft(), c.getRight()));
}
return result;
}
}
}
return result;
} else if (ElementIdentifierType.POINT.getJsName().equalsIgnoreCase(element.getType())) {
for (FullCommentView comment : comments) {
if (Point2D.class.equals(comment.getType())) {
if (equalPoints(comment.getUniqueId(), element.getObjectId())) {
for (Pair<String, String> c : comment.getComments()) {
result.add(new CommentDetails(c.getLeft(), c.getRight()));
}
return result;
}
}
}
return result;
} else if (ElementIdentifierType.ALIAS.getJsName().equalsIgnoreCase(element.getType())) {
for (FullCommentView comment : comments) {
if (Element.class.equals(comment.getType())) {
if (comment.getIdObject().equals(element.getObjectId())
&& comment.getModelId().equals(element.getModelId())) {
for (Pair<String, String> c : comment.getComments()) {
result.add(new CommentDetails(c.getLeft(), c.getRight()));
}
return result;
}
}
}
return result;
} else {
throw new InvalidArgumentException("Unknown clas stype: " + element.getType());
}
}
/**
* Checks if identifier of the points refer to the same point.
*
......
......@@ -11,9 +11,7 @@ import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.SecurityException;
import lcsb.mapviewer.services.UserAccessException;
import lcsb.mapviewer.services.search.ElementIdentifierDetails;
import lcsb.mapviewer.services.search.comment.FullCommentView;
import lcsb.mapviewer.services.search.data.ElementIdentifier;
import lcsb.mapviewer.services.view.CommentView;
/**
* Service responsible for comments functionality.
......@@ -63,17 +61,6 @@ public interface ICommentService {
void deleteComment(Comment comment, String token, String reason) throws UserAccessException, SecurityException;
/**
* Method returns all comments for a given map.
*
* @param model
* given map
* @return list of the comments to the map
* @throws UserAccessException
* @throws SecurityException
*/
List<CommentView> getCommentsByMap(Model model, String token) throws UserAccessException, SecurityException;
List<Comment> getCommentsByProject(Project project, String token) throws UserAccessException, SecurityException;
/**
......@@ -91,15 +78,6 @@ public interface ICommentService {
*/
void removeCommentsForModel(Model model);
/**
* This method returns marker for all comments in a model.
*
* @param model
* object to which we are looking for comments
* @return list of markers for comments
*/
List<FullCommentView> getCommentMarkers(Model model);
/**
* Removes comments from the model.
*
......@@ -108,17 +86,6 @@ public interface ICommentService {
*/
void removeCommentsForModel(ModelData model);
/**
* Returns detailed comment information about element.
*
* @param element
* element for which we are looking for comments
* @param model
* model where we are looking for comments
* @return detailed comment information about element
*/
List<ElementIdentifierDetails> getElementInformationForResult(ElementIdentifier element, Model model);
Comment getCommentById(String commentId);
}
package lcsb.mapviewer.services.view;
import java.io.Serializable;
import lcsb.mapviewer.model.map.Comment;
/**
* View representation of the Comment.
*
* @author Piotr Gawron
*
*/
public class CommentView extends AbstractView<Comment> implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Author of the comment.
*/
private String author;
/**
* Email of the comment.
*/
private String email;
/**
* Content of the comment.
*/
private String content;
/**
* Title of the comment.
*/
private String title;
/**
* Is the comment visible on the map.
*/
private String pinned;
/**
* Is the comment removed.
*/
private String removed;
/**
* X coordinate on the map.
*/
private String xCoord;
/**
* Y coordinate on the map.
*/
private String yCoord;
/**
* Zoom level at which comment should be investigated on the map (to see
* details).
*/
private String zoom;
/**
* Submap on which comment was placed.
*/
private String submap;
/**
* Constructor that initialize the view with the data from original comment.
*
* @param comment
* data required for initialization
*/
protected CommentView(final Comment comment) {
super(comment);
}
/**
* Default constructor. Should be used only for deserialization.
*/
protected CommentView() {
}
/**
* @return the author
* @see #author
*/
public String getAuthor() {
return author;
}
/**
* @param author
* the author to set
* @see #author
*/
public void setAuthor(String author) {
this.author = author;
}
/**
* @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 title
* @see #title
*/
public String getTitle() {
return title;
}
/**
* @param title
* the title to set
* @see #title
*/
public void setTitle(String title) {
this.title = title;
}
/**
* @return the pinned
* @see #pinned
*/
public String getPinned() {
return pinned;
}
/**
* @param pinned
* the pinned to set
* @see #pinned
*/
public void setPinned(String pinned) {
this.pinned = pinned;
}
/**
* @return the removed
* @see #removed
*/
public String getRemoved() {
return removed;
}
/**
* @param removed
* the removed to set
* @see #removed
*/
public void setRemoved(String removed) {
this.removed = removed;
}
/**
* @return the xCoord
* @see #xCoord
*/
public String getxCoord() {
return xCoord;
}
/**
* @param xCoord
* the xCoord to set
* @see #xCoord
*/
public void setxCoord(String xCoord) {
this.xCoord = xCoord;
}
/**
* @return the yCoord
* @see #yCoord
*/
public String getyCoord() {
return yCoord;
}
/**
* @param yCoord
* the yCoord to set
* @see #yCoord
*/
public void setyCoord(String yCoord) {
this.yCoord = yCoord;
}
/**
* @return the zoom
* @see #zoom
*/
public String getZoom() {
return zoom;
}
/**
* @param zoom
* the zoom to set
* @see #zoom
*/
public void setZoom(String zoom) {
this.zoom = zoom;
}
/**
* @param pinned
* the pinned to set
* @see #pinned
*/
public void setPinned(final boolean pinned) {
if (pinned) {
setPinned("YES");
} else {
setPinned("NO");
}
}
/**
* Sets x coordinate.
*
* @param x
* x coordinate to set
* @see #xCoord
*/
public void setxCoord(double x) {
this.xCoord = x + "";
}
/**
* Sets y coordinate.
*
* @param y
* y coordinate to set
* @see #yCoord
*/
public void setyCoord(double y) {
this.yCoord = y + "";
}
/**
* @return the submap
* @see #submap
*/
public String getSubmap() {
return submap;
}
/**
* @param submap
* the submap to set
* @see #submap
*/
public void setSubmap(String submap) {
this.submap = submap;
}
};
package lcsb.mapviewer.services.view;
import java.awt.geom.Point2D;
import org.apache.log4j.Logger;
import com.google.gson.Gson;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.NotImplementedException;
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;
/**
* Factory class for {@link CommentView} class.
*
* @author Piotr Gawron
*
*/
public class CommentViewFactory extends AbstractViewFactory<Comment, CommentView> {
/**
* Default class logger.
*/
private static Logger logger = Logger.getLogger(CommentViewFactory.class);
@Override
public CommentView create(Comment comment) {
CommentView result = new CommentView(comment);
if (comment == null) {
return result;
}
Model model = comment.getModelData().getModel();
return create(comment, model);
}
/**
* Creates a {@link CommentView} object for given comment.
*
* @param comment
* comment for which view is created
* @param model
* model where comments is placed
* @return {@link CommentView} object for given comment
*/
public CommentView create(Comment comment, Model model) {
CommentView result = new CommentView(comment);
if (comment == null) {
return result;
}
result.setAuthor(comment.getName());
result.setContent(comment.getContent());
result.setEmail(comment.getEmail());
result.setPinned(comment.isPinned());
if (comment.isDeleted()) {
result.setRemoved("YES (" + comment.getRemoveReason() + ")");
} else {
result.setRemoved("NO");
}
if (comment.getSubmodelData() != null) {
result.setSubmap(comment.getSubmodelData().getId() + "");
model = model.getSubmodelById(comment.getSubmodelData().getId());
if (model == null) {
throw new InvalidArgumentException("Cannot find submodel with id: " + comment.getSubmodelData().getId());
}
}
String title = "";
Point2D coordinates = null;
if (comment.getCoordinates() != null) {
title = "Comment (coord: " + String.format("%.2f", comment.getCoordinates().getX()) + ", " + String.format("%.2f", comment.getCoordinates().getY())
+ ")";
coordinates = comment.getCoordinates();
}
if (comment.getTableName() != null) {
if (comment.getTableName().getName().contains("Reaction")) {
Reaction reaction = model.getReactionByDbId(comment.getTableId());
if (reaction != null) {
title = "Reaction " + reaction.getIdReaction();
coordinates = reaction.getCenterPoint();
} else {
logger.warn("Invalid reaction dbID: " + comment.getTableId());
}
} else {
Element alias = model.getElementByDbId(comment.getTableId());
if (alias != null) {
title = alias.getName();
coordinates = alias.getCenter();
} else {
logger.warn("Invalid alias dbID: " + comment.getTableId());
}
}
}
result.setTitle(title);
if (coordinates != null) {
result.setxCoord(coordinates.getX());
result.setyCoord(coordinates.getY());
result.setZoom("" + (Configuration.MIN_ZOOM_LEVEL + model.getZoomLevels() - 1));
}
return result;
}
@Override
public String createGson(CommentView object) {
return new Gson().toJson(object);
}
@Override
public Comment viewToObject(CommentView view) {
throw new NotImplementedException();
}
}
......@@ -48,7 +48,6 @@
<!-- View factories -->
<bean id="AnnotationViewFactory" class="lcsb.mapviewer.services.view.AnnotationViewFactory"/>
<bean id="CommentViewFactory" class="lcsb.mapviewer.services.view.CommentViewFactory"/>
<bean id="ConfigurationViewFactory" class="lcsb.mapviewer.services.view.ConfigurationViewFactory"/>
<bean id="DataMiningViewFactory" class="lcsb.mapviewer.services.view.DataMiningViewFactory"/>
<bean id="LayoutViewFactory" class="lcsb.mapviewer.services.view.LayoutViewFactory"/>
......
......@@ -19,14 +19,9 @@ import lcsb.mapviewer.model.Project;
import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.user.ObjectPrivilege;
import lcsb.mapviewer.model.user.PrivilegeType;
import lcsb.mapviewer.model.user.User;
import lcsb.mapviewer.services.ServiceTestFunctions;
import lcsb.mapviewer.services.search.comment.FullCommentView;
import lcsb.mapviewer.services.view.CommentView;
@Rollback(true)
public class CommentServiceTest extends ServiceTestFunctions {
......@@ -198,29 +193,6 @@ public class CommentServiceTest extends ServiceTestFunctions {
}
}
@Test
public void testReactionComment() throws Exception {
try {
User admin = userService.getUserByLogin("admin");
userService.setUserPrivilege(admin, new ObjectPrivilege(project, 1, PrivilegeType.VIEW_PROJECT, admin));
Reaction reaction = model.getReactionByReactionId("re3");
Comment comment = commentService.addComment("John Doe", "a@a.pl", "Conteneta 1", model, new Point2D.Double(0, 1),
reaction, false, model);
// assume that we have admin account with all the privileges
String adminToken = userService.login("admin", "admin");
List<CommentView> views = commentService.getCommentsByMap(model, adminToken);
assertNotNull(views.get(0).getTitle());
commentDao.delete(comment);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testComparePointCommentId() throws Exception {
try {
......
......@@ -7,8 +7,6 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ AnnotationViewFactoryTest.class, //
AnnotationViewTest.class, //
CommentViewFactoryTest.class, //
CommentViewTest.class, //
ConfigurationViewFactoryTest.class, //
ConfigurationViewTest.class, //
DataMiningSetViewTest.class, //
......
package lcsb.mapviewer.services.view;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.apache.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import lcsb.mapviewer.model.map.Comment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.model.ModelSubmodelConnection;
import lcsb.mapviewer.model.map.model.SubmodelType;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
import lcsb.mapviewer.services.ServiceTestFunctions;
public class CommentViewFactoryTest extends ServiceTestFunctions {
Logger logger = Logger.getLogger(CommentViewFactoryTest.class);
@Autowired
CommentViewFactory commentViewFactory;
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testCreateEmpty() throws Exception {
try {
Object object = commentViewFactory.create(null);
assertNotNull(object);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateGson() throws Exception {
try {
CommentView object = commentViewFactory.create(null);
assertNotNull(commentViewFactory.createGson(object));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testCreateOnSubmap() throws Exception {
try {
Model model = new ModelFullIndexed(null);
Model submodel = new ModelFullIndexed(null);
submodel.setId(1);
Species species = new GenericProtein("id");
species.setId(23);
species.setName("ProteinName");
submodel.addElement(species);
model.addSubmodelConnection(new ModelSubmodelConnection(submodel, SubmodelType.UNKNOWN));
Comment comment = new Comment();
comment.setModel(model);
comment.setSubmodel(submodel);
comment.setTableName(species.getClass());
comment.setTableId(species.getId());
CommentView object = commentViewFactory.create(comment,model);
assertTrue(object.getTitle().contains(species.getName()));
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
package lcsb.mapviewer.services.view;
import org.apache.commons.lang3.SerializationUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class CommentViewTest {
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testSerialization() {
try {
SerializationUtils.serialize(new CommentView());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment