From f2055007bcb471925dbb72024212ac325aaaec28 Mon Sep 17 00:00:00 2001 From: Michael Zhou Date: Thu, 6 Jun 2013 14:21:43 -0700 Subject: [PATCH] Adding api wrappers for getting comments. Pulling the Side enum into com.google.gerrit.common so that it's shared across the server and the client. Change-Id: I4d4e8b74dd2adcebc44e403a1cbf4352d05762fb --- .../google/gerrit/common/changes/Side.java | 20 +++++++ .../gerrit/client/changes/CommentApi.java | 31 +++++++++++ .../gerrit/client/changes/CommentInfo.java | 52 +++++++++++++++++++ .../gerrit/server/change/CommentInfo.java | 4 +- .../gerrit/server/change/CreateDraft.java | 3 +- .../gerrit/server/change/ListDrafts.java | 3 +- .../gerrit/server/change/PostReview.java | 5 +- .../google/gerrit/server/change/PutDraft.java | 4 +- .../gerrit/server/change/CommentsTest.java | 4 +- 9 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 gerrit-common/src/main/java/com/google/gerrit/common/changes/Side.java create mode 100644 gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommentApi.java create mode 100644 gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommentInfo.java diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/changes/Side.java b/gerrit-common/src/main/java/com/google/gerrit/common/changes/Side.java new file mode 100644 index 0000000000..777467d805 --- /dev/null +++ b/gerrit-common/src/main/java/com/google/gerrit/common/changes/Side.java @@ -0,0 +1,20 @@ +// Copyright (C) 2012 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.common.changes; + +/** The side on which a comment was added. */ +public enum Side { + PARENT, REVISION; +} \ No newline at end of file diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommentApi.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommentApi.java new file mode 100644 index 0000000000..570aed131d --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommentApi.java @@ -0,0 +1,31 @@ +// Copyright (C) 2013 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.client.changes; + +import com.google.gerrit.client.rpc.NativeMap; +import com.google.gerrit.reviewdb.client.PatchSet; +import com.google.gwt.core.client.JsArray; +import com.google.gwt.user.client.rpc.AsyncCallback; + +public class CommentApi { + + public static void comments(PatchSet.Id id, + AsyncCallback>> cb) { + ChangeApi.revision(id).view("comments").get(cb); + } + + private CommentApi() { + } +} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommentInfo.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommentInfo.java new file mode 100644 index 0000000000..7e229f60e9 --- /dev/null +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommentInfo.java @@ -0,0 +1,52 @@ +// Copyright (C) 2013 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.client.changes; + +import com.google.gerrit.client.account.AccountInfo; +import com.google.gerrit.common.changes.Side; +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwtjsonrpc.client.impl.ser.JavaSqlTimestamp_JsonSerializer; + +import java.sql.Timestamp; + +public class CommentInfo extends JavaScriptObject { + + public final native String id() /*-{ return this.id; }-*/; + public final native String path() /*-{ return this.path; }-*/; + + public final Side side() { + String s = sideRaw(); + return s != null + ? Side.valueOf(s) + : Side.REVISION; + } + private final native String sideRaw() /*-{ return this.side }-*/; + + public final native int line() /*-{ return this.line; }-*/; + public final native String in_reply_to() /*-{ return this.in_reply_to; }-*/; + public final native String message() /*-{ return this.message; }-*/; + + public final Timestamp updated() { + return JavaSqlTimestamp_JsonSerializer.parseTimestamp(updatedRaw()); + } + private final native String updatedRaw() /*-{ return this.updated; }-*/; + + public final native AccountInfo author() /*-{ return this.author; }-*/; + + public final native boolean has_line() /*-{ return this.hasOwnProperty('line'); }-*/; + + protected CommentInfo() { + } +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/CommentInfo.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/CommentInfo.java index 798b9c6c52..c0942b2aef 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/CommentInfo.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/CommentInfo.java @@ -15,6 +15,7 @@ package com.google.gerrit.server.change; import com.google.common.base.Strings; +import com.google.gerrit.common.changes.Side; import com.google.gerrit.extensions.restapi.Url; import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.server.account.AccountInfo; @@ -22,9 +23,6 @@ import com.google.gerrit.server.account.AccountInfo; import java.sql.Timestamp; public class CommentInfo { - static enum Side { - PARENT, REVISION; - } final String kind = "gerritcodereview#comment"; String id; diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/CreateDraft.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/CreateDraft.java index 5157af4a83..9ef1cfe073 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/CreateDraft.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/CreateDraft.java @@ -15,6 +15,7 @@ package com.google.gerrit.server.change; import com.google.common.base.Strings; +import com.google.gerrit.common.changes.Side; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.ResourceConflictException; @@ -60,7 +61,7 @@ class CreateDraft implements RestModifyView { rsrc.getAccountId(), Url.decode(in.inReplyTo)); c.setStatus(Status.DRAFT); - c.setSide(in.side == CommentInfo.Side.PARENT ? (short) 0 : (short) 1); + c.setSide(in.side == Side.PARENT ? (short) 0 : (short) 1); c.setMessage(in.message.trim()); db.get().patchComments().insert(Collections.singleton(c)); return Response.created(new CommentInfo(c, null)); diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/ListDrafts.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/ListDrafts.java index 47863acb2e..97c7694e09 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/ListDrafts.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/ListDrafts.java @@ -18,6 +18,7 @@ import static com.google.common.base.Objects.firstNonNull; import com.google.common.collect.Lists; import com.google.common.collect.Maps; +import com.google.gerrit.common.changes.Side; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.ResourceConflictException; @@ -25,8 +26,6 @@ import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.account.AccountInfo; -import com.google.gerrit.server.change.CommentInfo; -import com.google.gerrit.server.change.CommentInfo.Side; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; 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 9c14bcbbae..549c3c5353 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 @@ -21,6 +21,7 @@ import com.google.common.base.Strings; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gerrit.common.ChangeHooks; +import com.google.gerrit.common.changes.Side; import com.google.gerrit.common.data.LabelType; import com.google.gerrit.common.data.LabelTypes; import com.google.gerrit.common.data.Permission; @@ -92,7 +93,7 @@ public class PostReview implements RestModifyView { static class Comment { String id; - CommentInfo.Side side; + Side side; int line; String inReplyTo; String message; @@ -289,7 +290,7 @@ public class PostReview implements RestModifyView { } e.setStatus(PatchLineComment.Status.PUBLISHED); e.setWrittenOn(timestamp); - e.setSide(c.side == CommentInfo.Side.PARENT ? (short) 0 : (short) 1); + e.setSide(c.side == Side.PARENT ? (short) 0 : (short) 1); e.setMessage(c.message); (create ? ins : upd).add(e); } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/PutDraft.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/PutDraft.java index befb8d70d6..c6fc4fcee3 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/PutDraft.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/PutDraft.java @@ -14,6 +14,7 @@ package com.google.gerrit.server.change; +import com.google.gerrit.common.changes.Side; import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.extensions.restapi.DefaultInput; @@ -23,7 +24,6 @@ import com.google.gerrit.extensions.restapi.Url; import com.google.gerrit.reviewdb.client.Patch; import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.server.ReviewDb; -import com.google.gerrit.server.change.CommentInfo.Side; import com.google.gerrit.server.change.PutDraft.Input; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; @@ -90,7 +90,7 @@ class PutDraft implements RestModifyView { private PatchLineComment update(PatchLineComment e, Input in) { if (in.side != null) { - e.setSide(in.side == CommentInfo.Side.PARENT ? (short) 0 : (short) 1); + e.setSide(in.side == Side.PARENT ? (short) 0 : (short) 1); } if (in.line != null) { e.setLine(in.line); diff --git a/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java b/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java index 21d1ce4331..6a9a93fdcd 100644 --- a/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java +++ b/gerrit-server/src/test/java/com/google/gerrit/server/change/CommentsTest.java @@ -22,6 +22,7 @@ import static org.easymock.EasyMock.replay; import com.google.common.base.Objects; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; +import com.google.gerrit.common.changes.Side; import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.restapi.IdString; import com.google.gerrit.extensions.restapi.ResourceNotFoundException; @@ -36,7 +37,6 @@ import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.server.PatchLineCommentAccess; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.account.AccountInfo; -import com.google.gerrit.server.change.CommentInfo.Side; import com.google.gwtorm.server.ListResultSet; import com.google.gwtorm.server.ResultSet; import com.google.inject.AbstractModule; @@ -216,7 +216,7 @@ public class CommentsTest extends TestCase { PatchLineComment plc = new PatchLineComment(id, line, authorId, inReplyToUuid); plc.setMessage(message); - plc.setSide(side == CommentInfo.Side.PARENT ? (short) 0 : (short) 1); + plc.setSide(side == Side.PARENT ? (short) 0 : (short) 1); plc.setStatus(Status.PUBLISHED); plc.setWrittenOn(new Timestamp(millis)); return plc;