From 0561211396bf6a93f9d05a016c99d379a6d15119 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Fri, 6 Dec 2013 22:10:09 +0100 Subject: [PATCH 1/5] Remove old EditCommitMessage RPC Change-Id: Ic25c5d68f3bb27423b7c6b829169e33c8361eba5 --- .../common/data/ChangeManageService.java | 5 -- .../changes/ChangeDescriptionBlock.java | 2 +- .../client/changes/CommitMessageBlock.java | 43 +++++---- .../changedetail/ChangeManageServiceImpl.java | 11 +-- .../httpd/rpc/changedetail/ChangeModule.java | 1 - .../EditCommitMessageHandler.java | 87 ------------------- 6 files changed, 22 insertions(+), 127 deletions(-) delete mode 100644 gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/EditCommitMessageHandler.java diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java index d0e5154776..a0376c9ca3 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java @@ -25,11 +25,6 @@ import com.google.gwtjsonrpc.common.RpcImpl.Version; @RpcImpl(version = Version.V2_0) public interface ChangeManageService extends RemoteJsonService { - @Audit - @SignInRequired - void createNewPatchSet(final PatchSet.Id patchSetId, final String newCommitMessage, - final AsyncCallback callback); - @Audit @SignInRequired void publish(PatchSet.Id patchSetId, AsyncCallback callback); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeDescriptionBlock.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeDescriptionBlock.java index 6b13ba0abf..8f2642c385 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeDescriptionBlock.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/ChangeDescriptionBlock.java @@ -42,7 +42,7 @@ public class ChangeDescriptionBlock extends Composite { SubmitTypeRecord submitTypeRecord, CommentLinkProcessor commentLinkProcessor) { infoBlock.display(changeDetail, acc, submitTypeRecord); - messageBlock.display(changeDetail.getChange().currentPatchSetId(), starred, + messageBlock.display(changeDetail.getChange().currentPatchSetId(), info.getRevId(), starred, canEditCommitMessage, info.getMessage(), commentLinkProcessor); } } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommitMessageBlock.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommitMessageBlock.java index f612dcda09..1f66b7274b 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommitMessageBlock.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/CommitMessageBlock.java @@ -14,17 +14,17 @@ package com.google.gerrit.client.changes; -import com.google.gerrit.client.ErrorDialog; import com.google.gerrit.client.Gerrit; +import com.google.gerrit.client.rpc.GerritCallback; import com.google.gerrit.client.ui.ChangeLink; import com.google.gerrit.client.ui.CommentLinkProcessor; import com.google.gerrit.client.ui.CommentedActionDialog; import com.google.gerrit.client.ui.TextBoxChangeListener; import com.google.gerrit.common.PageLinks; -import com.google.gerrit.common.data.ChangeDetail; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.dom.client.PreElement; import com.google.gwt.dom.client.Style.Display; import com.google.gwt.event.dom.client.ClickEvent; @@ -70,13 +70,14 @@ public class CommitMessageBlock extends Composite { public void display(String commitMessage, CommentLinkProcessor commentLinkProcessor) { - display(null, null, false, commitMessage, commentLinkProcessor); + display(null, null, null, false, commitMessage, commentLinkProcessor); } - private abstract class CommitMessageEditDialog extends CommentedActionDialog { + private abstract class CommitMessageEditDialog + extends CommentedActionDialog { private final String originalMessage; public CommitMessageEditDialog(final String title, final String heading, - final String commitMessage, AsyncCallback callback) { + final String commitMessage, AsyncCallback callback) { super(title, heading, callback); originalMessage = commitMessage.trim(); message.setCharacterWidth(72); @@ -103,7 +104,7 @@ public class CommitMessageBlock extends Composite { } } - public void display(final PatchSet.Id patchSetId, + public void display(final PatchSet.Id patchSetId, final String revision, Boolean starred, Boolean canEditCommitMessage, final String commitMessage, CommentLinkProcessor commentLinkProcessor) { starPanel.clear(); @@ -119,7 +120,7 @@ public class CommitMessageBlock extends Composite { } permalinkPanel.clear(); - if (patchSetId != null) { + if (patchSetId != null && revision != null) { final Change.Id changeId = patchSetId.getParentKey(); permalinkPanel.add(new ChangeLink(Util.C.changePermalink(), changeId)); permalinkPanel.add(new CopyableLabel(ChangeLink.permalink(changeId), @@ -134,24 +135,20 @@ public class CommitMessageBlock extends Composite { new CommitMessageEditDialog(Util.C.titleEditCommitMessage(), Util.C.headingEditCommitMessage(), commitMessage, - new ChangeDetailCache.IgnoreErrorCallback() {}) { - + new GerritCallback() { + @Override + public void onSuccess(JavaScriptObject result) {} + }) { @Override public void onSend() { - Util.MANAGE_SVC.createNewPatchSet(patchSetId, getMessageText(), - new AsyncCallback() { - @Override - public void onSuccess(ChangeDetail result) { - Gerrit.display(PageLinks.toChange(changeId)); - hide(); - } - - @Override - public void onFailure(Throwable caught) { - enableButtons(true); - new ErrorDialog(caught.getMessage()).center(); - } - }); + ChangeApi.message(changeId.get(), revision, getMessageText(), + new GerritCallback() { + @Override + public void onSuccess(JavaScriptObject msg) { + Gerrit.display(PageLinks.toChange(changeId)); + hide(); + } + }); } }.center(); } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java index 53e0d9de87..e683d88523 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java @@ -17,7 +17,6 @@ package com.google.gerrit.httpd.rpc.changedetail; import com.google.gerrit.common.data.ChangeDetail; import com.google.gerrit.common.data.ChangeManageService; import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gerrit.reviewdb.client.PatchSet.Id; import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtjsonrpc.common.VoidResult; import com.google.inject.Inject; @@ -26,18 +25,15 @@ class ChangeManageServiceImpl implements ChangeManageService { private final RebaseChangeHandler.Factory rebaseChangeFactory; private final PublishAction.Factory publishAction; private final DeleteDraftChange.Factory deleteDraftChangeFactory; - private final EditCommitMessageHandler.Factory editCommitMessageHandlerFactory; @Inject ChangeManageServiceImpl( final RebaseChangeHandler.Factory rebaseChangeFactory, final PublishAction.Factory publishAction, - final DeleteDraftChange.Factory deleteDraftChangeFactory, - final EditCommitMessageHandler.Factory editCommitMessageHandler) { + final DeleteDraftChange.Factory deleteDraftChangeFactory) { this.rebaseChangeFactory = rebaseChangeFactory; this.publishAction = publishAction; this.deleteDraftChangeFactory = deleteDraftChangeFactory; - this.editCommitMessageHandlerFactory = editCommitMessageHandler; } public void rebaseChange(final PatchSet.Id patchSetId, @@ -54,9 +50,4 @@ class ChangeManageServiceImpl implements ChangeManageService { final AsyncCallback callback) { deleteDraftChangeFactory.create(patchSetId).to(callback); } - - public void createNewPatchSet(Id patchSetId, String message, - AsyncCallback callback) { - editCommitMessageHandlerFactory.create(patchSetId, message).to(callback); - } } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java index 48c13c2698..3d2740e630 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java @@ -28,7 +28,6 @@ public class ChangeModule extends RpcServletModule { install(new FactoryModule() { @Override protected void configure() { - factory(EditCommitMessageHandler.Factory.class); factory(RebaseChangeHandler.Factory.class); factory(ChangeDetailFactory.Factory.class); factory(IncludedInDetailFactory.Factory.class); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/EditCommitMessageHandler.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/EditCommitMessageHandler.java deleted file mode 100644 index f8e4d1eeac..0000000000 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/EditCommitMessageHandler.java +++ /dev/null @@ -1,87 +0,0 @@ -// 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.httpd.rpc.changedetail; - -import com.google.gerrit.common.Nullable; -import com.google.gerrit.common.data.ChangeDetail; -import com.google.gerrit.common.errors.EmailException; -import com.google.gerrit.common.errors.NoSuchEntityException; -import com.google.gerrit.httpd.rpc.Handler; -import com.google.gerrit.reviewdb.client.Change; -import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gerrit.server.ChangeUtil; -import com.google.gerrit.server.GerritPersonIdent; -import com.google.gerrit.server.change.PatchSetInserter; -import com.google.gerrit.server.mail.CommitMessageEditedSender; -import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException; -import com.google.gerrit.server.project.ChangeControl; -import com.google.gerrit.server.project.InvalidChangeOperationException; -import com.google.gerrit.server.project.NoSuchChangeException; -import com.google.gerrit.server.project.NoSuchProjectException; -import com.google.gwtorm.server.OrmException; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; - -import org.eclipse.jgit.errors.IncorrectObjectTypeException; -import org.eclipse.jgit.errors.MissingObjectException; -import org.eclipse.jgit.lib.PersonIdent; - -import java.io.IOException; - -class EditCommitMessageHandler extends Handler { - interface Factory { - EditCommitMessageHandler create(PatchSet.Id patchSetId, String message); - } - - private final ChangeControl.Factory changeControlFactory; - private final ChangeDetailFactory.Factory changeDetailFactory; - private final ChangeUtil changeUtil; - private final PatchSet.Id patchSetId; - @Nullable - private final String message; - private final PersonIdent myIdent; - - @Inject - EditCommitMessageHandler(ChangeControl.Factory changeControlFactory, - ChangeDetailFactory.Factory changeDetailFactory, - CommitMessageEditedSender.Factory commitMessageEditedSenderFactory, - @Assisted PatchSet.Id patchSetId, - @Assisted @Nullable String message, - ChangeUtil changeUtil, - @GerritPersonIdent PersonIdent myIdent, - PatchSetInserter.Factory patchSetInserterFactory) { - this.changeControlFactory = changeControlFactory; - this.changeDetailFactory = changeDetailFactory; - this.changeUtil = changeUtil; - this.patchSetId = patchSetId; - this.message = message; - this.myIdent = myIdent; - } - - @Override - public ChangeDetail call() throws NoSuchChangeException, OrmException, - EmailException, NoSuchEntityException, PatchSetInfoNotAvailableException, - MissingObjectException, IncorrectObjectTypeException, IOException, - InvalidChangeOperationException, NoSuchProjectException { - Change.Id changeId = patchSetId.getParentKey(); - ChangeControl control = changeControlFactory.validateFor(changeId); - if (!control.canAddPatchSet()) { - throw new InvalidChangeOperationException( - "Not allowed to add new Patch Sets to: " + changeId.toString()); - } - changeUtil.editCommitMessage(control, patchSetId, message, myIdent); - return changeDetailFactory.create(changeId).call(); - } -} From d0a4fea342235bca8ec880f054419f3813e47a49 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Fri, 6 Dec 2013 22:33:42 +0100 Subject: [PATCH 2/5] Remove old DeleteDraftChange RPC Change-Id: I77f1cb57123922aa519eddbeda3b6b9fa44ea559 --- .../common/data/ChangeManageService.java | 5 -- .../PatchSetComplexDisclosurePanel.java | 27 ++++---- .../changedetail/ChangeManageServiceImpl.java | 11 +--- .../httpd/rpc/changedetail/ChangeModule.java | 1 - .../rpc/changedetail/DeleteDraftChange.java | 62 ------------------- 5 files changed, 16 insertions(+), 90 deletions(-) delete mode 100644 gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/DeleteDraftChange.java diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java index a0376c9ca3..6922d2394c 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java @@ -20,7 +20,6 @@ import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtjsonrpc.common.RemoteJsonService; import com.google.gwtjsonrpc.common.RpcImpl; -import com.google.gwtjsonrpc.common.VoidResult; import com.google.gwtjsonrpc.common.RpcImpl.Version; @RpcImpl(version = Version.V2_0) @@ -29,10 +28,6 @@ public interface ChangeManageService extends RemoteJsonService { @SignInRequired void publish(PatchSet.Id patchSetId, AsyncCallback callback); - @Audit - @SignInRequired - void deleteDraftChange(PatchSet.Id patchSetId, AsyncCallback callback); - @Audit @SignInRequired void rebaseChange(PatchSet.Id patchSetId, AsyncCallback callback); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java index a11d8a674e..4365793399 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java @@ -55,7 +55,6 @@ import com.google.gwt.user.client.ui.HTMLTable.CellFormatter; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.InlineLabel; import com.google.gwt.user.client.ui.Panel; -import com.google.gwtjsonrpc.common.VoidResult; import java.util.HashSet; import java.util.List; @@ -479,18 +478,22 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel @Override public void onClick(final ClickEvent event) { b.setEnabled(false); - Util.MANAGE_SVC.deleteDraftChange(patchSet.getId(), - new GerritCallback() { - public void onSuccess(VoidResult result) { - Gerrit.display(PageLinks.MINE); - } + ChangeApi.deleteChange(patchSet.getId().getParentKey().get(), + new GerritCallback() { + public void onSuccess(JavaScriptObject result) { + Gerrit.display(PageLinks.MINE); + } - @Override - public void onFailure(Throwable caught) { - b.setEnabled(true); - super.onFailure(caught); - } - }); + public void onFailure(Throwable err) { + if (SubmitFailureDialog.isConflict(err)) { + new SubmitFailureDialog(err.getMessage()).center(); + Gerrit.display(PageLinks.MINE); + } else { + b.setEnabled(true); + super.onFailure(err); + } + } + }); } }); actionsPanel.add(b); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java index e683d88523..bf9a24541e 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java @@ -18,22 +18,18 @@ import com.google.gerrit.common.data.ChangeDetail; import com.google.gerrit.common.data.ChangeManageService; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gwtjsonrpc.common.AsyncCallback; -import com.google.gwtjsonrpc.common.VoidResult; import com.google.inject.Inject; class ChangeManageServiceImpl implements ChangeManageService { private final RebaseChangeHandler.Factory rebaseChangeFactory; private final PublishAction.Factory publishAction; - private final DeleteDraftChange.Factory deleteDraftChangeFactory; @Inject ChangeManageServiceImpl( final RebaseChangeHandler.Factory rebaseChangeFactory, - final PublishAction.Factory publishAction, - final DeleteDraftChange.Factory deleteDraftChangeFactory) { + final PublishAction.Factory publishAction) { this.rebaseChangeFactory = rebaseChangeFactory; this.publishAction = publishAction; - this.deleteDraftChangeFactory = deleteDraftChangeFactory; } public void rebaseChange(final PatchSet.Id patchSetId, @@ -45,9 +41,4 @@ class ChangeManageServiceImpl implements ChangeManageService { final AsyncCallback callback) { publishAction.create(patchSetId).to(callback); } - - public void deleteDraftChange(final PatchSet.Id patchSetId, - final AsyncCallback callback) { - deleteDraftChangeFactory.create(patchSetId).to(callback); - } } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java index 3d2740e630..99a623695e 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java @@ -34,7 +34,6 @@ public class ChangeModule extends RpcServletModule { factory(PatchSetDetailFactory.Factory.class); factory(PatchSetPublishDetailFactory.Factory.class); factory(PublishAction.Factory.class); - factory(DeleteDraftChange.Factory.class); } }); rpc(ChangeDetailServiceImpl.class); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/DeleteDraftChange.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/DeleteDraftChange.java deleted file mode 100644 index bee5613464..0000000000 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/DeleteDraftChange.java +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2011 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.httpd.rpc.changedetail; - -import com.google.gerrit.httpd.rpc.Handler; -import com.google.gerrit.reviewdb.client.Change; -import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gerrit.reviewdb.server.ReviewDb; -import com.google.gerrit.server.ChangeUtil; -import com.google.gerrit.server.project.ChangeControl; -import com.google.gerrit.server.project.NoSuchChangeException; -import com.google.gwtjsonrpc.common.VoidResult; -import com.google.gwtorm.server.OrmException; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; - -import java.io.IOException; - -class DeleteDraftChange extends Handler { - interface Factory { - DeleteDraftChange create(PatchSet.Id patchSetId); - } - - private final ChangeControl.Factory changeControlFactory; - private final ReviewDb db; - private final ChangeUtil changeUtil; - private final PatchSet.Id patchSetId; - - @Inject - DeleteDraftChange(ReviewDb db, - ChangeControl.Factory changeControlFactory, - ChangeUtil changeUtil, - @Assisted PatchSet.Id patchSetId) { - this.changeControlFactory = changeControlFactory; - this.db = db; - this.changeUtil = changeUtil; - this.patchSetId = patchSetId; - } - - @Override - public VoidResult call() throws NoSuchChangeException, OrmException, IOException { - Change.Id changeId = patchSetId.getParentKey(); - ChangeControl control = changeControlFactory.validateFor(changeId); - if (!control.canDeleteDraft(db)) { - throw new NoSuchChangeException(changeId); - } - changeUtil.deleteDraftChange(patchSetId); - return VoidResult.INSTANCE; - } -} From 68b7449da7e925d7da1161ea5b9bf49c75abf55a Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sat, 7 Dec 2013 00:21:37 +0100 Subject: [PATCH 3/5] Remove old publish RPC Change-Id: I23d2b007ab4f0154d763973f838505f31d071c48 --- .../common/data/ChangeManageService.java | 4 -- .../gerrit/client/change/DraftActions.java | 4 +- .../PatchSetComplexDisclosurePanel.java | 7 +- .../changedetail/ChangeManageServiceImpl.java | 10 +-- .../httpd/rpc/changedetail/ChangeModule.java | 1 - .../httpd/rpc/changedetail/PublishAction.java | 65 ------------------- 6 files changed, 8 insertions(+), 83 deletions(-) delete mode 100644 gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PublishAction.java diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java index 6922d2394c..9a18d0d9ff 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java @@ -24,10 +24,6 @@ import com.google.gwtjsonrpc.common.RpcImpl.Version; @RpcImpl(version = Version.V2_0) public interface ChangeManageService extends RemoteJsonService { - @Audit - @SignInRequired - void publish(PatchSet.Id patchSetId, AsyncCallback callback); - @Audit @SignInRequired void rebaseChange(PatchSet.Id patchSetId, AsyncCallback callback); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/DraftActions.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/DraftActions.java index 808e4f0a75..d0666c644e 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/DraftActions.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/change/DraftActions.java @@ -23,7 +23,7 @@ import com.google.gerrit.reviewdb.client.Change; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.user.client.rpc.AsyncCallback; -class DraftActions { +public class DraftActions { static void publish(Change.Id id, String revision) { ChangeApi.publish(id.get(), revision, cs(id)); @@ -37,7 +37,7 @@ class DraftActions { ChangeApi.deleteChange(id.get(), mine()); } - private static GerritCallback cs( + public static GerritCallback cs( final Change.Id id) { return new GerritCallback() { public void onSuccess(JavaScriptObject result) { diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java index 4365793399..bf50407efc 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java @@ -18,6 +18,7 @@ import com.google.gerrit.client.ErrorDialog; import com.google.gerrit.client.FormatUtil; import com.google.gerrit.client.Gerrit; import com.google.gerrit.client.GitwebLink; +import com.google.gerrit.client.change.DraftActions; import com.google.gerrit.client.download.DownloadPanel; import com.google.gerrit.client.patches.PatchUtil; import com.google.gerrit.client.rpc.GerritCallback; @@ -608,8 +609,10 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel @Override public void onClick(final ClickEvent event) { b.setEnabled(false); - Util.MANAGE_SVC.publish(patchSet.getId(), - new ChangeDetailCache.GerritWidgetCallback(b)); + final Change.Id id = patchSet.getId().getParentKey(); + ChangeApi.publish(id.get(), + patchSet.getRevision().get(), + DraftActions.cs(id)); } }); actionsPanel.add(b); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java index bf9a24541e..00e83af53d 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java @@ -22,23 +22,15 @@ import com.google.inject.Inject; class ChangeManageServiceImpl implements ChangeManageService { private final RebaseChangeHandler.Factory rebaseChangeFactory; - private final PublishAction.Factory publishAction; @Inject ChangeManageServiceImpl( - final RebaseChangeHandler.Factory rebaseChangeFactory, - final PublishAction.Factory publishAction) { + final RebaseChangeHandler.Factory rebaseChangeFactory) { this.rebaseChangeFactory = rebaseChangeFactory; - this.publishAction = publishAction; } public void rebaseChange(final PatchSet.Id patchSetId, final AsyncCallback callback) { rebaseChangeFactory.create(patchSetId).to(callback); } - - public void publish(final PatchSet.Id patchSetId, - final AsyncCallback callback) { - publishAction.create(patchSetId).to(callback); - } } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java index 99a623695e..a286a41918 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java @@ -33,7 +33,6 @@ public class ChangeModule extends RpcServletModule { factory(IncludedInDetailFactory.Factory.class); factory(PatchSetDetailFactory.Factory.class); factory(PatchSetPublishDetailFactory.Factory.class); - factory(PublishAction.Factory.class); } }); rpc(ChangeDetailServiceImpl.class); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PublishAction.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PublishAction.java deleted file mode 100644 index 38f8fc62bf..0000000000 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PublishAction.java +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2011 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.httpd.rpc.changedetail; - -import com.google.gerrit.common.data.ChangeDetail; -import com.google.gerrit.common.data.ReviewResult; -import com.google.gerrit.common.errors.NoSuchEntityException; -import com.google.gerrit.httpd.rpc.Handler; -import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gerrit.server.changedetail.PublishDraft; -import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException; -import com.google.gerrit.server.project.NoSuchChangeException; -import com.google.gerrit.server.project.NoSuchProjectException; -import com.google.gwtorm.server.OrmException; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; - -import org.eclipse.jgit.errors.RepositoryNotFoundException; - -import java.io.IOException; - -class PublishAction extends Handler { - interface Factory { - PublishAction create(PatchSet.Id patchSetId); - } - - private final PublishDraft.Factory publishFactory; - private final ChangeDetailFactory.Factory changeDetailFactory; - - private final PatchSet.Id patchSetId; - - @Inject - PublishAction(final PublishDraft.Factory publishFactory, - final ChangeDetailFactory.Factory changeDetailFactory, - @Assisted final PatchSet.Id patchSetId) { - this.publishFactory = publishFactory; - this.changeDetailFactory = changeDetailFactory; - - this.patchSetId = patchSetId; - } - - @Override - public ChangeDetail call() throws OrmException, NoSuchEntityException, - IllegalStateException, PatchSetInfoNotAvailableException, - NoSuchChangeException, RepositoryNotFoundException, IOException, - NoSuchProjectException { - final ReviewResult result = publishFactory.create(patchSetId).call(); - if (result.getErrors().size() > 0) { - throw new IllegalStateException("Cannot publish patchset"); - } - return changeDetailFactory.create(result.getChangeId()).call(); - } -} From a15cfff1b23cd7f2d8ce8ddbc6be14d52a16c5b8 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sat, 7 Dec 2013 00:28:50 +0100 Subject: [PATCH 4/5] Remove old rebaseChange RPC Change-Id: Ieb55dd1c01f1161649400a375119bdd89ec50330 --- .../common/data/ChangeManageService.java | 30 -------- .../PatchSetComplexDisclosurePanel.java | 9 ++- .../google/gerrit/client/changes/Util.java | 5 -- .../changedetail/ChangeManageServiceImpl.java | 36 ---------- .../httpd/rpc/changedetail/ChangeModule.java | 2 - .../rpc/changedetail/RebaseChangeHandler.java | 68 ------------------- 6 files changed, 7 insertions(+), 143 deletions(-) delete mode 100644 gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java delete mode 100644 gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java delete mode 100644 gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/RebaseChangeHandler.java diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java deleted file mode 100644 index 9a18d0d9ff..0000000000 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/ChangeManageService.java +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2009 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.data; - -import com.google.gerrit.common.audit.Audit; -import com.google.gerrit.common.auth.SignInRequired; -import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gwtjsonrpc.common.AsyncCallback; -import com.google.gwtjsonrpc.common.RemoteJsonService; -import com.google.gwtjsonrpc.common.RpcImpl; -import com.google.gwtjsonrpc.common.RpcImpl.Version; - -@RpcImpl(version = Version.V2_0) -public interface ChangeManageService extends RemoteJsonService { - @Audit - @SignInRequired - void rebaseChange(PatchSet.Id patchSetId, AsyncCallback callback); -} diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java index bf50407efc..6ec71554fa 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java @@ -543,8 +543,13 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel @Override public void onClick(final ClickEvent event) { b.setEnabled(false); - Util.MANAGE_SVC.rebaseChange(patchSet.getId(), - new ChangeDetailCache.GerritWidgetCallback(b)); + final Change.Id id = patchSet.getId().getParentKey(); + ChangeApi.rebase(id.get(), patchSet.getRevision().get(), + new GerritCallback() { + public void onSuccess(ChangeInfo result) { + Gerrit.display(PageLinks.toChange(id)); + } + }); } }); actionsPanel.add(b); diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/Util.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/Util.java index 76dfd58aec..9c16330c0e 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/Util.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/Util.java @@ -15,7 +15,6 @@ package com.google.gerrit.client.changes; import com.google.gerrit.common.data.ChangeDetailService; -import com.google.gerrit.common.data.ChangeManageService; import com.google.gerrit.reviewdb.client.Change; import com.google.gwt.core.client.GWT; import com.google.gwtjsonrpc.client.JsonUtil; @@ -26,7 +25,6 @@ public class Util { public static final ChangeResources R = GWT.create(ChangeResources.class); public static final ChangeDetailService DETAIL_SVC; - public static final ChangeManageService MANAGE_SVC; private static final int SUBJECT_MAX_LENGTH = 80; private static final String SUBJECT_CROP_APPENDIX = "..."; @@ -35,9 +33,6 @@ public class Util { static { DETAIL_SVC = GWT.create(ChangeDetailService.class); JsonUtil.bind(DETAIL_SVC, "rpc/ChangeDetailService"); - - MANAGE_SVC = GWT.create(ChangeManageService.class); - JsonUtil.bind(MANAGE_SVC, "rpc/ChangeManageService"); } public static String toLongString(final Change.Status status) { diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java deleted file mode 100644 index 00e83af53d..0000000000 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeManageServiceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2009 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.httpd.rpc.changedetail; - -import com.google.gerrit.common.data.ChangeDetail; -import com.google.gerrit.common.data.ChangeManageService; -import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gwtjsonrpc.common.AsyncCallback; -import com.google.inject.Inject; - -class ChangeManageServiceImpl implements ChangeManageService { - private final RebaseChangeHandler.Factory rebaseChangeFactory; - - @Inject - ChangeManageServiceImpl( - final RebaseChangeHandler.Factory rebaseChangeFactory) { - this.rebaseChangeFactory = rebaseChangeFactory; - } - - public void rebaseChange(final PatchSet.Id patchSetId, - final AsyncCallback callback) { - rebaseChangeFactory.create(patchSetId).to(callback); - } -} diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java index a286a41918..6069f85162 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/ChangeModule.java @@ -28,7 +28,6 @@ public class ChangeModule extends RpcServletModule { install(new FactoryModule() { @Override protected void configure() { - factory(RebaseChangeHandler.Factory.class); factory(ChangeDetailFactory.Factory.class); factory(IncludedInDetailFactory.Factory.class); factory(PatchSetDetailFactory.Factory.class); @@ -36,6 +35,5 @@ public class ChangeModule extends RpcServletModule { } }); rpc(ChangeDetailServiceImpl.class); - rpc(ChangeManageServiceImpl.class); } } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/RebaseChangeHandler.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/RebaseChangeHandler.java deleted file mode 100644 index 8558fe8e7d..0000000000 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/RebaseChangeHandler.java +++ /dev/null @@ -1,68 +0,0 @@ -// 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.httpd.rpc.changedetail; - -import com.google.gerrit.common.data.ChangeDetail; -import com.google.gerrit.common.errors.EmailException; -import com.google.gerrit.common.errors.NoSuchEntityException; -import com.google.gerrit.httpd.rpc.Handler; -import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gerrit.server.IdentifiedUser; -import com.google.gerrit.server.changedetail.RebaseChange; -import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException; -import com.google.gerrit.server.project.InvalidChangeOperationException; -import com.google.gerrit.server.project.NoSuchChangeException; -import com.google.gerrit.server.project.NoSuchProjectException; -import com.google.gwtorm.server.OrmException; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; - -import org.eclipse.jgit.errors.IncorrectObjectTypeException; -import org.eclipse.jgit.errors.MissingObjectException; - -import java.io.IOException; - -class RebaseChangeHandler extends Handler { - interface Factory { - RebaseChangeHandler create(PatchSet.Id patchSetId); - } - - private final RebaseChange rebaseChange; - private final IdentifiedUser currentUser; - private final ChangeDetailFactory.Factory changeDetailFactory; - - private final PatchSet.Id patchSetId; - - @Inject - RebaseChangeHandler(final RebaseChange rebaseChange, - final IdentifiedUser currentUser, - final ChangeDetailFactory.Factory changeDetailFactory, - @Assisted final PatchSet.Id patchSetId) { - this.rebaseChange = rebaseChange; - this.currentUser = currentUser; - this.changeDetailFactory = changeDetailFactory; - - this.patchSetId = patchSetId; - } - - @Override - public ChangeDetail call() throws NoSuchChangeException, OrmException, - EmailException, NoSuchEntityException, PatchSetInfoNotAvailableException, - MissingObjectException, IncorrectObjectTypeException, IOException, - InvalidChangeOperationException, NoSuchProjectException { - rebaseChange.rebase(patchSetId, currentUser); - return changeDetailFactory.create(patchSetId.getParentKey()).call(); - } -} From ad47c869c5405648f14af6695f6187d391445398 Mon Sep 17 00:00:00 2001 From: David Ostrovsky Date: Sat, 7 Dec 2013 01:09:56 +0100 Subject: [PATCH 5/5] Remove old deleteDraftPatchSet RPC Change-Id: I89f4a6dd5307f40a7b1b58596ce111b5b7c51a0b --- .../common/data/PatchDetailService.java | 17 --- .../PatchSetComplexDisclosurePanel.java | 14 +- .../rpc/patch/PatchDetailServiceImpl.java | 47 ------- .../changedetail/DeleteDraftPatchSet.java | 120 ------------------ .../server/config/GerritRequestModule.java | 2 - 5 files changed, 4 insertions(+), 196 deletions(-) delete mode 100644 gerrit-server/src/main/java/com/google/gerrit/server/changedetail/DeleteDraftPatchSet.java diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchDetailService.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchDetailService.java index bf14b55fe6..8015117b1c 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchDetailService.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/PatchDetailService.java @@ -40,21 +40,4 @@ public interface PatchDetailService extends RemoteJsonService { @Audit @SignInRequired void deleteDraft(PatchLineComment.Key key, AsyncCallback callback); - - /** - * Deletes the specified draft patch set. If the draft patch set is the only - * patch set of the change, then also the change gets deleted. - * - * @param psid ID of the draft patch set that should be deleted - * @param callback callback to report the result of the draft patch set - * deletion operation; if the draft patch set was successfully deleted - * {@link AsyncCallback#onSuccess(Object)} is invoked and the change - * details are passed as parameter; if the change gets deleted because - * the draft patch set that was deleted was the only patch set in the - * change, then {@code null} is passed as result to - * {@link AsyncCallback#onSuccess(Object)} - */ - @Audit - @SignInRequired - void deleteDraftPatchSet(PatchSet.Id psid, AsyncCallback callback); } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java index 6ec71554fa..6c6147e08f 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java @@ -629,16 +629,10 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel @Override public void onClick(final ClickEvent event) { b.setEnabled(false); - PatchUtil.DETAIL_SVC.deleteDraftPatchSet(patchSet.getId(), - new ChangeDetailCache.GerritWidgetCallback(b) { - public void onSuccess(final ChangeDetail result) { - if (result != null) { - detailCache.set(result); - } else { - Gerrit.display(PageLinks.MINE); - } - } - }); + final Change.Id id = patchSet.getId().getParentKey(); + ChangeApi.deleteRevision(id.get(), + patchSet.getRevision().get(), + DraftActions.cs(id)); } }); actionsPanel.add(b); diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchDetailServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchDetailServiceImpl.java index 98d3661e4d..833a00d9ea 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchDetailServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/patch/PatchDetailServiceImpl.java @@ -14,10 +14,8 @@ package com.google.gerrit.httpd.rpc.patch; -import com.google.gerrit.common.data.ChangeDetail; import com.google.gerrit.common.data.PatchDetailService; import com.google.gerrit.common.data.PatchScript; -import com.google.gerrit.common.data.ReviewResult; import com.google.gerrit.common.errors.NoSuchEntityException; import com.google.gerrit.httpd.rpc.BaseServiceImplementation; import com.google.gerrit.httpd.rpc.Handler; @@ -29,45 +27,33 @@ import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.CurrentUser; -import com.google.gerrit.server.changedetail.DeleteDraftPatchSet; import com.google.gerrit.server.patch.PatchScriptFactory; -import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException; import com.google.gerrit.server.project.ChangeControl; -import com.google.gerrit.server.project.NoSuchChangeException; -import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gwtjsonrpc.common.AsyncCallback; import com.google.gwtjsonrpc.common.VoidResult; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.Provider; -import org.eclipse.jgit.errors.RepositoryNotFoundException; - -import java.io.IOException; import java.util.Collections; class PatchDetailServiceImpl extends BaseServiceImplementation implements PatchDetailService { - private final DeleteDraftPatchSet.Factory deleteDraftPatchSetFactory; private final PatchScriptFactory.Factory patchScriptFactoryFactory; private final SaveDraft.Factory saveDraftFactory; - private final ChangeDetailFactory.Factory changeDetailFactory; private final ChangeControl.Factory changeControlFactory; @Inject PatchDetailServiceImpl(final Provider schema, final Provider currentUser, - final DeleteDraftPatchSet.Factory deleteDraftPatchSetFactory, final PatchScriptFactory.Factory patchScriptFactoryFactory, final SaveDraft.Factory saveDraftFactory, final ChangeDetailFactory.Factory changeDetailFactory, final ChangeControl.Factory changeControlFactory) { super(schema, currentUser); - this.deleteDraftPatchSetFactory = deleteDraftPatchSetFactory; this.patchScriptFactoryFactory = patchScriptFactoryFactory; this.saveDraftFactory = saveDraftFactory; - this.changeDetailFactory = changeDetailFactory; this.changeControlFactory = changeControlFactory; } @@ -121,37 +107,4 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements } }); } - - public void deleteDraftPatchSet(final PatchSet.Id psid, - final AsyncCallback callback) { - run(callback, new Action() { - public ChangeDetail run(ReviewDb db) throws OrmException, Failure { - ReviewResult result; - try { - result = deleteDraftPatchSetFactory.create(psid).call(); - if (result.getErrors().size() > 0) { - throw new Failure(new NoSuchEntityException()); - } - if (result.getChangeId() == null) { - // the change was deleted because the draft patch set that was - // deleted was the only patch set in the change - return null; - } - return changeDetailFactory.create(result.getChangeId()).call(); - } catch (NoSuchChangeException e) { - throw new Failure(new NoSuchChangeException(psid.getParentKey())); - } catch (NoSuchProjectException e) { - throw new Failure(e); - } catch (NoSuchEntityException e) { - throw new Failure(e); - } catch (PatchSetInfoNotAvailableException e) { - throw new Failure(e); - } catch (RepositoryNotFoundException e) { - throw new Failure(e); - } catch (IOException e) { - throw new Failure(e); - } - } - }); - } } diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/changedetail/DeleteDraftPatchSet.java b/gerrit-server/src/main/java/com/google/gerrit/server/changedetail/DeleteDraftPatchSet.java deleted file mode 100644 index f5e08cc1b8..0000000000 --- a/gerrit-server/src/main/java/com/google/gerrit/server/changedetail/DeleteDraftPatchSet.java +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (C) 2011 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.server.changedetail; - -import com.google.gerrit.common.data.ReviewResult; -import com.google.gerrit.reviewdb.client.Change; -import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gerrit.reviewdb.server.ReviewDb; -import com.google.gerrit.server.ChangeUtil; -import com.google.gerrit.server.index.ChangeIndexer; -import com.google.gerrit.server.patch.PatchSetInfoFactory; -import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException; -import com.google.gerrit.server.project.ChangeControl; -import com.google.gerrit.server.project.NoSuchChangeException; -import com.google.gwtorm.server.OrmException; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; - -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Callable; - -public class DeleteDraftPatchSet implements Callable { - public interface Factory { - DeleteDraftPatchSet create(PatchSet.Id patchSetId); - } - - private final ChangeControl.Factory changeControlFactory; - private final ReviewDb db; - private final PatchSetInfoFactory patchSetInfoFactory; - private final ChangeUtil changeUtil; - private final PatchSet.Id patchSetId; - - @Inject - DeleteDraftPatchSet(ChangeControl.Factory changeControlFactory, - ReviewDb db, - PatchSetInfoFactory patchSetInfoFactory, - ChangeIndexer indexer, - ChangeUtil changeUtil, - @Assisted PatchSet.Id patchSetId) { - this.changeControlFactory = changeControlFactory; - this.db = db; - this.patchSetInfoFactory = patchSetInfoFactory; - this.changeUtil = changeUtil; - this.patchSetId = patchSetId; - } - - @Override - public ReviewResult call() throws NoSuchChangeException, OrmException { - ReviewResult result = new ReviewResult(); - - Change.Id changeId = patchSetId.getParentKey(); - result.setChangeId(changeId); - ChangeControl control = changeControlFactory.validateFor(changeId); - PatchSet patch = db.patchSets().get(patchSetId); - if (patch == null) { - throw new NoSuchChangeException(changeId); - } - if (!patch.isDraft()) { - result.addError(new ReviewResult.Error( - ReviewResult.Error.Type.NOT_A_DRAFT)); - return result; - } - - if (!control.canDeleteDraft(db)) { - result.addError(new ReviewResult.Error( - ReviewResult.Error.Type.DELETE_NOT_PERMITTED)); - return result; - } - Change change = control.getChange(); - - try { - changeUtil.deleteOnlyDraftPatchSet(patch, change); - } catch (IOException e) { - result.addError(new ReviewResult.Error( - ReviewResult.Error.Type.GIT_ERROR, e.getMessage())); - } - - List restOfPatches = db.patchSets().byChange(changeId).toList(); - if (restOfPatches.size() == 0) { - try { - changeUtil.deleteDraftChange(patchSetId); - result.setChangeId(null); - } catch (IOException e) { - result.addError(new ReviewResult.Error( - ReviewResult.Error.Type.GIT_ERROR, e.getMessage())); - } - } else { - PatchSet.Id highestId = null; - for (PatchSet ps : restOfPatches) { - if (highestId == null || ps.getPatchSetId() > highestId.get()) { - highestId = ps.getId(); - } - } - if (change.currentPatchSetId().equals(patchSetId)) { - try { - change.setCurrentPatchSet(patchSetInfoFactory.get(db, highestId)); - } catch (PatchSetInfoNotAvailableException e) { - throw new NoSuchChangeException(changeId); - } - db.changes().update(Collections.singleton(change)); - } - } - return result; - } -} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java index af14015a14..765ef1f7f6 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/GerritRequestModule.java @@ -18,7 +18,6 @@ import static com.google.inject.Scopes.SINGLETON; import com.google.gerrit.server.IdentifiedUser; import com.google.gerrit.server.RequestCleanup; -import com.google.gerrit.server.changedetail.DeleteDraftPatchSet; import com.google.gerrit.server.changedetail.PublishDraft; import com.google.gerrit.server.git.BanCommit; import com.google.gerrit.server.git.MergeOp; @@ -48,7 +47,6 @@ public class GerritRequestModule extends FactoryModule { // Not really per-request, but dammit, I don't know where else to // easily park this stuff. // - factory(DeleteDraftPatchSet.Factory.class); factory(PublishDraft.Factory.class); factory(RemoveReviewer.Factory.class); factory(SuggestParentCandidates.Factory.class);