Move ReviewInput.Comment to abstract class Comment
This class is used in both CommentInfo and ReviewInput.CommentInput. Change-Id: I933ec829488d777a11b84aa57108415568950f58
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.extensions.api.changes;
|
package com.google.gerrit.extensions.api.changes;
|
||||||
|
|
||||||
|
import com.google.gerrit.extensions.common.Comment;
|
||||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@@ -26,7 +27,7 @@ public class ReviewInput {
|
|||||||
public String message;
|
public String message;
|
||||||
|
|
||||||
public Map<String, Short> labels;
|
public Map<String, Short> labels;
|
||||||
public Map<String, List<Comment>> comments;
|
public Map<String, List<CommentInput>> comments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true require all labels to be within the user's permitted ranges based
|
* 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
|
NONE, OWNER, OWNER_REVIEWERS, ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Side {
|
public static class CommentInput extends Comment {
|
||||||
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 ReviewInput message(String msg) {
|
public ReviewInput message(String msg) {
|
||||||
|
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
@@ -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;
|
||||||
|
}
|
@@ -29,10 +29,10 @@ import com.google.gerrit.common.data.LabelTypes;
|
|||||||
import com.google.gerrit.common.data.Permission;
|
import com.google.gerrit.common.data.Permission;
|
||||||
import com.google.gerrit.common.data.PermissionRange;
|
import com.google.gerrit.common.data.PermissionRange;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
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.DraftHandling;
|
||||||
import com.google.gerrit.extensions.api.changes.ReviewInput.NotifyHandling;
|
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.AuthException;
|
||||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||||
import com.google.gerrit.extensions.restapi.RestModifyView;
|
import com.google.gerrit.extensions.restapi.RestModifyView;
|
||||||
@@ -272,16 +272,16 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkComments(RevisionResource revision, Map<String, List<Comment>> in)
|
private void checkComments(RevisionResource revision, Map<String, List<CommentInput>> in)
|
||||||
throws BadRequestException, OrmException {
|
throws BadRequestException, OrmException {
|
||||||
Iterator<Map.Entry<String, List<Comment>>> mapItr =
|
Iterator<Map.Entry<String, List<CommentInput>>> mapItr =
|
||||||
in.entrySet().iterator();
|
in.entrySet().iterator();
|
||||||
Set<String> filePaths =
|
Set<String> filePaths =
|
||||||
Sets.newHashSet(changeDataFactory.create(
|
Sets.newHashSet(changeDataFactory.create(
|
||||||
db.get(), revision.getChange()).filePaths(
|
db.get(), revision.getChange()).filePaths(
|
||||||
revision.getPatchSet()));
|
revision.getPatchSet()));
|
||||||
while (mapItr.hasNext()) {
|
while (mapItr.hasNext()) {
|
||||||
Map.Entry<String, List<Comment>> ent = mapItr.next();
|
Map.Entry<String, List<CommentInput>> ent = mapItr.next();
|
||||||
String path = ent.getKey();
|
String path = ent.getKey();
|
||||||
if (!filePaths.contains(path) && !Patch.COMMIT_MSG.equals(path)) {
|
if (!filePaths.contains(path) && !Patch.COMMIT_MSG.equals(path)) {
|
||||||
throw new BadRequestException(String.format(
|
throw new BadRequestException(String.format(
|
||||||
@@ -289,15 +289,15 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
path, revision.getChange().currentPatchSetId()));
|
path, revision.getChange().currentPatchSetId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Comment> list = ent.getValue();
|
List<CommentInput> list = ent.getValue();
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
mapItr.remove();
|
mapItr.remove();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<Comment> listItr = list.iterator();
|
Iterator<CommentInput> listItr = list.iterator();
|
||||||
while (listItr.hasNext()) {
|
while (listItr.hasNext()) {
|
||||||
Comment c = listItr.next();
|
CommentInput c = listItr.next();
|
||||||
if (c.line < 0) {
|
if (c.line < 0) {
|
||||||
throw new BadRequestException(String.format(
|
throw new BadRequestException(String.format(
|
||||||
"negative line number %d not allowed on %s",
|
"negative line number %d not allowed on %s",
|
||||||
@@ -315,7 +315,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean insertComments(RevisionResource rsrc,
|
private boolean insertComments(RevisionResource rsrc,
|
||||||
Map<String, List<Comment>> in, DraftHandling draftsHandling)
|
Map<String, List<CommentInput>> in, DraftHandling draftsHandling)
|
||||||
throws OrmException {
|
throws OrmException {
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
in = Collections.emptyMap();
|
in = Collections.emptyMap();
|
||||||
@@ -329,9 +329,9 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
|
|||||||
List<PatchLineComment> del = Lists.newArrayList();
|
List<PatchLineComment> del = Lists.newArrayList();
|
||||||
List<PatchLineComment> ups = Lists.newArrayList();
|
List<PatchLineComment> ups = Lists.newArrayList();
|
||||||
|
|
||||||
for (Map.Entry<String, List<Comment>> ent : in.entrySet()) {
|
for (Map.Entry<String, List<CommentInput>> ent : in.entrySet()) {
|
||||||
String path = ent.getKey();
|
String path = ent.getKey();
|
||||||
for (Comment c : ent.getValue()) {
|
for (CommentInput c : ent.getValue()) {
|
||||||
String parent = Url.decode(c.inReplyTo);
|
String parent = Url.decode(c.inReplyTo);
|
||||||
PatchLineComment e = drafts.remove(Url.decode(c.id));
|
PatchLineComment e = drafts.remove(Url.decode(c.id));
|
||||||
if (e == null) {
|
if (e == null) {
|
||||||
|
@@ -718,11 +718,11 @@ public abstract class AbstractQueryChangesTest {
|
|||||||
|
|
||||||
ReviewInput input = new ReviewInput();
|
ReviewInput input = new ReviewInput();
|
||||||
input.message = "toplevel";
|
input.message = "toplevel";
|
||||||
ReviewInput.Comment comment = new ReviewInput.Comment();
|
ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
|
||||||
comment.line = 1;
|
comment.line = 1;
|
||||||
comment.message = "inline";
|
comment.message = "inline";
|
||||||
input.comments = ImmutableMap.<String, List<ReviewInput.Comment>> of(
|
input.comments = ImmutableMap.<String, List<ReviewInput.CommentInput>> of(
|
||||||
Patch.COMMIT_MSG, ImmutableList.<ReviewInput.Comment> of(comment));
|
Patch.COMMIT_MSG, ImmutableList.<ReviewInput.CommentInput> of(comment));
|
||||||
postReview.apply(new RevisionResource(
|
postReview.apply(new RevisionResource(
|
||||||
changes.parse(change.getId()), ins.getPatchSet()), input);
|
changes.parse(change.getId()), ins.getPatchSet()), input);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user