Skip to content

The Unified and Autonomous Development Platform

Merge PullRequestComment with PullRequestInlineComment

robin shinedf86b2f768ad
diff --git a/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java b/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java
index d1d6ae358a..6124f8f3e0 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java
@@ -2,7 +2,6 @@ package com.pmease.commons.git;
import java.io.Serializable;
-import javax.persistence.Column;
import javax.persistence.Embeddable;
import org.apache.commons.lang3.builder.EqualsBuilder;
@@ -16,17 +15,17 @@ public class BlobInfo implements Serializable {
private String path;
- @Column(nullable=false)
private String revision;
- @Column(nullable=false)
- private int mode;
+ // Use Integer instead of int here in order to allow this class to be
+ // embedded as nullable property of JPA entities
+ private Integer mode;
public BlobInfo() {
};
- public BlobInfo(String revision, String path, int mode) {
+ public BlobInfo(String revision, String path, Integer mode) {
this.revision = revision;
this.path = path;
this.mode = mode;
@@ -44,6 +43,10 @@ public class BlobInfo implements Serializable {
return mode;
}
+ public void setMode(int mode) {
+ this.mode = mode;
+ }
+
public void setPath(String path) {
this.path = path;
}
@@ -52,10 +55,6 @@ public class BlobInfo implements Serializable {
this.revision = revision;
}
- public void setMode(int mode) {
- this.mode = mode;
- }
-
@Override
public boolean equals(Object other) {
if (!(other instanceof BlobInfo))
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
index 143d0371db..cb4eaa86c8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
@@ -12,9 +12,9 @@ import com.pmease.commons.git.BlobText;
import com.pmease.commons.git.RevAwareChange;
import com.pmease.commons.util.diff.DiffUtils;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
+import com.pmease.gitplex.core.manager.PullRequestCommentManager;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestInlineComment;
+import com.pmease.gitplex.core.model.PullRequestComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.Repository;
@@ -96,15 +96,17 @@ public class ChangeComments implements Serializable {
if (commentsOnCommit == null) {
commentsOnCommit = new HashMap<>();
- for (PullRequestInlineComment comment: request.getInlineComments()) {
- GitPlex.getInstance(PullRequestInlineCommentManager.class).update(comment);
- if (comment.getBlobInfo().getRevision().equals(commit)) {
- List<InlineComment> commentsOnFile = commentsOnCommit.get(comment.getBlobInfo().getPath());
- if (commentsOnFile == null) {
- commentsOnFile = new ArrayList<>();
- commentsOnCommit.put(comment.getBlobInfo().getPath(), commentsOnFile);
+ for (PullRequestComment comment: request.getComments()) {
+ if (comment.getInlineInfo() != null) {
+ GitPlex.getInstance(PullRequestCommentManager.class).updateInline(comment);
+ if (comment.getBlobInfo().getRevision().equals(commit)) {
+ List<InlineComment> commentsOnFile = commentsOnCommit.get(comment.getBlobInfo().getPath());
+ if (commentsOnFile == null) {
+ commentsOnFile = new ArrayList<>();
+ commentsOnCommit.put(comment.getBlobInfo().getPath(), commentsOnFile);
+ }
+ commentsOnFile.add(comment);
}
- commentsOnFile.add(comment);
}
}
comments.put(commit, commentsOnCommit);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java
index 25ff87ac5b..07b0548cec 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java
@@ -7,6 +7,14 @@ import com.pmease.gitplex.core.model.PullRequestComment;
@ImplementedBy(DefaultPullRequestCommentManager.class)
public interface PullRequestCommentManager {
+ /**
+ * Update specified inline comment to make sure it is up to date with latest pull request update
+ *
+ * @param comment
+ * comment to be updated
+ */
+ void updateInline(PullRequestComment comment);
+
void save(PullRequestComment comment);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentManager.java
deleted file mode 100644
index ff335b3f1f..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentManager.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.pmease.gitplex.core.manager;
-
-import com.google.inject.ImplementedBy;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestInlineCommentManager;
-import com.pmease.gitplex.core.model.PullRequestInlineComment;
-
-@ImplementedBy(DefaultPullRequestInlineCommentManager.class)
-public interface PullRequestInlineCommentManager {
-
- /**
- * Update specified inline comment to make sure it is up to date with latest pull request update
- *
- * @param comment
- * comment to be updated
- */
- void update(PullRequestInlineComment comment);
-
- void save(PullRequestInlineComment comment);
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentReplyManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentReplyManager.java
deleted file mode 100644
index 70b6ef7242..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentReplyManager.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.pmease.gitplex.core.manager;
-
-import com.google.inject.ImplementedBy;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestInlineCommentReplyManager;
-import com.pmease.gitplex.core.model.PullRequestInlineCommentReply;
-
-@ImplementedBy(DefaultPullRequestInlineCommentReplyManager.class)
-public interface PullRequestInlineCommentReplyManager {
-
- void save(PullRequestInlineCommentReply reply);
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
index d8ffd56350..4f48092c30 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
@@ -1,10 +1,22 @@
package com.pmease.gitplex.core.manager.impl;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.inject.Inject;
import javax.inject.Singleton;
+import com.google.common.base.Preconditions;
+import com.pmease.commons.git.BlobInfo;
+import com.pmease.commons.git.BlobText;
+import com.pmease.commons.git.Change;
import com.pmease.commons.hibernate.Transactional;
import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.util.diff.AroundContext;
+import com.pmease.commons.util.diff.DiffLine;
+import com.pmease.commons.util.diff.DiffUtils;
+import com.pmease.commons.util.diff.WordSplitter;
+import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.extensionpoint.PullRequestListener;
import com.pmease.gitplex.core.extensionpoint.PullRequestListeners;
import com.pmease.gitplex.core.manager.PullRequestCommentManager;
@@ -24,6 +36,124 @@ public class DefaultPullRequestCommentManager implements PullRequestCommentManag
this.pullRequestListeners = pullRequestListeners;
}
+ @Override
+ public void updateInline(PullRequestComment comment) {
+ Preconditions.checkNotNull(comment.getInlineInfo());
+
+ String latestCommitHash = comment.getRequest().getLatestUpdate().getHeadCommitHash();
+ if (!comment.getNewCommitHash().equals(latestCommitHash)) {
+ List<Change> changes = comment.getRepository().getChanges(comment.getNewCommitHash(), latestCommitHash);
+ String oldCommitHash = comment.getOldCommitHash();
+ if (oldCommitHash.equals(comment.getBlobInfo().getRevision())) {
+ BlobInfo newBlobInfo = null;
+ if (comment.getCompareWith().getPath() != null) {
+ for (Change change: changes) {
+ if (comment.getCompareWith().getPath().equals(change.getOldPath())) {
+ newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
+ break;
+ }
+ }
+ } else {
+ for (Change change: changes) {
+ if (comment.getBlobInfo().getPath().equals(change.getNewPath())) {
+ newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
+ break;
+ }
+ }
+ }
+ if (newBlobInfo != null) {
+ BlobText oldText = comment.getRepository().getBlobText(comment.getBlobInfo());
+ Preconditions.checkNotNull(oldText);
+ List<String> newLines;
+ if (newBlobInfo.getPath() != null) {
+ BlobText newText = comment.getRepository().getBlobText(newBlobInfo);
+ if (newText != null)
+ newLines = newText.getLines();
+ else
+ newLines = null;
+ } else {
+ newLines = new ArrayList<>();
+ }
+ if (newLines != null) {
+ List<DiffLine> diffs = DiffUtils.diff(oldText.getLines(), newLines, null);
+ AroundContext context = DiffUtils.around(
+ diffs, comment.getLine(), -1, InlineComment.CONTEXT_SIZE);
+ context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
+ comment.setContext(context);
+ } else {
+ comment.setContext(null);
+ }
+ comment.setCompareWith(newBlobInfo);
+ } else {
+ comment.getCompareWith().setRevision(latestCommitHash);
+ }
+ } else {
+ BlobInfo newBlobInfo = null;
+ for (Change change: changes) {
+ if (comment.getBlobInfo().getPath().equals(change.getOldPath())) {
+ newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
+ break;
+ }
+ }
+ if (newBlobInfo != null) {
+ BlobText oldText = comment.getRepository().getBlobText(comment.getBlobInfo());
+ Preconditions.checkNotNull(oldText);
+ List<String> newLines;
+ if (newBlobInfo.getPath() != null) {
+ BlobText newText = comment.getRepository().getBlobText(newBlobInfo);
+ if (newText != null)
+ newLines = newText.getLines();
+ else
+ newLines = null;
+ } else {
+ newLines = new ArrayList<>();
+ }
+ if (newLines != null) {
+ List<DiffLine> diffs = DiffUtils.diff(oldText.getLines(), newLines, null);
+ Integer newLineNo = DiffUtils.mapLines(diffs).get(comment.getLine());
+ if (newLineNo != null) {
+ comment.setBlobInfo(newBlobInfo);
+ comment.setLine(newLineNo);
+
+ List<String> oldLines;
+ if (comment.getCompareWith().getPath() != null) {
+ oldText = comment.getRepository().getBlobText(comment.getCompareWith());
+ if (oldText != null)
+ oldLines = oldText.getLines();
+ else
+ oldLines = null;
+ } else {
+ oldLines = new ArrayList<>();
+ }
+ if (oldLines != null) {
+ diffs = DiffUtils.diff(oldLines, newLines, null);
+ AroundContext context = DiffUtils.around(
+ diffs, -1, newLineNo, InlineComment.CONTEXT_SIZE);
+ context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
+ comment.setContext(context);
+ } else {
+ comment.setContext(null);
+ }
+ } else {
+ comment.setCompareWith(newBlobInfo);
+
+ AroundContext context = DiffUtils.around(
+ diffs, comment.getLine(), -1, InlineComment.CONTEXT_SIZE);
+ context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
+ comment.setContext(context);
+ }
+ } else {
+ comment.setCompareWith(newBlobInfo);
+ comment.setContext(null);
+ }
+ } else {
+ comment.getBlobInfo().setRevision(latestCommitHash);
+ }
+ }
+ dao.persist(comment);
+ }
+ }
+
@Transactional
@Override
public void save(PullRequestComment comment) {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentManager.java
deleted file mode 100644
index 058beddc69..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentManager.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.git.BlobInfo;
-import com.pmease.commons.git.BlobText;
-import com.pmease.commons.git.Change;
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.util.diff.AroundContext;
-import com.pmease.commons.util.diff.DiffLine;
-import com.pmease.commons.util.diff.DiffUtils;
-import com.pmease.commons.util.diff.WordSplitter;
-import com.pmease.gitplex.core.comment.InlineComment;
-import com.pmease.gitplex.core.extensionpoint.PullRequestListener;
-import com.pmease.gitplex.core.extensionpoint.PullRequestListeners;
-import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestInlineComment;
-
-@Singleton
-public class DefaultPullRequestInlineCommentManager implements PullRequestInlineCommentManager {
-
- private final Dao dao;
-
- private final PullRequestListeners pullRequestListeners;
-
- @Inject
- public DefaultPullRequestInlineCommentManager(Dao dao, PullRequestListeners pullRequestListeners) {
- this.dao = dao;
- this.pullRequestListeners = pullRequestListeners;
- }
-
- @Override
- public void update(PullRequestInlineComment comment) {
- String latestCommitHash = comment.getRequest().getLatestUpdate().getHeadCommitHash();
- if (!comment.getNewCommitHash().equals(latestCommitHash)) {
- List<Change> changes = comment.getRepository().getChanges(comment.getNewCommitHash(), latestCommitHash);
- String oldCommitHash = comment.getOldCommitHash();
- if (oldCommitHash.equals(comment.getBlobInfo().getRevision())) {
- BlobInfo newBlobInfo = null;
- if (comment.getCompareWith().getPath() != null) {
- for (Change change: changes) {
- if (comment.getCompareWith().getPath().equals(change.getOldPath())) {
- newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
- break;
- }
- }
- } else {
- for (Change change: changes) {
- if (comment.getBlobInfo().getPath().equals(change.getNewPath())) {
- newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
- break;
- }
- }
- }
- if (newBlobInfo != null) {
- BlobText oldText = comment.getRepository().getBlobText(comment.getBlobInfo());
- Preconditions.checkNotNull(oldText);
- List<String> newLines;
- if (newBlobInfo.getPath() != null) {
- BlobText newText = comment.getRepository().getBlobText(newBlobInfo);
- if (newText != null)
- newLines = newText.getLines();
- else
- newLines = null;
- } else {
- newLines = new ArrayList<>();
- }
- if (newLines != null) {
- List<DiffLine> diffs = DiffUtils.diff(oldText.getLines(), newLines, null);
- AroundContext context = DiffUtils.around(
- diffs, comment.getLine(), -1, InlineComment.CONTEXT_SIZE);
- context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
- comment.setContext(context);
- } else {
- comment.setContext(null);
- }
- comment.setCompareWith(newBlobInfo);
- } else {
- comment.getCompareWith().setRevision(latestCommitHash);
- }
- } else {
- BlobInfo newBlobInfo = null;
- for (Change change: changes) {
- if (comment.getBlobInfo().getPath().equals(change.getOldPath())) {
- newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
- break;
- }
- }
- if (newBlobInfo != null) {
- BlobText oldText = comment.getRepository().getBlobText(comment.getBlobInfo());
- Preconditions.checkNotNull(oldText);
- List<String> newLines;
- if (newBlobInfo.getPath() != null) {
- BlobText newText = comment.getRepository().getBlobText(newBlobInfo);
- if (newText != null)
- newLines = newText.getLines();
- else
- newLines = null;
- } else {
- newLines = new ArrayList<>();
- }
- if (newLines != null) {
- List<DiffLine> diffs = DiffUtils.diff(oldText.getLines(), newLines, null);
- Integer newLineNo = DiffUtils.mapLines(diffs).get(comment.getLine());
- if (newLineNo != null) {
- comment.setBlobInfo(newBlobInfo);
- comment.setLine(newLineNo);
-
- List<String> oldLines;
- if (comment.getCompareWith().getPath() != null) {
- oldText = comment.getRepository().getBlobText(comment.getCompareWith());
- if (oldText != null)
- oldLines = oldText.getLines();
- else
- oldLines = null;
- } else {
- oldLines = new ArrayList<>();
- }
- if (oldLines != null) {
- diffs = DiffUtils.diff(oldLines, newLines, null);
- AroundContext context = DiffUtils.around(
- diffs, -1, newLineNo, InlineComment.CONTEXT_SIZE);
- context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
- comment.setContext(context);
- } else {
- comment.setContext(null);
- }
- } else {
- comment.setCompareWith(newBlobInfo);
-
- AroundContext context = DiffUtils.around(
- diffs, comment.getLine(), -1, InlineComment.CONTEXT_SIZE);
- context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
- comment.setContext(context);
- }
- } else {
- comment.setCompareWith(newBlobInfo);
- comment.setContext(null);
- }
- } else {
- comment.getBlobInfo().setRevision(latestCommitHash);
- }
- }
- dao.persist(comment);
- }
- }
-
- @Transactional
- @Override
- public void save(PullRequestInlineComment comment) {
- dao.persist(comment);
-
- final Long requestId = comment.getRequest().getId();
-
- dao.afterCommit(new Runnable() {
-
- @Override
- public void run() {
- pullRequestListeners.asyncCall(requestId, new PullRequestListeners.Callback() {
-
- @Override
- protected void call(PullRequestListener listener, PullRequest request) {
- listener.onCommented(request);
- }
-
- });
- }
-
- });
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentReplyManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentReplyManager.java
deleted file mode 100644
index 5d0551de20..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentReplyManager.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.extensionpoint.PullRequestListener;
-import com.pmease.gitplex.core.extensionpoint.PullRequestListeners;
-import com.pmease.gitplex.core.manager.PullRequestInlineCommentReplyManager;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestInlineCommentReply;
-
-@Singleton
-public class DefaultPullRequestInlineCommentReplyManager implements PullRequestInlineCommentReplyManager {
-
- private final Dao dao;
-
- private final PullRequestListeners pullRequestListeners;
-
- @Inject
- public DefaultPullRequestInlineCommentReplyManager(Dao dao, PullRequestListeners pullRequestListeners) {
- this.dao = dao;
- this.pullRequestListeners = pullRequestListeners;
- }
-
- @Transactional
- @Override
- public void save(PullRequestInlineCommentReply reply) {
- dao.persist(reply);
-
- final Long requestId = reply.getComment().getRequest().getId();
-
- dao.afterCommit(new Runnable() {
-
- @Override
- public void run() {
- pullRequestListeners.asyncCall(requestId, new PullRequestListeners.Callback() {
-
- @Override
- protected void call(PullRequestListener listener, PullRequest request) {
- listener.onCommented(request);
- }
-
- });
- }
-
- });
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
index 7606f8df63..6a7abbb400 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
@@ -9,11 +9,11 @@ import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.util.FileUtils;
import com.pmease.gitplex.core.extensionpoint.PullRequestListener;
import com.pmease.gitplex.core.extensionpoint.PullRequestListeners;
-import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
+import com.pmease.gitplex.core.manager.PullRequestCommentManager;
import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
import com.pmease.gitplex.core.manager.StorageManager;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestInlineComment;
+import com.pmease.gitplex.core.model.PullRequestComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
@Singleton
@@ -27,17 +27,17 @@ public class DefaultPullRequestUpdateManager implements PullRequestUpdateManager
private final UnitOfWork unitOfWork;
- private final PullRequestInlineCommentManager pullRequestInlineCommentManager;
+ private final PullRequestCommentManager pullRequestCommentManager;
@Inject
public DefaultPullRequestUpdateManager(Dao dao, StorageManager storageManager,
PullRequestListeners pullRequestListeners, UnitOfWork unitOfWork,
- PullRequestInlineCommentManager pullRequestInlineCommentManager) {
+ PullRequestCommentManager pullRequestCommentManager) {
this.dao = dao;
this.storageManager = storageManager;
this.pullRequestListeners = pullRequestListeners;
this.unitOfWork = unitOfWork;
- this.pullRequestInlineCommentManager = pullRequestInlineCommentManager;
+ this.pullRequestCommentManager = pullRequestCommentManager;
}
@Transactional
@@ -70,8 +70,10 @@ public class DefaultPullRequestUpdateManager implements PullRequestUpdateManager
@Override
public void run() {
PullRequest request = dao.load(PullRequest.class, requestId);
- for (PullRequestInlineComment comment: request.getInlineComments())
- pullRequestInlineCommentManager.update((PullRequestInlineComment) comment);
+ for (PullRequestComment comment: request.getComments()) {
+ if (comment.getInlineInfo() != null)
+ pullRequestCommentManager.updateInline(comment);
+ }
pullRequestListeners.call(request, new PullRequestListeners.Callback() {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestComment.java
deleted file mode 100644
index faf2baa463..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestComment.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import java.util.Date;
-
-import javax.annotation.Nullable;
-import javax.persistence.Column;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.MappedSuperclass;
-
-import com.pmease.commons.hibernate.AbstractEntity;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.comment.Comment;
-
-@SuppressWarnings("serial")
-@MappedSuperclass
-public abstract class AbstractPullRequestComment extends AbstractEntity implements Comment {
-
- @ManyToOne
- @JoinColumn(nullable=false)
- private PullRequest request;
-
- @ManyToOne(fetch=FetchType.LAZY)
- private User user;
-
- @Column(nullable=false)
- private String content;
-
- @Column(nullable=false)
- private Date date = new Date();
-
- private boolean resolved;
-
- public PullRequest getRequest() {
- return request;
- }
-
- public void setRequest(PullRequest request) {
- this.request = request;
- }
-
- @Nullable
- @Override
- public User getUser() {
- return user;
- }
-
- public void setUser(@Nullable User user) {
- this.user = user;
- }
-
- @Override
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- @Override
- public Date getDate() {
- return date;
- }
-
- public void setDate(Date date) {
- this.date = date;
- }
-
- @Override
- public void saveContent(String content) {
- setContent(content);
- GitPlex.getInstance(Dao.class).persist(this);
- }
-
- @Override
- public Repository getRepository() {
- return request.getTarget().getRepository();
- }
-
- @Override
- public void delete() {
- GitPlex.getInstance(Dao.class).remove(this);
- }
-
- @Override
- public boolean isResolved() {
- return resolved;
- }
-
- public void setResolved(boolean resolved) {
- this.resolved = resolved;
- }
-
- @Override
- public void resolve(boolean resolved) {
- setResolved(resolved);
- GitPlex.getInstance(Dao.class).persist(this);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestCommentReply.java
deleted file mode 100644
index 4b36889166..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestCommentReply.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import java.util.Date;
-
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.MappedSuperclass;
-
-import com.pmease.commons.hibernate.AbstractEntity;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.comment.CommentReply;
-
-@SuppressWarnings("serial")
-@MappedSuperclass
-public abstract class AbstractPullRequestCommentReply extends AbstractEntity implements CommentReply {
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private User user;
-
- private Date date;
-
- private String content;
-
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-
- public Date getDate() {
- return date;
- }
-
- public void setDate(Date date) {
- this.date = date;
- }
-
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- @Override
- public void saveContent(String content) {
- setContent(content);
- GitPlex.getInstance(Dao.class).persist(this);
- }
-
- @Override
- public void delete() {
- GitPlex.getInstance(Dao.class).remove(this);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java
new file mode 100644
index 0000000000..044e36c484
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java
@@ -0,0 +1,71 @@
+package com.pmease.gitplex.core.model;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.Embedded;
+import javax.persistence.Lob;
+
+import com.pmease.commons.git.BlobInfo;
+import com.pmease.commons.util.diff.AroundContext;
+
+@Embeddable
+public class InlineInfo {
+
+ @Embedded
+ @AttributeOverrides({
+ @AttributeOverride(name="revision", column=@Column(name="G_BLOB_REV")),
+ @AttributeOverride(name="path", column=@Column(name="G_BLOB_PATH")),
+ @AttributeOverride(name="mode", column=@Column(name="G_BLOB_MODE"))
+ })
+ private BlobInfo blobInfo;
+
+ @Embedded
+ @AttributeOverrides({
+ @AttributeOverride(name="revision", column=@Column(name="G_COMPARE_REV") ),
+ @AttributeOverride(name="path", column=@Column(name="G_COMPARE_PATH")),
+ @AttributeOverride(name="mode", column=@Column(name="G_COMPARE_MODE"))
+ })
+ private BlobInfo compareWith;
+
+ // Use Integer instead of int here in order to allow this class to be
+ // embedded as nullable property of JPA entities
+ private Integer line;
+
+ @Lob
+ private AroundContext context;
+
+ public BlobInfo getBlobInfo() {
+ return blobInfo;
+ }
+
+ public void setBlobInfo(BlobInfo blobInfo) {
+ this.blobInfo = blobInfo;
+ }
+
+ public BlobInfo getCompareWith() {
+ return compareWith;
+ }
+
+ public void setCompareWith(BlobInfo compareWith) {
+ this.compareWith = compareWith;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ public void setLine(int line) {
+ this.line = line;
+ }
+
+ public AroundContext getContext() {
+ return context;
+ }
+
+ public void setContext(AroundContext context) {
+ this.context = context;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
index e2a20e20ab..8a6e82d6f8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
@@ -144,9 +144,6 @@ public class PullRequest extends AbstractEntity {
@OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)
private Collection<PullRequestComment> comments = new ArrayList<>();
- @OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)
- private Collection<PullRequestInlineComment> inlineComments = new ArrayList<>();
-
@OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)
private Collection<PullRequestAudit> audits = new ArrayList<>();
@@ -313,15 +310,6 @@ public class PullRequest extends AbstractEntity {
this.comments = comments;
}
- public Collection<PullRequestInlineComment> getInlineComments() {
- return inlineComments;
- }
-
- public void setInlineComments(
- Collection<PullRequestInlineComment> inlineComments) {
- this.inlineComments = inlineComments;
- }
-
public Collection<PullRequestAudit> getAudits() {
return audits;
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
index 7a0fd3b452..648950f1b7 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
@@ -3,24 +3,124 @@ package com.pmease.gitplex.core.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.List;
+import javax.annotation.Nullable;
import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import com.google.common.base.Preconditions;
+import com.pmease.commons.git.BlobInfo;
+import com.pmease.commons.hibernate.AbstractEntity;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.util.Pair;
+import com.pmease.commons.util.diff.AroundContext;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.CommentReply;
+import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.manager.PullRequestCommentReplyManager;
import com.pmease.gitplex.core.manager.UserManager;
@SuppressWarnings("serial")
@Entity
-public class PullRequestComment extends AbstractPullRequestComment {
+public class PullRequestComment extends AbstractEntity implements InlineComment {
+
+ @ManyToOne
+ @JoinColumn(nullable=false)
+ private PullRequest request;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ private User user;
+
+ @Column(nullable=false)
+ private String content;
+
+ @Column(nullable=false)
+ private Date date = new Date();
+
+ private boolean resolved;
@OneToMany(mappedBy="comment", cascade=CascadeType.REMOVE)
private Collection<PullRequestCommentReply> replies = new ArrayList<>();
+ @Embedded
+ private InlineInfo inlineInfo;
+
+ private transient Pair<String, String> oldCommitAndNewCommit;
+
+ public PullRequest getRequest() {
+ return request;
+ }
+
+ public void setRequest(PullRequest request) {
+ this.request = request;
+ }
+
+ @Nullable
+ @Override
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(@Nullable User user) {
+ this.user = user;
+ }
+
+ @Override
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ @Override
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ @Override
+ public void saveContent(String content) {
+ setContent(content);
+ GitPlex.getInstance(Dao.class).persist(this);
+ }
+
+ @Override
+ public Repository getRepository() {
+ return request.getTarget().getRepository();
+ }
+
+ @Override
+ public void delete() {
+ GitPlex.getInstance(Dao.class).remove(this);
+ }
+
+ @Override
+ public boolean isResolved() {
+ return resolved;
+ }
+
+ public void setResolved(boolean resolved) {
+ this.resolved = resolved;
+ }
+
+ @Override
+ public void resolve(boolean resolved) {
+ setResolved(resolved);
+ GitPlex.getInstance(Dao.class).persist(this);
+ }
+
@Override
public Collection<PullRequestCommentReply> getReplies() {
return replies;
@@ -43,4 +143,77 @@ public class PullRequestComment extends AbstractPullRequestComment {
return reply;
}
+ private Pair<String, String> getOldCommitAndNewCommit() {
+ if (oldCommitAndNewCommit == null) {
+ List<String> commitHashes = getRequest().getCommentables();
+ int index = commitHashes.indexOf(getBlobInfo().getRevision());
+ int compareIndex = commitHashes.indexOf(getCompareWith().getRevision());
+ Preconditions.checkState(index != -1 && compareIndex != -1);
+ if (index <= compareIndex)
+ oldCommitAndNewCommit = new Pair<>(getBlobInfo().getRevision(), getCompareWith().getRevision());
+ else
+ oldCommitAndNewCommit = new Pair<>(getCompareWith().getRevision(), getBlobInfo().getRevision());
+ }
+ return oldCommitAndNewCommit;
+ }
+
+ public InlineInfo getInlineInfo() {
+ return inlineInfo;
+ }
+
+ public void setInlineInfo(InlineInfo inlineInfo) {
+ this.inlineInfo = inlineInfo;
+ }
+
+ public String getOldCommitHash() {
+ return getOldCommitAndNewCommit().getFirst();
+ }
+
+ public String getNewCommitHash() {
+ return getOldCommitAndNewCommit().getSecond();
+ }
+
+ @Override
+ public BlobInfo getBlobInfo() {
+ return Preconditions.checkNotNull(inlineInfo).getBlobInfo();
+ }
+
+ public void setBlobInfo(BlobInfo blobInfo) {
+ if (inlineInfo == null)
+ inlineInfo = new InlineInfo();
+ inlineInfo.setBlobInfo(blobInfo);
+ }
+
+ public BlobInfo getCompareWith() {
+ return Preconditions.checkNotNull(inlineInfo).getCompareWith();
+ }
+
+ public void setCompareWith(BlobInfo compareWith) {
+ if (inlineInfo == null)
+ inlineInfo = new InlineInfo();
+ inlineInfo.setCompareWith(compareWith);
+ }
+
+ @Override
+ public int getLine() {
+ return Preconditions.checkNotNull(inlineInfo).getLine();
+ }
+
+ public void setLine(int line) {
+ if (inlineInfo == null)
+ inlineInfo = new InlineInfo();
+ inlineInfo.setLine(line);
+ }
+
+ @Override
+ public AroundContext getContext() {
+ return Preconditions.checkNotNull(inlineInfo).getContext();
+ }
+
+ public void setContext(AroundContext context) {
+ if (inlineInfo == null)
+ inlineInfo = new InlineInfo();
+ inlineInfo.setContext(context);
+ }
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java
index 3cfd757c55..15bd8d06ff 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java
@@ -1,17 +1,68 @@
package com.pmease.gitplex.core.model;
+import java.util.Date;
+
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
+import com.pmease.commons.hibernate.AbstractEntity;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.comment.CommentReply;
+
@SuppressWarnings("serial")
@Entity
-public class PullRequestCommentReply extends AbstractPullRequestCommentReply {
+public class PullRequestCommentReply extends AbstractEntity implements CommentReply {
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(nullable=false)
+ private User user;
+
+ private Date date;
+
+ private String content;
@ManyToOne
@JoinColumn(nullable=false)
private PullRequestComment comment;
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ @Override
+ public void saveContent(String content) {
+ setContent(content);
+ GitPlex.getInstance(Dao.class).persist(this);
+ }
+
+ @Override
+ public void delete() {
+ GitPlex.getInstance(Dao.class).remove(this);
+ }
+
@Override
public PullRequestComment getComment() {
return comment;
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineComment.java
deleted file mode 100644
index 3a326346c9..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineComment.java
+++ /dev/null
@@ -1,146 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
-import javax.annotation.Nullable;
-import javax.persistence.AttributeOverride;
-import javax.persistence.AttributeOverrides;
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Embedded;
-import javax.persistence.Entity;
-import javax.persistence.Lob;
-import javax.persistence.OneToMany;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.git.BlobInfo;
-import com.pmease.commons.util.Pair;
-import com.pmease.commons.util.diff.AroundContext;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.comment.CommentReply;
-import com.pmease.gitplex.core.comment.InlineComment;
-import com.pmease.gitplex.core.manager.PullRequestInlineCommentReplyManager;
-import com.pmease.gitplex.core.manager.UserManager;
-
-@Entity
-@SuppressWarnings("serial")
-public class PullRequestInlineComment extends AbstractPullRequestComment implements InlineComment {
-
- @OneToMany(mappedBy="comment", cascade=CascadeType.REMOVE)
- private Collection<PullRequestInlineCommentReply> replies = new ArrayList<>();
-
- @Embedded
- @AttributeOverrides({
- @AttributeOverride(name="revision", column=@Column(name="G_BLOB_REV", nullable=false)),
- @AttributeOverride(name="path", column=@Column(name="G_BLOB_PATH", nullable=false)),
- @AttributeOverride(name="mode", column=@Column(name="G_BLOB_MODE", nullable=false))
- })
- private BlobInfo blobInfo;
-
- @Embedded
- @AttributeOverrides({
- @AttributeOverride(name="revision", column=@Column(name="G_COMPARE_REV", nullable=false) ),
- @AttributeOverride(name="path", column=@Column(name="G_COMPARE_PATH")),
- @AttributeOverride(name="mode", column=@Column(name="G_COMPARE_MODE", nullable=false))
- })
- private BlobInfo compareWith;
-
- @Column(nullable=false)
- private int line;
-
- @Lob
- private AroundContext context;
-
- private transient Pair<String, String> oldCommitAndNewCommit;
-
- @Override
- public int getLine() {
- return line;
- }
-
- public void setLine(int line) {
- this.line = line;
- }
-
- /**
- * Inline context to be displayed in pull request activities page.
- *
- * @return
- * null if inline context can not be extracted due to one side
- * of the diff is a binary file
- */
- @Nullable
- @Override
- public AroundContext getContext() {
- return context;
- }
-
- public void setContext(@Nullable AroundContext context) {
- this.context = context;
- }
-
- public BlobInfo getCompareWith() {
- return compareWith;
- }
-
- public void setCompareWith(BlobInfo compareWith) {
- this.compareWith = compareWith;
- }
-
- private Pair<String, String> getOldCommitAndNewCommit() {
- if (oldCommitAndNewCommit == null) {
- List<String> commitHashes = getRequest().getCommentables();
- int index = commitHashes.indexOf(getBlobInfo().getRevision());
- int compareIndex = commitHashes.indexOf(getCompareWith().getRevision());
- Preconditions.checkState(index != -1 && compareIndex != -1);
- if (index <= compareIndex)
- oldCommitAndNewCommit = new Pair<>(getBlobInfo().getRevision(), getCompareWith().getRevision());
- else
- oldCommitAndNewCommit = new Pair<>(getCompareWith().getRevision(), getBlobInfo().getRevision());
- }
- return oldCommitAndNewCommit;
- }
-
- public String getOldCommitHash() {
- return getOldCommitAndNewCommit().getFirst();
- }
-
- public String getNewCommitHash() {
- return getOldCommitAndNewCommit().getSecond();
- }
-
- @Override
- public BlobInfo getBlobInfo() {
- return blobInfo;
- }
-
- public void setBlobInfo(BlobInfo blobInfo) {
- this.blobInfo = blobInfo;
- }
-
- @Override
- public Collection<PullRequestInlineCommentReply> getReplies() {
- return replies;
- }
-
- public void setReplies(Collection<PullRequestInlineCommentReply> replies) {
- this.replies = replies;
- }
-
- @Override
- public CommentReply addReply(String content) {
- User user = GitPlex.getInstance(UserManager.class).getCurrent();
- Preconditions.checkNotNull(user);
- PullRequestInlineCommentReply reply = new PullRequestInlineCommentReply();
- reply.setUser(user);
- reply.setDate(new Date());
- reply.setContent(content);
- reply.setComment(this);
- GitPlex.getInstance(PullRequestInlineCommentReplyManager.class).save(reply);
- return reply;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineCommentReply.java
deleted file mode 100644
index 342c824bd6..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineCommentReply.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import javax.persistence.Entity;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-
-@SuppressWarnings("serial")
-@Entity
-public class PullRequestInlineCommentReply extends AbstractPullRequestCommentReply {
-
- @ManyToOne
- @JoinColumn(nullable=false)
- private PullRequestInlineComment comment;
-
- @Override
- public PullRequestInlineComment getComment() {
- return comment;
- }
-
- public void setComment(PullRequestInlineComment comment) {
- this.comment = comment;
- }
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
index 0abb25968c..0ca0fffb1d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
@@ -24,6 +24,7 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import com.pmease.commons.loader.InheritableThreadLocalData;
+import com.pmease.commons.wicket.behavior.AllowLeaveBehavior;
import com.pmease.commons.wicket.behavior.ConfirmBehavior;
import com.pmease.commons.wicket.component.markdown.MarkdownInput;
import com.pmease.commons.wicket.component.markdown.MarkdownViewer;
@@ -324,7 +325,7 @@ public class CommentPanel extends Panel {
target.add(form);
}
- });
+ }.add(new AllowLeaveBehavior()));
form.add(new AjaxLink<Void>("cancel") {
@@ -335,7 +336,7 @@ public class CommentPanel extends Panel {
target.add(addReplyRow);
}
- });
+ }.add(new AllowLeaveBehavior()));
CommentPanel.this.replace(row);
target.add(row);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
index e498357dc7..c81d491cd7 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
@@ -52,6 +52,7 @@ import com.pmease.commons.util.diff.DiffLine;
import com.pmease.commons.util.diff.DiffUtils;
import com.pmease.commons.util.diff.Token;
import com.pmease.commons.util.diff.WordSplitter;
+import com.pmease.commons.wicket.behavior.AllowLeaveBehavior;
import com.pmease.commons.wicket.behavior.ScrollBehavior;
import com.pmease.commons.wicket.behavior.StickyBehavior;
import com.pmease.commons.wicket.behavior.TooltipBehavior;
@@ -65,7 +66,7 @@ import com.pmease.gitplex.core.comment.CommentReply;
import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.PullRequestInlineCommentReply;
+import com.pmease.gitplex.core.model.PullRequestCommentReply;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.core.permission.ObjectPermission;
@@ -533,7 +534,8 @@ public class TextDiffPanel extends Panel {
target.appendJavaScript(String.format("gitplex.comments.cancelAdd(%d);", index));
}
- });
+ }.add(new AllowLeaveBehavior()));
+
form.add(new AjaxSubmitLink("save") {
@Override
@@ -580,7 +582,7 @@ public class TextDiffPanel extends Panel {
target.add(head);
}
- });
+ }.add(new AllowLeaveBehavior()));
add(form);
add(addCommentBehavior = new AbstractDefaultAjaxBehavior() {
@@ -840,8 +842,8 @@ public class TextDiffPanel extends Panel {
item.add(new CommentPanel("comment", item.getModel(), new ModelWrapper<CommentReply>() {
@Override
- public IModel<PullRequestInlineCommentReply> asModel(CommentReply object) {
- return new EntityModel<PullRequestInlineCommentReply>((PullRequestInlineCommentReply) object);
+ public IModel<PullRequestCommentReply> asModel(CommentReply object) {
+ return new EntityModel<PullRequestCommentReply>((PullRequestCommentReply) object);
}
}).setOutputMarkupId(true));
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestActivitiesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestActivitiesPage.java
index dd1e836eee..5c7228d272 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestActivitiesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestActivitiesPage.java
@@ -27,16 +27,15 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.google.common.base.Preconditions;
import com.pmease.commons.loader.InheritableThreadLocalData;
+import com.pmease.commons.wicket.behavior.AllowLeaveBehavior;
import com.pmease.commons.wicket.component.markdown.MarkdownInput;
import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior.PageId;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.manager.PullRequestCommentManager;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.AbstractPullRequestComment;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestAudit;
import com.pmease.gitplex.core.model.PullRequestComment;
-import com.pmease.gitplex.core.model.PullRequestInlineComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.web.component.comment.event.CommentCollapsing;
import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
@@ -45,12 +44,10 @@ import com.pmease.gitplex.web.component.label.AgeLabel;
import com.pmease.gitplex.web.component.user.AvatarMode;
import com.pmease.gitplex.web.component.user.UserLink;
import com.pmease.gitplex.web.model.UserModel;
-import com.pmease.gitplex.web.page.repository.pullrequest.activity.AbstractCommentPullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.ApprovePullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.CommentPullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.DisapprovePullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.DiscardPullRequest;
-import com.pmease.gitplex.web.page.repository.pullrequest.activity.InlineCommentPullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.IntegratePullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.OpenPullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.PullRequestActivity;
@@ -66,9 +63,9 @@ public class RequestActivitiesPage extends RequestDetailPage {
}
private Component newActivityRow(final String id, PullRequestActivity activity) {
- final AbstractCommentPullRequest commentActivity;
- if (activity instanceof AbstractCommentPullRequest)
- commentActivity = (AbstractCommentPullRequest) activity;
+ final CommentPullRequest commentActivity;
+ if (activity instanceof CommentPullRequest)
+ commentActivity = (CommentPullRequest) activity;
else
commentActivity = null;
@@ -93,17 +90,15 @@ public class RequestActivitiesPage extends RequestDetailPage {
};
if (commentActivity != null && commentActivity.isCollapsed()) {
- AbstractPullRequestComment comment = commentActivity.getComment();
+ PullRequestComment comment = commentActivity.getComment();
Fragment fragment = new Fragment("activity", "collapsedCommentFrag", RequestActivitiesPage.this);
fragment.add(new UserLink("user", new UserModel(comment.getUser()), AvatarMode.NAME));
- if (comment instanceof PullRequestInlineComment) {
- PullRequestInlineComment inlineComment = (PullRequestInlineComment) comment;
- fragment.add(new Label("activity", "added inline comment on file '" + inlineComment.getBlobInfo().getPath() + "'"));
- } else {
+ if (comment.getInlineInfo() != null)
+ fragment.add(new Label("activity", "added inline comment on file '" + comment.getBlobInfo().getPath() + "'"));
+ else
fragment.add(new Label("activity", "commented"));
- }
fragment.add(new AgeLabel("age", Model.of(comment.getDate())));
fragment.add(new Label("detail", comment.getContent()));
@@ -129,7 +124,7 @@ public class RequestActivitiesPage extends RequestDetailPage {
if (row.get("activity") == null)
row.add(activity.render("activity"));
- if (activity instanceof OpenPullRequest || activity instanceof AbstractCommentPullRequest)
+ if (activity instanceof OpenPullRequest || activity instanceof CommentPullRequest)
row.add(AttributeAppender.append("class", " discussion non-update"));
else if (activity instanceof UpdatePullRequest)
row.add(AttributeAppender.append("class", " non-discussion update"));
@@ -142,8 +137,8 @@ public class RequestActivitiesPage extends RequestDetailPage {
protected String load() {
String cssClasses = "";
PullRequestActivity activity = (PullRequestActivity) row.getDefaultModelObject();
- if (activity instanceof AbstractCommentPullRequest) {
- AbstractCommentPullRequest commentActivity = (AbstractCommentPullRequest) activity;
+ if (activity instanceof CommentPullRequest) {
+ CommentPullRequest commentActivity = (CommentPullRequest) activity;
if (commentActivity.isCollapsed())
cssClasses += " collapsed";
if (commentActivity.getComment().isResolved())
@@ -169,9 +164,6 @@ public class RequestActivitiesPage extends RequestDetailPage {
for (PullRequestComment comment: request.getComments())
activities.add(new CommentPullRequest(comment));
- for (PullRequestInlineComment comment: request.getInlineComments())
- activities.add(new InlineCommentPullRequest(comment));
-
for (PullRequestAudit audit: request.getAudits()) {
if (audit.getOperation() == INTEGRATE) {
activities.add(new IntegratePullRequest(audit.getUser(), audit.getDate()));
@@ -194,7 +186,7 @@ public class RequestActivitiesPage extends RequestDetailPage {
return -1;
else if (o1.getDate().after(o2.getDate()))
return 1;
- else if (o1 instanceof OpenPullRequest || o1 instanceof AbstractCommentPullRequest)
+ else if (o1 instanceof OpenPullRequest || o1 instanceof CommentPullRequest)
return -1;
else
return 1;
@@ -310,7 +302,7 @@ public class RequestActivitiesPage extends RequestDetailPage {
target.add(form);
}
- });
+ }.add(new AllowLeaveBehavior()));
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
index 0e5505a0d3..03149efd57 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
@@ -49,13 +49,12 @@ import com.pmease.commons.wicket.websocket.WebSocketRenderBehavior.PageId;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
-import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
+import com.pmease.gitplex.core.manager.PullRequestCommentManager;
import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.manager.UserManager;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestComment;
-import com.pmease.gitplex.core.model.PullRequestInlineComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
@@ -86,7 +85,7 @@ public class RequestComparePage extends RequestDetailPage {
private String newCommitHash;
- private final IModel<PullRequestInlineComment> commentModel;
+ private final IModel<PullRequestComment> commentModel;
private final IModel<Map<String, CommitDescription>> commitsModel =
new LoadableDetachableModel<Map<String, CommitDescription>>() {
@@ -135,13 +134,13 @@ public class RequestComparePage extends RequestDetailPage {
public RequestComparePage(final PageParameters params) {
super(params);
- commentModel = new LoadableDetachableModel<PullRequestInlineComment>() {
+ commentModel = new LoadableDetachableModel<PullRequestComment>() {
@Override
- protected PullRequestInlineComment load() {
+ protected PullRequestComment load() {
Long commentId = params.get(COMMENT_PARAM).toOptionalLong();
if (commentId != null)
- return GitPlex.getInstance(Dao.class).load(PullRequestInlineComment.class, commentId);
+ return GitPlex.getInstance(Dao.class).load(PullRequestComment.class, commentId);
else
return null;
}
@@ -152,7 +151,7 @@ public class RequestComparePage extends RequestDetailPage {
newCommitHash = params.get(REVISED_PARAM).toString();
file = params.get(FILE_PARAM).toString();
- PullRequestInlineComment comment = getComment();
+ PullRequestComment comment = getComment();
if (comment != null) {
if (oldCommitHash != null || newCommitHash != null) {
throw new IllegalArgumentException("Parameter 'original' or 'revised' "
@@ -433,8 +432,8 @@ public class RequestComparePage extends RequestDetailPage {
AroundContext commentContext, int line, String content) {
User user = GitPlex.getInstance(UserManager.class).getCurrent();
Preconditions.checkNotNull(user);
- PullRequestInlineComment comment = new PullRequestInlineComment();
- getPullRequest().getInlineComments().add(comment);
+ PullRequestComment comment = new PullRequestComment();
+ getPullRequest().getComments().add(comment);
comment.setUser(user);
comment.setDate(new Date());
comment.setContent(content);
@@ -445,7 +444,7 @@ public class RequestComparePage extends RequestDetailPage {
comment.setContext(commentContext);
InheritableThreadLocalData.set(new PageId(getPageId()));
try {
- GitPlex.getInstance(PullRequestInlineCommentManager.class).save(comment);
+ GitPlex.getInstance(PullRequestCommentManager.class).save(comment);
} finally {
InheritableThreadLocalData.clear();
}
@@ -490,7 +489,7 @@ public class RequestComparePage extends RequestDetailPage {
super.onDetach();
}
- public static PageParameters paramsOf(PullRequestInlineComment concernedComment) {
+ public static PageParameters paramsOf(PullRequestComment concernedComment) {
PageParameters params = RequestDetailPage.paramsOf(concernedComment.getRequest());
params.set("comment", concernedComment.getId());
@@ -646,7 +645,7 @@ public class RequestComparePage extends RequestDetailPage {
}
}
- private PullRequestInlineComment getComment() {
+ private PullRequestComment getComment() {
return commentModel.getObject();
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/AbstractCommentPullRequest.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/AbstractCommentPullRequest.java
deleted file mode 100644
index 601332f2f7..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/AbstractCommentPullRequest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.pmease.gitplex.web.page.repository.pullrequest.activity;
-
-import java.util.Date;
-
-import com.pmease.gitplex.core.model.AbstractPullRequestComment;
-import com.pmease.gitplex.core.model.User;
-
-@SuppressWarnings("serial")
-public abstract class AbstractCommentPullRequest implements PullRequestActivity {
-
- private Boolean collapsed;
-
- @Override
- public Date getDate() {
- return getComment().getDate();
- }
-
- public abstract AbstractPullRequestComment getComment();
-
- @Override
- public User getUser() {
- return getComment().getUser();
- }
-
- public boolean isCollapsed() {
- if (collapsed == null)
- collapsed = getComment().isResolved();
- return collapsed;
- }
-
- public void setCollapsed(boolean collapsed) {
- this.collapsed = collapsed;
- }
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentPullRequest.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentPullRequest.java
index 806b9b400b..206a6aa6fd 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentPullRequest.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentPullRequest.java
@@ -1,31 +1,61 @@
package com.pmease.gitplex.web.page.repository.pullrequest.activity;
+import java.util.Date;
+
import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.model.PullRequestComment;
+import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
-public class CommentPullRequest extends AbstractCommentPullRequest {
+public class CommentPullRequest implements PullRequestActivity {
private final Long commentId;
+ private Boolean collapsed;
+
+ @Override
+ public Date getDate() {
+ return getComment().getDate();
+ }
+
+ @Override
+ public User getUser() {
+ return getComment().getUser();
+ }
+
+ public boolean isCollapsed() {
+ if (collapsed == null)
+ collapsed = getComment().isResolved();
+ return collapsed;
+ }
+
+ public void setCollapsed(boolean collapsed) {
+ this.collapsed = collapsed;
+ }
+
public CommentPullRequest(PullRequestComment comment) {
this.commentId = comment.getId();
}
@Override
public Panel render(String panelId) {
- return new CommentActivityPanel(panelId, new LoadableDetachableModel<PullRequestComment>(){
-
+ IModel<PullRequestComment> commentModel = new LoadableDetachableModel<PullRequestComment>(){
+
@Override
protected PullRequestComment load() {
return getComment();
}
- });
+ };
+ if (getComment().getInlineInfo() != null)
+ return new InlineCommentActivityPanel(panelId, commentModel);
+ else
+ return new CommentActivityPanel(panelId, commentModel);
}
public PullRequestComment getComment() {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.java
index ecc2e127f1..247db0960d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.java
@@ -29,9 +29,9 @@ import com.pmease.commons.util.diff.Token;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.Comment;
import com.pmease.gitplex.core.comment.CommentReply;
-import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
-import com.pmease.gitplex.core.model.PullRequestInlineComment;
-import com.pmease.gitplex.core.model.PullRequestInlineCommentReply;
+import com.pmease.gitplex.core.manager.PullRequestCommentManager;
+import com.pmease.gitplex.core.model.PullRequestComment;
+import com.pmease.gitplex.core.model.PullRequestCommentReply;
import com.pmease.gitplex.web.component.comment.CommentPanel;
import com.pmease.gitplex.web.component.comment.event.CommentCollapsing;
import com.pmease.gitplex.web.component.comment.event.PullRequestChanged;
@@ -46,9 +46,9 @@ import com.pmease.gitplex.web.page.repository.pullrequest.RequestComparePage;
@SuppressWarnings("serial")
public class InlineCommentActivityPanel extends Panel {
- private final IModel<PullRequestInlineComment> commentModel;
+ private final IModel<PullRequestComment> commentModel;
- public InlineCommentActivityPanel(String id, IModel<PullRequestInlineComment> commentModel) {
+ public InlineCommentActivityPanel(String id, IModel<PullRequestComment> commentModel) {
super(id);
this.commentModel = commentModel;
@@ -58,8 +58,8 @@ public class InlineCommentActivityPanel extends Panel {
protected void onInitialize() {
super.onInitialize();
- PullRequestInlineComment comment = commentModel.getObject();
- GitPlex.getInstance(PullRequestInlineCommentManager.class).update(comment);
+ PullRequestComment comment = commentModel.getObject();
+ GitPlex.getInstance(PullRequestCommentManager.class).updateInline(comment);
add(new UserLink("name", new UserModel(comment.getUser()), AvatarMode.NAME));
add(new AgeLabel("age", Model.of(comment.getDate())));
@@ -213,8 +213,8 @@ public class InlineCommentActivityPanel extends Panel {
add(new CommentPanel("comment", commentModel, new ModelWrapper<CommentReply>() {
@Override
- public IModel<PullRequestInlineCommentReply> asModel(CommentReply object) {
- return new EntityModel<PullRequestInlineCommentReply>((PullRequestInlineCommentReply) object);
+ public IModel<PullRequestCommentReply> asModel(CommentReply object) {
+ return new EntityModel<PullRequestCommentReply>((PullRequestCommentReply) object);
}
}) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPullRequest.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPullRequest.java
deleted file mode 100644
index f71f102e10..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPullRequest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.pmease.gitplex.web.page.repository.pullrequest.activity;
-
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.LoadableDetachableModel;
-
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.PullRequestInlineComment;
-
-@SuppressWarnings("serial")
-public class InlineCommentPullRequest extends AbstractCommentPullRequest {
-
- private final Long commentId;
-
- public InlineCommentPullRequest(PullRequestInlineComment comment) {
- this.commentId = comment.getId();
- }
-
- @Override
- public Panel render(String panelId) {
- return new InlineCommentActivityPanel(panelId, new LoadableDetachableModel<PullRequestInlineComment>(){
-
- @Override
- protected PullRequestInlineComment load() {
- return getComment();
- }
-
- });
- }
-
- public PullRequestInlineComment getComment() {
- return GitPlex.getInstance(Dao.class).load(PullRequestInlineComment.class, commentId);
- }
-
-}