当前位置: 首页>>代码示例>>Java>>正文


Java BadRequestException类代码示例

本文整理汇总了Java中com.google.gerrit.extensions.restapi.BadRequestException的典型用法代码示例。如果您正苦于以下问题:Java BadRequestException类的具体用法?Java BadRequestException怎么用?Java BadRequestException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BadRequestException类属于com.google.gerrit.extensions.restapi包,在下文中一共展示了BadRequestException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readKeysToAdd

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
private List<PGPPublicKeyRing> readKeysToAdd(GpgKeysInput input, Set<Fingerprint> toRemove)
    throws BadRequestException, IOException {
  if (input.add == null || input.add.isEmpty()) {
    return ImmutableList.of();
  }
  List<PGPPublicKeyRing> keyRings = new ArrayList<>(input.add.size());
  for (String armored : input.add) {
    try (InputStream in = new ByteArrayInputStream(armored.getBytes(UTF_8));
        ArmoredInputStream ain = new ArmoredInputStream(in)) {
      @SuppressWarnings("unchecked")
      List<Object> objs = Lists.newArrayList(new BcPGPObjectFactory(ain));
      if (objs.size() != 1 || !(objs.get(0) instanceof PGPPublicKeyRing)) {
        throw new BadRequestException("Expected exactly one PUBLIC KEY BLOCK");
      }
      PGPPublicKeyRing keyRing = (PGPPublicKeyRing) objs.get(0);
      if (toRemove.contains(new Fingerprint(keyRing.getPublicKey().getFingerprint()))) {
        throw new BadRequestException(
            "Cannot both add and delete key: " + keyToString(keyRing.getPublicKey()));
      }
      keyRings.add(keyRing);
    } catch (PGPRuntimeOperationException e) {
      throw new BadRequestException("Failed to parse GPG keys", e);
    }
  }
  return keyRings;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:PostGpgKeys.java

示例2: applyImpl

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
protected Response<String> applyImpl(
    BatchUpdate.Factory updateFactory, ChangeResource req, TopicInput input)
    throws UpdateException, RestApiException, PermissionBackendException {
  req.permissions().check(ChangePermission.EDIT_TOPIC_NAME);

  if (input != null
      && input.topic != null
      && input.topic.length() > ChangeUtil.TOPIC_MAX_LENGTH) {
    throw new BadRequestException(
        String.format("topic length exceeds the limit (%s)", ChangeUtil.TOPIC_MAX_LENGTH));
  }

  Op op = new Op(input != null ? input : new TopicInput());
  try (BatchUpdate u =
      updateFactory.create(
          dbProvider.get(), req.getChange().getProject(), req.getUser(), TimeUtil.nowTs())) {
    u.addOp(req.getId(), op);
    u.execute();
  }
  return Strings.isNullOrEmpty(op.newTopicName) ? Response.none() : Response.ok(op.newTopicName);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:PutTopic.java

示例3: getContent

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
/**
 * Get the content of a file at a specific commit or one of it's parent commits.
 *
 * @param project A {@code Project} that this request refers to.
 * @param revstr An {@code ObjectId} specifying the commit.
 * @param path A string specifying the filepath.
 * @param parent A 1-based parent index to get the content from instead. Null if the content
 *     should be obtained from {@code revstr} instead.
 * @return Content of the file as {@code BinaryResult}.
 * @throws ResourceNotFoundException
 * @throws IOException
 */
public BinaryResult getContent(
    ProjectState project, ObjectId revstr, String path, @Nullable Integer parent)
    throws BadRequestException, ResourceNotFoundException, IOException {
  try (Repository repo = openRepository(project);
      RevWalk rw = new RevWalk(repo)) {
    if (parent != null) {
      RevCommit revCommit = rw.parseCommit(revstr);
      if (revCommit == null) {
        throw new ResourceNotFoundException("commit not found");
      }
      if (parent > revCommit.getParentCount()) {
        throw new BadRequestException("invalid parent");
      }
      revstr = rw.parseCommit(revstr).getParent(Integer.max(0, parent - 1)).toObjectId();
    }
    return getContent(repo, project, revstr, path);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:31,代码来源:FileContentUtil.java

示例4: apply

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
public Response<PluginInfo> apply(TopLevelResource resource, InstallPluginInput input)
    throws RestApiException, IOException {
  loader.checkRemoteAdminEnabled();
  try {
    try (InputStream in = openStream(input)) {
      String pluginName = loader.installPluginFromStream(name, in);
      PluginInfo info = ListPlugins.toPluginInfo(loader.get(pluginName));
      return created ? Response.created(info) : Response.ok(info);
    }
  } catch (PluginInstallException e) {
    StringWriter buf = new StringWriter();
    buf.write(String.format("cannot install %s", name));
    if (e.getCause() instanceof ZipException) {
      buf.write(": ");
      buf.write(e.getCause().getMessage());
    } else {
      buf.write(":\n");
      PrintWriter pw = new PrintWriter(buf);
      e.printStackTrace(pw);
      pw.flush();
    }
    throw new BadRequestException(buf.toString());
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:InstallPlugin.java

示例5: setParentName

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
public void setParentName(
    IdentifiedUser identifiedUser,
    ProjectConfig config,
    Project.NameKey projectName,
    Project.NameKey newParentProjectName,
    boolean checkAdmin)
    throws ResourceConflictException, AuthException, PermissionBackendException,
        BadRequestException {
  if (newParentProjectName != null
      && !config.getProject().getNameKey().equals(allProjects)
      && !config.getProject().getParent(allProjects).equals(newParentProjectName)) {
    try {
      setParent
          .get()
          .validateParentUpdate(
              projectName, identifiedUser, newParentProjectName.get(), checkAdmin);
    } catch (UnprocessableEntityException e) {
      throw new ResourceConflictException(e.getMessage(), e);
    }
    config.getProject().setParentName(newParentProjectName);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:SetAccessUtil.java

示例6: filter

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
public List<T> filter(List<T> refs) throws BadRequestException {
  if (!Strings.isNullOrEmpty(matchSubstring) && !Strings.isNullOrEmpty(matchRegex)) {
    throw new BadRequestException("specify exactly one of m/r");
  }
  FluentIterable<T> results = FluentIterable.from(refs);
  if (!Strings.isNullOrEmpty(matchSubstring)) {
    results = results.filter(new SubstringPredicate(matchSubstring));
  } else if (!Strings.isNullOrEmpty(matchRegex)) {
    results = results.filter(new RegexPredicate(matchRegex));
  }
  if (start > 0) {
    results = results.skip(start);
  }
  if (limit > 0) {
    results = results.limit(limit);
  }
  return results.toList();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:19,代码来源:RefFilter.java

示例7: ensureRangeIsValid

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
private static void ensureRangeIsValid(String commentPath, Range range)
    throws BadRequestException {
  if (range == null) {
    return;
  }
  if (!range.isValid()) {
    throw new BadRequestException(
        String.format(
            "Range (%s:%s - %s:%s) is not valid for the comment on %s",
            range.startLine,
            range.startCharacter,
            range.endLine,
            range.endCharacter,
            commentPath));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:PostReview.java

示例8: normalizeTagRef

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
public static String normalizeTagRef(String tag) throws BadRequestException {
  String result = tag;
  while (result.startsWith("/")) {
    result = result.substring(1);
  }
  if (result.startsWith(R_REFS) && !result.startsWith(R_TAGS)) {
    throw new BadRequestException("invalid tag name \"" + result + "\"");
  }
  if (!result.startsWith(R_TAGS)) {
    result = R_TAGS + result;
  }
  if (!Repository.isValidRefName(result)) {
    throw new BadRequestException("invalid tag name \"" + result + "\"");
  }
  return result;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:RefUtil.java

示例9: cannotSetReviewedLabelForPatchSetThatAlreadyHasUnreviewedLabel

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Test
public void cannotSetReviewedLabelForPatchSetThatAlreadyHasUnreviewedLabel() throws Exception {
  String changeId = createChange().getChangeId();

  setApiUser(user);
  gApi.changes().id(changeId).markAsReviewed(false);
  assertThat(gApi.changes().id(changeId).get().reviewed).isNull();

  exception.expect(BadRequestException.class);
  exception.expectMessage(
      "The labels "
          + StarredChangesUtil.REVIEWED_LABEL
          + "/"
          + 1
          + " and "
          + StarredChangesUtil.UNREVIEWED_LABEL
          + "/"
          + 1
          + " are mutually exclusive. Only one of them can be set.");
  gApi.accounts()
      .self()
      .setStars(
          changeId, new StarsInput(ImmutableSet.of(StarredChangesUtil.REVIEWED_LABEL + "/1")));
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:ChangeIT.java

示例10: apply

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
public Object apply(ChangeResource rsrc, Input input)
    throws AuthException, IOException, BadRequestException, ResourceConflictException,
        OrmException, PermissionBackendException {
  if (input == null || Strings.isNullOrEmpty(input.message)) {
    throw new BadRequestException("commit message must be provided");
  }

  Project.NameKey project = rsrc.getProject();
  try (Repository repository = repositoryManager.openRepository(project)) {
    editModifier.modifyMessage(repository, rsrc.getNotes(), input.message);
  } catch (UnchangedCommitMessageException e) {
    throw new ResourceConflictException(e.getMessage());
  }

  return Response.none();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:ChangeEdits.java

示例11: create

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
public ProjectApi create(ProjectInput in) throws RestApiException {
  try {
    if (name == null) {
      throw new ResourceConflictException("Project already exists");
    }
    if (in.name != null && !name.equals(in.name)) {
      throw new BadRequestException("name must match input.name");
    }
    CreateProject impl = createProjectFactory.create(name);
    permissionBackend.user(user).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
    impl.apply(TopLevelResource.INSTANCE, in);
    return projectApi.create(projects.parse(name));
  } catch (Exception e) {
    throw asRestApiException("Cannot create project: " + e.getMessage(), e);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:ProjectApiImpl.java

示例12: cherryPickMergeUsingNonExistentParent

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Test
public void cherryPickMergeUsingNonExistentParent() throws Exception {
  String parent1FileName = "a.txt";
  String parent2FileName = "b.txt";
  PushOneCommit.Result mergeChangeResult =
      createCherryPickableMerge(parent1FileName, parent2FileName);

  String cherryPickBranchName = "branch_for_cherry_pick";
  createBranch(new Branch.NameKey(project, cherryPickBranchName));

  CherryPickInput cherryPickInput = new CherryPickInput();
  cherryPickInput.destination = cherryPickBranchName;
  cherryPickInput.message = "Cherry-pick a merge commit to another branch";
  cherryPickInput.parent = 3;

  exception.expect(BadRequestException.class);
  exception.expectMessage(
      "Cherry Pick: Parent 3 does not exist. Please specify a parent in range [1, 2].");
  gApi.changes().id(mergeChangeResult.getChangeId()).current().cherryPick(cherryPickInput);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:RevisionIT.java

示例13: convertFormToJson

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Test
public void convertFormToJson() throws BadRequestException {
  JsonObject obj =
      ParameterParser.formToJson(
          ImmutableMap.of(
              "message", new String[] {"this.is.text"},
              "labels.Verified", new String[] {"-1"},
              "labels.Code-Review", new String[] {"2"},
              "a_list", new String[] {"a", "b"}),
          ImmutableSet.of("q"));

  JsonObject labels = new JsonObject();
  labels.addProperty("Verified", "-1");
  labels.addProperty("Code-Review", "2");
  JsonArray list = new JsonArray();
  list.add(new JsonPrimitive("a"));
  list.add(new JsonPrimitive("b"));
  JsonObject exp = new JsonObject();
  exp.addProperty("message", "this.is.text");
  exp.add("labels", labels);
  exp.add("a_list", list);

  assertEquals(exp, obj);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:ParameterParserTest.java

示例14: suggestGroups

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
private List<GroupInfo> suggestGroups() throws OrmException, BadRequestException {
  if (conflictingSuggestParameters()) {
    throw new BadRequestException(
        "You should only have no more than one --project and -n with --suggest");
  }
  List<GroupReference> groupRefs =
      Lists.newArrayList(
          Iterables.limit(
              groupBackend.suggest(suggest, projects.stream().findFirst().orElse(null)),
              limit <= 0 ? 10 : Math.min(limit, 10)));

  List<GroupInfo> groupInfos = Lists.newArrayListWithCapacity(groupRefs.size());
  for (GroupReference ref : groupRefs) {
    GroupDescription.Basic desc = groupBackend.get(ref.getUUID());
    if (desc != null) {
      groupInfos.add(json.addOptions(options).format(desc));
    }
  }
  return groupInfos;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:ListGroups.java

示例15: apply

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
public String apply(GroupResource rsrc, NameInput input)
    throws MethodNotAllowedException, AuthException, BadRequestException,
        ResourceConflictException, ResourceNotFoundException, OrmException, IOException,
        ConfigInvalidException {
  GroupDescription.Internal internalGroup =
      rsrc.asInternalGroup().orElseThrow(MethodNotAllowedException::new);
  if (!rsrc.getControl().isOwner()) {
    throw new AuthException("Not group owner");
  } else if (input == null || Strings.isNullOrEmpty(input.name)) {
    throw new BadRequestException("name is required");
  }
  String newName = input.name.trim();
  if (newName.isEmpty()) {
    throw new BadRequestException("name is required");
  }

  if (internalGroup.getName().equals(newName)) {
    return newName;
  }

  renameGroup(internalGroup, newName);
  return newName;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:PutName.java


注:本文中的com.google.gerrit.extensions.restapi.BadRequestException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。