com.google.gerrit.server.restapi.change.SubmittedTogether Maven / Gradle / Ivy
// Copyright (C) 2015 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.restapi.change;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.NON_VISIBLE_CHANGES;
import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.TOPIC_CLOSURE;
import static java.util.Collections.reverseOrder;
import com.google.common.collect.ImmutableList;
import com.google.common.flogger.FluentLogger;
import com.google.gerrit.entities.Change;
import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.api.changes.SubmittedTogetherInfo;
import com.google.gerrit.extensions.api.changes.SubmittedTogetherOption;
import com.google.gerrit.extensions.client.ListChangesOption;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.change.ChangeJson;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.WalkSorter;
import com.google.gerrit.server.change.WalkSorter.PatchSetData;
import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.submit.ChangeSet;
import com.google.gerrit.server.submit.MergeSuperSet;
import com.google.inject.Inject;
import com.google.inject.Provider;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import org.kohsuke.args4j.Option;
public class SubmittedTogether implements RestReadView {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final EnumSet options =
EnumSet.noneOf(SubmittedTogetherOption.class);
private final EnumSet jsonOpt =
EnumSet.of(ListChangesOption.CURRENT_REVISION, ListChangesOption.SUBMITTABLE);
private static final Comparator COMPARATOR =
Comparator.comparing(ChangeData::project)
.thenComparing(cd -> cd.getId().get(), reverseOrder());
private final ChangeJson.Factory json;
private final Provider queryProvider;
private final Provider mergeSuperSet;
private final Provider sorter;
@Option(name = "-o", usage = "Output options")
void addOption(String option) {
for (ListChangesOption o : ListChangesOption.values()) {
if (o.name().equalsIgnoreCase(option)) {
jsonOpt.add(o);
return;
}
}
for (SubmittedTogetherOption o : SubmittedTogetherOption.values()) {
if (o.name().equalsIgnoreCase(option)) {
options.add(o);
return;
}
}
throw new IllegalArgumentException("option not recognized: " + option);
}
@Inject
SubmittedTogether(
ChangeJson.Factory json,
Provider queryProvider,
Provider mergeSuperSet,
Provider sorter) {
this.json = json;
this.queryProvider = queryProvider;
this.mergeSuperSet = mergeSuperSet;
this.sorter = sorter;
}
public SubmittedTogether addListChangesOption(Set o) {
jsonOpt.addAll(o);
return this;
}
public SubmittedTogether addSubmittedTogetherOption(Set o) {
options.addAll(o);
return this;
}
@Override
public Response