Remove old deleteDraftPatchSet RPC
Change-Id: I89f4a6dd5307f40a7b1b58596ce111b5b7c51a0b
This commit is contained in:
@@ -40,21 +40,4 @@ public interface PatchDetailService extends RemoteJsonService {
|
|||||||
@Audit
|
@Audit
|
||||||
@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} is passed as result to
|
|
||||||
* {@link AsyncCallback#onSuccess(Object)}
|
|
||||||
*/
|
|
||||||
@Audit
|
|
||||||
@SignInRequired
|
|
||||||
void deleteDraftPatchSet(PatchSet.Id psid, AsyncCallback<ChangeDetail> callback);
|
|
||||||
}
|
}
|
||||||
|
@@ -629,16 +629,10 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(final ClickEvent event) {
|
public void onClick(final ClickEvent event) {
|
||||||
b.setEnabled(false);
|
b.setEnabled(false);
|
||||||
PatchUtil.DETAIL_SVC.deleteDraftPatchSet(patchSet.getId(),
|
final Change.Id id = patchSet.getId().getParentKey();
|
||||||
new ChangeDetailCache.GerritWidgetCallback(b) {
|
ChangeApi.deleteRevision(id.get(),
|
||||||
public void onSuccess(final ChangeDetail result) {
|
patchSet.getRevision().get(),
|
||||||
if (result != null) {
|
DraftActions.cs(id));
|
||||||
detailCache.set(result);
|
|
||||||
} else {
|
|
||||||
Gerrit.display(PageLinks.MINE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
actionsPanel.add(b);
|
actionsPanel.add(b);
|
||||||
|
@@ -14,10 +14,8 @@
|
|||||||
|
|
||||||
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.PatchDetailService;
|
import com.google.gerrit.common.data.PatchDetailService;
|
||||||
import com.google.gerrit.common.data.PatchScript;
|
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.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;
|
||||||
@@ -29,45 +27,33 @@ import com.google.gerrit.reviewdb.client.PatchLineComment;
|
|||||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
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.PatchScriptFactory;
|
||||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
|
||||||
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.NoSuchProjectException;
|
|
||||||
import com.google.gwtjsonrpc.common.AsyncCallback;
|
import com.google.gwtjsonrpc.common.AsyncCallback;
|
||||||
import com.google.gwtjsonrpc.common.VoidResult;
|
import com.google.gwtjsonrpc.common.VoidResult;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
|
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
class PatchDetailServiceImpl extends BaseServiceImplementation implements
|
class PatchDetailServiceImpl extends BaseServiceImplementation implements
|
||||||
PatchDetailService {
|
PatchDetailService {
|
||||||
private final DeleteDraftPatchSet.Factory deleteDraftPatchSetFactory;
|
|
||||||
private final PatchScriptFactory.Factory patchScriptFactoryFactory;
|
private final PatchScriptFactory.Factory patchScriptFactoryFactory;
|
||||||
private final SaveDraft.Factory saveDraftFactory;
|
private final SaveDraft.Factory saveDraftFactory;
|
||||||
private final ChangeDetailFactory.Factory changeDetailFactory;
|
|
||||||
private final ChangeControl.Factory changeControlFactory;
|
private final ChangeControl.Factory changeControlFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
PatchDetailServiceImpl(final Provider<ReviewDb> schema,
|
PatchDetailServiceImpl(final Provider<ReviewDb> schema,
|
||||||
final Provider<CurrentUser> currentUser,
|
final Provider<CurrentUser> currentUser,
|
||||||
final DeleteDraftPatchSet.Factory deleteDraftPatchSetFactory,
|
|
||||||
final PatchScriptFactory.Factory patchScriptFactoryFactory,
|
final PatchScriptFactory.Factory patchScriptFactoryFactory,
|
||||||
final SaveDraft.Factory saveDraftFactory,
|
final SaveDraft.Factory saveDraftFactory,
|
||||||
final ChangeDetailFactory.Factory changeDetailFactory,
|
final ChangeDetailFactory.Factory changeDetailFactory,
|
||||||
final ChangeControl.Factory changeControlFactory) {
|
final ChangeControl.Factory changeControlFactory) {
|
||||||
super(schema, currentUser);
|
super(schema, currentUser);
|
||||||
|
|
||||||
this.deleteDraftPatchSetFactory = deleteDraftPatchSetFactory;
|
|
||||||
this.patchScriptFactoryFactory = patchScriptFactoryFactory;
|
this.patchScriptFactoryFactory = patchScriptFactoryFactory;
|
||||||
this.saveDraftFactory = saveDraftFactory;
|
this.saveDraftFactory = saveDraftFactory;
|
||||||
this.changeDetailFactory = changeDetailFactory;
|
|
||||||
this.changeControlFactory = changeControlFactory;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -18,7 +18,6 @@ import static com.google.inject.Scopes.SINGLETON;
|
|||||||
|
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.RequestCleanup;
|
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.changedetail.PublishDraft;
|
||||||
import com.google.gerrit.server.git.BanCommit;
|
import com.google.gerrit.server.git.BanCommit;
|
||||||
import com.google.gerrit.server.git.MergeOp;
|
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
|
// Not really per-request, but dammit, I don't know where else to
|
||||||
// easily park this stuff.
|
// easily park this stuff.
|
||||||
//
|
//
|
||||||
factory(DeleteDraftPatchSet.Factory.class);
|
|
||||||
factory(PublishDraft.Factory.class);
|
factory(PublishDraft.Factory.class);
|
||||||
factory(RemoveReviewer.Factory.class);
|
factory(RemoveReviewer.Factory.class);
|
||||||
factory(SuggestParentCandidates.Factory.class);
|
factory(SuggestParentCandidates.Factory.class);
|
||||||
|
Reference in New Issue
Block a user