Merge changes I89f4a6dd,Ieb55dd1c,I23d2b007,I77f1cb57,Ic25c5d68

* changes:
  Remove old deleteDraftPatchSet RPC
  Remove old rebaseChange RPC
  Remove old publish RPC
  Remove old DeleteDraftChange RPC
  Remove old EditCommitMessage RPC
This commit is contained in:
Shawn Pearce
2013-12-07 01:54:32 +00:00
committed by Gerrit Code Review
16 changed files with 54 additions and 636 deletions

View File

@@ -1,44 +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.VoidResult;
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<ChangeDetail> callback);
@Audit
@SignInRequired
void publish(PatchSet.Id patchSetId, AsyncCallback<ChangeDetail> callback);
@Audit
@SignInRequired
void deleteDraftChange(PatchSet.Id patchSetId, AsyncCallback<VoidResult> callback);
@Audit
@SignInRequired
void rebaseChange(PatchSet.Id patchSetId, AsyncCallback<ChangeDetail> callback);
}

View File

@@ -40,21 +40,4 @@ public interface PatchDetailService extends RemoteJsonService {
@Audit
@SignInRequired
void deleteDraft(PatchLineComment.Key key, AsyncCallback<VoidResult> 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<ChangeDetail> callback);
}

View File

@@ -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<JavaScriptObject> cs(
public static GerritCallback<JavaScriptObject> cs(
final Change.Id id) {
return new GerritCallback<JavaScriptObject>() {
public void onSuccess(JavaScriptObject result) {

View File

@@ -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);
}
}

View File

@@ -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<ChangeDetail> {
private abstract class CommitMessageEditDialog
extends CommentedActionDialog<JavaScriptObject> {
private final String originalMessage;
public CommitMessageEditDialog(final String title, final String heading,
final String commitMessage, AsyncCallback<ChangeDetail> callback) {
final String commitMessage, AsyncCallback<JavaScriptObject> 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<JavaScriptObject>() {
@Override
public void onSuccess(JavaScriptObject result) {}
}) {
@Override
public void onSend() {
Util.MANAGE_SVC.createNewPatchSet(patchSetId, getMessageText(),
new AsyncCallback<ChangeDetail>() {
@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<JavaScriptObject>() {
@Override
public void onSuccess(JavaScriptObject msg) {
Gerrit.display(PageLinks.toChange(changeId));
hide();
}
});
}
}.center();
}

View File

@@ -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;
@@ -55,7 +56,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 +479,22 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
@Override
public void onClick(final ClickEvent event) {
b.setEnabled(false);
Util.MANAGE_SVC.deleteDraftChange(patchSet.getId(),
new GerritCallback<VoidResult>() {
public void onSuccess(VoidResult result) {
Gerrit.display(PageLinks.MINE);
}
ChangeApi.deleteChange(patchSet.getId().getParentKey().get(),
new GerritCallback<JavaScriptObject>() {
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);
@@ -539,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<ChangeInfo>() {
public void onSuccess(ChangeInfo result) {
Gerrit.display(PageLinks.toChange(id));
}
});
}
});
actionsPanel.add(b);
@@ -605,8 +614,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);
@@ -618,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);

View File

@@ -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) {

View File

@@ -1,62 +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.gerrit.reviewdb.client.PatchSet.Id;
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;
private final EditCommitMessageHandler.Factory editCommitMessageHandlerFactory;
@Inject
ChangeManageServiceImpl(
final RebaseChangeHandler.Factory rebaseChangeFactory,
final PublishAction.Factory publishAction,
final DeleteDraftChange.Factory deleteDraftChangeFactory,
final EditCommitMessageHandler.Factory editCommitMessageHandler) {
this.rebaseChangeFactory = rebaseChangeFactory;
this.publishAction = publishAction;
this.deleteDraftChangeFactory = deleteDraftChangeFactory;
this.editCommitMessageHandlerFactory = editCommitMessageHandler;
}
public void rebaseChange(final PatchSet.Id patchSetId,
final AsyncCallback<ChangeDetail> callback) {
rebaseChangeFactory.create(patchSetId).to(callback);
}
public void publish(final PatchSet.Id patchSetId,
final AsyncCallback<ChangeDetail> callback) {
publishAction.create(patchSetId).to(callback);
}
public void deleteDraftChange(final PatchSet.Id patchSetId,
final AsyncCallback<VoidResult> callback) {
deleteDraftChangeFactory.create(patchSetId).to(callback);
}
public void createNewPatchSet(Id patchSetId, String message,
AsyncCallback<ChangeDetail> callback) {
editCommitMessageHandlerFactory.create(patchSetId, message).to(callback);
}
}

View File

@@ -28,17 +28,12 @@ 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);
factory(PatchSetDetailFactory.Factory.class);
factory(PatchSetPublishDetailFactory.Factory.class);
factory(PublishAction.Factory.class);
factory(DeleteDraftChange.Factory.class);
}
});
rpc(ChangeDetailServiceImpl.class);
rpc(ChangeManageServiceImpl.class);
}
}

View File

@@ -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<VoidResult> {
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;
}
}

View File

@@ -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<ChangeDetail> {
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();
}
}

View File

@@ -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<ChangeDetail> {
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();
}
}

View File

@@ -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<ChangeDetail> {
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();
}
}

View File

@@ -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<ReviewDb> schema,
final Provider<CurrentUser> 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<ChangeDetail> callback) {
run(callback, new Action<ChangeDetail>() {
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);
}
}
});
}
}

View File

@@ -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<ReviewResult> {
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<PatchSet> 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;
}
}

View File

@@ -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);