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
This commit is contained in:
parent
60878e7cf1
commit
f2055007bc
@ -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;
|
||||
}
|
@ -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<NativeMap<JsArray<CommentInfo>>> cb) {
|
||||
ChangeApi.revision(id).view("comments").get(cb);
|
||||
}
|
||||
|
||||
private CommentApi() {
|
||||
}
|
||||
}
|
@ -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() {
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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<RevisionResource, Input> {
|
||||
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));
|
||||
|
@ -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;
|
||||
|
@ -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<RevisionResource, Input> {
|
||||
|
||||
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<RevisionResource, Input> {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
@ -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<DraftResource, Input> {
|
||||
|
||||
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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user