Stay on change screen after deleting draft patch set

Change-Id: I47a4dcb0db20c97a31eabafbd5b2db8f397fd4f5
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2012-02-14 12:57:25 +01:00
parent 9b1d517a27
commit 33e3a82c32
4 changed files with 45 additions and 12 deletions

View File

@@ -44,8 +44,21 @@ public interface PatchDetailService extends RemoteJsonService {
@SignInRequired @SignInRequired
void deleteDraft(PatchLineComment.Key key, AsyncCallback<VoidResult> callback); 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</code> is passed as result to
* {@link AsyncCallback#onSuccess(Object)}
*/
@SignInRequired @SignInRequired
void deleteDraftPatchSet(PatchSet.Id psid, AsyncCallback<VoidResult> callback); void deleteDraftPatchSet(PatchSet.Id psid, AsyncCallback<ChangeDetail> callback);
@SignInRequired @SignInRequired
void publishComments(PatchSet.Id psid, String message, void publishComments(PatchSet.Id psid, String message,

View File

@@ -614,9 +614,13 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel implements O
public void onClick(final ClickEvent event) { public void onClick(final ClickEvent event) {
b.setEnabled(false); b.setEnabled(false);
PatchUtil.DETAIL_SVC.deleteDraftPatchSet(patchSet.getId(), PatchUtil.DETAIL_SVC.deleteDraftPatchSet(patchSet.getId(),
new GerritCallback<VoidResult>() { new GerritCallback<ChangeDetail>() {
public void onSuccess(VoidResult result) { public void onSuccess(final ChangeDetail result) {
Gerrit.display(PageLinks.MINE); if (result != null) {
changeScreen.update(result);
} else {
Gerrit.display(PageLinks.MINE);
}
} }
@Override @Override

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.httpd.rpc.patch; package com.google.gerrit.httpd.rpc.patch;
import com.google.gerrit.common.data.ChangeDetail;
import com.google.gerrit.common.data.ReviewerResult; import com.google.gerrit.common.data.ReviewerResult;
import com.google.gerrit.common.data.ReviewResult; import com.google.gerrit.common.data.ReviewResult;
import com.google.gerrit.common.data.ApprovalSummary; import com.google.gerrit.common.data.ApprovalSummary;
@@ -24,6 +25,7 @@ import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.common.errors.NoSuchEntityException; import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.httpd.rpc.BaseServiceImplementation; import com.google.gerrit.httpd.rpc.BaseServiceImplementation;
import com.google.gerrit.httpd.rpc.Handler; import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.httpd.rpc.changedetail.ChangeDetailFactory;
import com.google.gerrit.reviewdb.Account; import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.AccountDiffPreference; import com.google.gerrit.reviewdb.AccountDiffPreference;
import com.google.gerrit.reviewdb.AccountPatchReview; import com.google.gerrit.reviewdb.AccountPatchReview;
@@ -43,6 +45,7 @@ import com.google.gerrit.server.changedetail.DeleteDraftPatchSet;
import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.ReplicationQueue; import com.google.gerrit.server.git.ReplicationQueue;
import com.google.gerrit.server.patch.PatchSetInfoFactory; import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.patch.PublishComments; import com.google.gerrit.server.patch.PublishComments;
import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.NoSuchChangeException;
@@ -75,6 +78,7 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
private final PatchSetInfoFactory patchSetInfoFactory; private final PatchSetInfoFactory patchSetInfoFactory;
private final GitRepositoryManager gitManager; private final GitRepositoryManager gitManager;
private final ReplicationQueue replication; private final ReplicationQueue replication;
private final ChangeDetailFactory.Factory changeDetailFactory;
@Inject @Inject
PatchDetailServiceImpl(final Provider<ReviewDb> schema, PatchDetailServiceImpl(final Provider<ReviewDb> schema,
@@ -91,7 +95,8 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
final SaveDraft.Factory saveDraftFactory, final SaveDraft.Factory saveDraftFactory,
final PatchSetInfoFactory patchSetInfoFactory, final PatchSetInfoFactory patchSetInfoFactory,
final GitRepositoryManager gitManager, final GitRepositoryManager gitManager,
final ReplicationQueue replication) { final ReplicationQueue replication,
final ChangeDetailFactory.Factory changeDetailFactory) {
super(schema, currentUser); super(schema, currentUser);
this.approvalTypes = approvalTypes; this.approvalTypes = approvalTypes;
@@ -107,6 +112,7 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
this.patchSetInfoFactory = patchSetInfoFactory; this.patchSetInfoFactory = patchSetInfoFactory;
this.gitManager = gitManager; this.gitManager = gitManager;
this.replication = replication; this.replication = replication;
this.changeDetailFactory = changeDetailFactory;
} }
public void patchScript(final Patch.Key patchKey, final PatchSet.Id psa, public void patchScript(final Patch.Key patchKey, final PatchSet.Id psa,
@@ -152,19 +158,28 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
} }
public void deleteDraftPatchSet(final PatchSet.Id psid, public void deleteDraftPatchSet(final PatchSet.Id psid,
final AsyncCallback<VoidResult> callback) { final AsyncCallback<ChangeDetail> callback) {
run(callback, new Action<VoidResult>() { run(callback, new Action<ChangeDetail>() {
public VoidResult run(ReviewDb db) throws OrmException, Failure { public ChangeDetail run(ReviewDb db) throws OrmException, Failure {
ReviewResult result = null; ReviewResult result = null;
try { try {
result = deleteDraftPatchSetFactory.create(psid).call(); 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) { } catch (NoSuchChangeException e) {
throw new Failure(new NoSuchChangeException(result.getChangeId())); throw new Failure(new NoSuchChangeException(result.getChangeId()));
} catch (NoSuchEntityException e) {
throw new Failure(e);
} catch (PatchSetInfoNotAvailableException e) {
throw new Failure(e);
} }
if (result.getErrors().size() > 0) {
throw new Failure(new NoSuchEntityException());
}
return VoidResult.INSTANCE;
} }
}); });
} }

View File

@@ -98,6 +98,7 @@ public class DeleteDraftPatchSet implements Callable<ReviewResult> {
if (restOfPatches.size() == 0) { if (restOfPatches.size() == 0) {
try { try {
ChangeUtil.deleteDraftChange(patchSetId, gitManager, replication, db); ChangeUtil.deleteDraftChange(patchSetId, gitManager, replication, db);
result.setChangeId(null);
} catch (IOException e) { } catch (IOException e) {
result.addError(new ReviewResult.Error( result.addError(new ReviewResult.Error(
ReviewResult.Error.Type.GIT_ERROR, e.getMessage())); ReviewResult.Error.Type.GIT_ERROR, e.getMessage()));