blob: 3aecb0c839190d0fca04c3ab4b3906a4dcfa4237 [file] [log] [blame]
// 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.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.AbandonChange;
import com.google.gerrit.server.mail.EmailException;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.InvalidChangeOperationException;
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 javax.annotation.Nullable;
class AbandonChangeHandler extends Handler<ChangeDetail> {
interface Factory {
AbandonChangeHandler create(PatchSet.Id patchSetId, String message);
}
private final AbandonChange.Factory abandonChangeFactory;
private final ChangeDetailFactory.Factory changeDetailFactory;
private final PatchSet.Id patchSetId;
@Nullable
private final String message;
@Inject
AbandonChangeHandler(final AbandonChange.Factory abandonChangeFactory,
final ChangeDetailFactory.Factory changeDetailFactory,
@Assisted final PatchSet.Id patchSetId,
@Assisted @Nullable final String message) {
this.abandonChangeFactory = abandonChangeFactory;
this.changeDetailFactory = changeDetailFactory;
this.patchSetId = patchSetId;
this.message = message;
}
@Override
public ChangeDetail call() throws NoSuchChangeException, OrmException,
EmailException, NoSuchEntityException, InvalidChangeOperationException,
PatchSetInfoNotAvailableException {
final ReviewResult result =
abandonChangeFactory.create(patchSetId, message).call();
if (result.getErrors().size() > 0) {
throw new NoSuchChangeException(result.getChangeId());
}
return changeDetailFactory.create(result.getChangeId()).call();
}
}