• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java BadRequestException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: apply

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
public Response<EmailInfo> apply(AccountResource rsrc, EmailInput input)
    throws AuthException, BadRequestException, ResourceConflictException,
        ResourceNotFoundException, OrmException, EmailException, MethodNotAllowedException,
        IOException, ConfigInvalidException, PermissionBackendException {
  if (self.get() != rsrc.getUser() || input.noConfirmation) {
    permissionBackend.user(self).check(GlobalPermission.MODIFY_ACCOUNT);
  }

  if (input == null) {
    input = new EmailInput();
  }

  if (!validator.isValid(email)) {
    throw new BadRequestException("invalid email address");
  }

  if (!realm.allowsEdit(AccountFieldName.REGISTER_NEW_EMAIL)) {
    throw new MethodNotAllowedException("realm does not allow adding emails");
  }

  return apply(rsrc.getUser(), input);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:24,代码来源:CreateEmail.java


示例17: cannotSetUnreviewedLabelForPatchSetThatAlreadyHasReviewedLabel

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

  setApiUser(user);
  gApi.changes().id(changeId).markAsReviewed(true);
  assertThat(gApi.changes().id(changeId).get().reviewed).isTrue();

  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.UNREVIEWED_LABEL + "/1")));
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:ChangeIT.java


示例18: apply

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
public Collection<String> apply(AccountResource.Star rsrc, StarsInput in)
    throws AuthException, BadRequestException, OrmException {
  if (self.get() != rsrc.getUser()) {
    throw new AuthException("not allowed to update stars of another account");
  }
  try {
    return starredChangesUtil.star(
        self.get().getAccountId(),
        rsrc.getChange().getProject(),
        rsrc.getChange().getId(),
        in.add,
        in.remove);
  } catch (IllegalLabelException e) {
    throw new BadRequestException(e.getMessage());
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:18,代码来源:Stars.java


示例19: apply

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
public BinaryResult apply(FileResource rsrc)
    throws ResourceNotFoundException, IOException, BadRequestException, OrmException {
  String path = rsrc.getPatchKey().get();
  if (Patch.COMMIT_MSG.equals(path)) {
    String msg = getMessage(rsrc.getRevision().getChangeResource().getNotes());
    return BinaryResult.create(msg)
        .setContentType(FileContentUtil.TEXT_X_GERRIT_COMMIT_MESSAGE)
        .base64();
  } else if (Patch.MERGE_LIST.equals(path)) {
    byte[] mergeList = getMergeList(rsrc.getRevision().getChangeResource().getNotes());
    return BinaryResult.create(mergeList)
        .setContentType(FileContentUtil.TEXT_X_GERRIT_MERGE_LIST)
        .base64();
  }
  return fileContentUtil.getContent(
      projectCache.checkedGet(rsrc.getRevision().getProject()),
      ObjectId.fromString(rsrc.getRevision().getPatchSet().getRevision().get()),
      path,
      parent);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:GetContent.java


示例20: apply

import com.google.gerrit.extensions.restapi.BadRequestException; //导入依赖的package包/类
@Override
public ConsistencyCheckInfo apply(ConfigResource resource, ConsistencyCheckInput input)
    throws RestApiException, IOException, OrmException, PermissionBackendException {
  permissionBackend.user(user).check(GlobalPermission.ACCESS_DATABASE);

  if (input == null || (input.checkAccounts == null && input.checkAccountExternalIds == null)) {
    throw new BadRequestException("input required");
  }

  ConsistencyCheckInfo consistencyCheckInfo = new ConsistencyCheckInfo();
  if (input.checkAccounts != null) {
    consistencyCheckInfo.checkAccountsResult =
        new CheckAccountsResultInfo(accountsConsistencyChecker.check());
  }
  if (input.checkAccountExternalIds != null) {
    consistencyCheckInfo.checkAccountExternalIdsResult =
        new CheckAccountExternalIdsResultInfo(externalIdsConsistencyChecker.check());
  }

  return consistencyCheckInfo;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:CheckConsistency.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DoubleLiteral类代码示例发布时间:2022-05-23
下一篇:
Java JetEngine类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap