diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ReviewInput.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ReviewInput.java index 9a88b0c4e2..cf2d930dbc 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ReviewInput.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/api/changes/ReviewInput.java @@ -14,6 +14,7 @@ package com.google.gerrit.extensions.api.changes; +import com.google.gerrit.extensions.common.Comment; import com.google.gerrit.extensions.restapi.DefaultInput; import java.util.LinkedHashMap; @@ -26,7 +27,7 @@ public class ReviewInput { public String message; public Map labels; - public Map> comments; + public Map> comments; /** * If true require all labels to be within the user's permitted ranges based @@ -67,24 +68,7 @@ public class ReviewInput { NONE, OWNER, OWNER_REVIEWERS, ALL } - public static enum Side { - PARENT, REVISION - } - - public static class Comment { - public String id; - public Side side; - public int line; - public String inReplyTo; - public String message; - public Range range; - - public static class Range { - public int startLine; - public int startCharacter; - public int endLine; - public int endCharacter; - } + public static class CommentInput extends Comment { } public ReviewInput message(String msg) { diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/Comment.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/Comment.java new file mode 100644 index 0000000000..b7ad9a7dd1 --- /dev/null +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/Comment.java @@ -0,0 +1,39 @@ +// Copyright (C) 2014 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.extensions.common; + +import java.sql.Timestamp; + +public abstract class Comment { + public String id; + public String path; + public Side side; + public int line; + public Range range; + public String inReplyTo; + public Timestamp updated; + public String message; + + public static enum Side { + PARENT, REVISION + } + + public static class Range { + public int startLine; + public int startCharacter; + public int endLine; + public int endCharacter; + } +} diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/CommentInfo.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/CommentInfo.java new file mode 100644 index 0000000000..cef1718f4c --- /dev/null +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/common/CommentInfo.java @@ -0,0 +1,19 @@ +// Copyright (C) 2014 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.extensions.common; + +public class CommentInfo extends Comment { + public AccountInfo author; +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java index 0079068044..d5047438a9 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PostReview.java @@ -29,10 +29,10 @@ import com.google.gerrit.common.data.LabelTypes; import com.google.gerrit.common.data.Permission; import com.google.gerrit.common.data.PermissionRange; import com.google.gerrit.extensions.api.changes.ReviewInput; -import com.google.gerrit.extensions.api.changes.ReviewInput.Comment; +import com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput; import com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling; import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling; -import com.google.gerrit.extensions.api.changes.ReviewInput.Side; +import com.google.gerrit.extensions.common.Comment.Side; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.RestModifyView; @@ -272,16 +272,16 @@ public class PostReview implements RestModifyView } } - private void checkComments(RevisionResource revision, Map> in) + private void checkComments(RevisionResource revision, Map> in) throws BadRequestException, OrmException { - Iterator>> mapItr = + Iterator>> mapItr = in.entrySet().iterator(); Set filePaths = Sets.newHashSet(changeDataFactory.create( db.get(), revision.getChange()).filePaths( revision.getPatchSet())); while (mapItr.hasNext()) { - Map.Entry> ent = mapItr.next(); + Map.Entry> ent = mapItr.next(); String path = ent.getKey(); if (!filePaths.contains(path) && !Patch.COMMIT_MSG.equals(path)) { throw new BadRequestException(String.format( @@ -289,15 +289,15 @@ public class PostReview implements RestModifyView path, revision.getChange().currentPatchSetId())); } - List list = ent.getValue(); + List list = ent.getValue(); if (list == null) { mapItr.remove(); continue; } - Iterator listItr = list.iterator(); + Iterator listItr = list.iterator(); while (listItr.hasNext()) { - Comment c = listItr.next(); + CommentInput c = listItr.next(); if (c.line < 0) { throw new BadRequestException(String.format( "negative line number %d not allowed on %s", @@ -315,7 +315,7 @@ public class PostReview implements RestModifyView } private boolean insertComments(RevisionResource rsrc, - Map> in, DraftHandling draftsHandling) + Map> in, DraftHandling draftsHandling) throws OrmException { if (in == null) { in = Collections.emptyMap(); @@ -329,9 +329,9 @@ public class PostReview implements RestModifyView List del = Lists.newArrayList(); List ups = Lists.newArrayList(); - for (Map.Entry> ent : in.entrySet()) { + for (Map.Entry> ent : in.entrySet()) { String path = ent.getKey(); - for (Comment c : ent.getValue()) { + for (CommentInput c : ent.getValue()) { String parent = Url.decode(c.inReplyTo); PatchLineComment e = drafts.remove(Url.decode(c.id)); if (e == null) { diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java index 0bea141897..5a534d5acb 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java +++ b/gerrit-server/src/test/java/com/google/gerrit/server/query/change/AbstractQueryChangesTest.java @@ -718,11 +718,11 @@ public abstract class AbstractQueryChangesTest { ReviewInput input = new ReviewInput(); input.message = "toplevel"; - ReviewInput.Comment comment = new ReviewInput.Comment(); + ReviewInput.CommentInput comment = new ReviewInput.CommentInput(); comment.line = 1; comment.message = "inline"; - input.comments = ImmutableMap.> of( - Patch.COMMIT_MSG, ImmutableList. of(comment)); + input.comments = ImmutableMap.> of( + Patch.COMMIT_MSG, ImmutableList. of(comment)); postReview.apply(new RevisionResource( changes.parse(change.getId()), ins.getPatchSet()), input);