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

Java Response类代码示例

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

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



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

示例1: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<?> apply(RevisionResource revision, VerifyInput input)
    throws AuthException, BadRequestException, UnprocessableEntityException,
    OrmException, IOException {
  if (input.verifications == null) {
    throw new BadRequestException("Missing verifications field");
  }

  try (CiDb db = schemaFactory.open()) {
    // Only needed for Google Megastore (that we don't use yet)
    db.patchSetVerifications().beginTransaction(null);
    boolean dirty = false;
    try {
      dirty |= updateLabels(revision, db, input.verifications);
      if (dirty) {
        db.commit();
      }
    } finally {
      db.rollback();
    }
  }
  return Response.none();
}
 
开发者ID:davido,项目名称:gerrit-ci-plugin,代码行数:24,代码来源:PostVerification.java


示例2: applyAsync

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
private Response.Accepted applyAsync(Project.NameKey project, Input input) {
  Runnable job =
      new Runnable() {
        @Override
        public void run() {
          runGC(project, input, null);
        }

        @Override
        public String toString() {
          return "Run "
              + (input.aggressive ? "aggressive " : "")
              + "garbage collection on project "
              + project.get();
        }
      };

  @SuppressWarnings("unchecked")
  WorkQueue.Task<Void> task = (WorkQueue.Task<Void>) workQueue.getDefaultQueue().submit(job);

  String location =
      canonicalUrl.get() + "a/config/server/tasks/" + IdGenerator.format(task.getTaskId());

  return Response.accepted(location);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:GarbageCollect.java


示例3: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的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


示例4: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<?> apply(GroupResource rsrc, Input input)
    throws IOException, AuthException, UnprocessableEntityException {
  if (!rsrc.getControl().isOwner()) {
    throw new AuthException("not allowed to index group");
  }

  AccountGroup.UUID groupUuid = rsrc.getGroup().getGroupUUID();
  if (!rsrc.isInternalGroup()) {
    throw new UnprocessableEntityException(
        String.format("External Group Not Allowed: %s", groupUuid.get()));
  }

  Optional<InternalGroup> group = groupCache.get(groupUuid);
  // evicting the group from the cache, reindexes the group
  if (group.isPresent()) {
    groupCache.evict(group.get().getGroupUUID(), group.get().getId(), group.get().getNameKey());
  }
  return Response.none();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:Index.java


示例5: apply

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

  if (input == null) {
    input = new HttpPasswordInput();
  }
  input.httpPassword = Strings.emptyToNull(input.httpPassword);

  String newPassword;
  if (input.generate) {
    newPassword = generate();
  } else if (input.httpPassword == null) {
    newPassword = null;
  } else {
    // Only administrators can explicitly set the password.
    permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
    newPassword = input.httpPassword;
  }
  return apply(rsrc.getUser(), newPassword);
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:PutHttpPassword.java


示例6: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<String> apply(IdentifiedUser user, String email)
    throws ResourceNotFoundException, IOException, ConfigInvalidException {
  AtomicBoolean alreadyPreferred = new AtomicBoolean(false);
  Account account =
      accountsUpdate
          .create()
          .update(
              user.getAccountId(),
              a -> {
                if (email.equals(a.getPreferredEmail())) {
                  alreadyPreferred.set(true);
                } else {
                  a.setPreferredEmail(email);
                }
              });
  if (account == null) {
    throw new ResourceNotFoundException("account not found");
  }
  return alreadyPreferred.get() ? Response.ok("") : Response.created("");
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:PutPreferred.java


示例7: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的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


示例8: deactivate

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<?> deactivate(Account.Id accountId)
    throws RestApiException, IOException, ConfigInvalidException {
  AtomicBoolean alreadyInactive = new AtomicBoolean(false);
  Account account =
      accountsUpdate
          .create()
          .update(
              accountId,
              a -> {
                if (!a.isActive()) {
                  alreadyInactive.set(true);
                } else {
                  a.setActive(false);
                }
              });
  if (account == null) {
    throw new ResourceNotFoundException("account not found");
  }
  if (alreadyInactive.get()) {
    throw new ResourceConflictException("account not active");
  }
  return Response.none();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:24,代码来源:SetInactiveFlag.java


示例9: activate

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<String> activate(Account.Id accountId)
    throws ResourceNotFoundException, IOException, ConfigInvalidException {
  AtomicBoolean alreadyActive = new AtomicBoolean(false);
  Account account =
      accountsUpdate
          .create()
          .update(
              accountId,
              a -> {
                if (a.isActive()) {
                  alreadyActive.set(true);
                } else {
                  a.setActive(true);
                }
              });
  if (account == null) {
    throw new ResourceNotFoundException("account not found");
  }
  return alreadyActive.get() ? Response.ok("") : Response.created("");
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:21,代码来源:SetInactiveFlag.java


示例10: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<String> apply(IdentifiedUser user, NameInput input)
    throws MethodNotAllowedException, ResourceNotFoundException, IOException,
        ConfigInvalidException {
  if (input == null) {
    input = new NameInput();
  }

  if (!realm.allowsEdit(AccountFieldName.FULL_NAME)) {
    throw new MethodNotAllowedException("realm does not allow editing name");
  }

  String newName = input.name;
  Account account =
      accountsUpdate.create().update(user.getAccountId(), a -> a.setFullName(newName));
  if (account == null) {
    throw new ResourceNotFoundException("account not found");
  }
  return Strings.isNullOrEmpty(account.getFullName())
      ? Response.none()
      : Response.ok(account.getFullName());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:22,代码来源:PutName.java


示例11: applyImpl

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
protected Response<?> applyImpl(
    BatchUpdate.Factory updateFactory, ChangeResource rsrc, PublishChangeEditInput in)
    throws IOException, OrmException, RestApiException, UpdateException, ConfigInvalidException,
        NoSuchProjectException {
  contributorAgreementsChecker.check(rsrc.getProject(), rsrc.getUser());
  Optional<ChangeEdit> edit = editUtil.byChange(rsrc.getNotes(), rsrc.getUser());
  if (!edit.isPresent()) {
    throw new ResourceConflictException(
        String.format("no edit exists for change %s", rsrc.getChange().getChangeId()));
  }
  if (in == null) {
    in = new PublishChangeEditInput();
  }
  editUtil.publish(
      updateFactory,
      rsrc.getNotes(),
      rsrc.getUser(),
      edit.get(),
      in.notify,
      notifyUtil.resolveAccounts(in.notifyDetails));
  return Response.none();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:24,代码来源:PublishChangeEdit.java


示例12: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Response<String> apply(IdentifiedUser user, StatusInput input)
    throws ResourceNotFoundException, IOException, ConfigInvalidException {
  if (input == null) {
    input = new StatusInput();
  }

  String newStatus = input.status;
  Account account =
      accountsUpdate
          .create()
          .update(user.getAccountId(), a -> a.setStatus(Strings.nullToEmpty(newStatus)));
  if (account == null) {
    throw new ResourceNotFoundException("account not found");
  }
  return Strings.isNullOrEmpty(account.getStatus())
      ? Response.none()
      : Response.ok(account.getStatus());
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:19,代码来源:PutStatus.java


示例13: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<?> apply(AccountResource rsrc, List<ProjectWatchInfo> input)
    throws AuthException, UnprocessableEntityException, OrmException, IOException,
        ConfigInvalidException, PermissionBackendException {
  if (self.get() != rsrc.getUser()) {
    permissionBackend.user(self).check(GlobalPermission.ADMINISTRATE_SERVER);
  }
  if (input == null) {
    return Response.none();
  }

  Account.Id accountId = rsrc.getUser().getAccountId();
  watchConfig.deleteProjectWatches(
      accountId,
      input
          .stream()
          .filter(Objects::nonNull)
          .map(w -> ProjectWatchKey.create(new Project.NameKey(w.project), w.filter))
          .collect(toList()));
  accountCache.evict(accountId);
  return Response.none();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:DeleteWatchedProjects.java


示例14: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<String> apply(ConfigResource rsrc, Input input)
    throws AuthException, BadRequestException, UnprocessableEntityException,
        PermissionBackendException {
  if (input == null || input.operation == null) {
    throw new BadRequestException("operation must be specified");
  }

  switch (input.operation) {
    case FLUSH_ALL:
      if (input.caches != null) {
        throw new BadRequestException(
            "specifying caches is not allowed for operation 'FLUSH_ALL'");
      }
      flushAll();
      return Response.ok("");
    case FLUSH:
      if (input.caches == null || input.caches.isEmpty()) {
        throw new BadRequestException("caches must be specified for operation 'FLUSH'");
      }
      flush(input.caches);
      return Response.ok("");
    default:
      throw new BadRequestException("unsupported operation: " + input.operation);
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:27,代码来源:PostCaches.java


示例15: importAccount

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
public Account.Id importAccount(String login, String name, String email)
    throws IOException, BadRequestException, ResourceConflictException,
        UnprocessableEntityException, OrmException, ConfigInvalidException {
  CreateAccount createAccount = createAccountFactory.create(login);
  AccountInput accountInput = new AccountInput();
  accountInput.email = email;
  accountInput.username = login;
  accountInput.name = MoreObjects.firstNonNull(name, login);
  Response<AccountInfo> accountResponse =
      createAccount.apply(TopLevelResource.INSTANCE, accountInput);
  if (accountResponse.statusCode() != HttpStatus.SC_CREATED) {
    throw new IOException(
        "Cannot import GitHub account "
            + login
            + ": HTTP Status "
            + accountResponse.statusCode());
  }
  Id accountId = new Account.Id(accountResponse.value()._accountId.intValue());
  externalIdsUpdateServer
      .create()
      .insert(ExternalId.create(ExternalId.SCHEME_GERRIT, login, accountId));
  return accountId;
}
 
开发者ID:GerritCodeReview,项目名称:plugins_github,代码行数:24,代码来源:AccountImporter.java


示例16: applyImpl

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
protected Response<CommentInfo> applyImpl(
    BatchUpdate.Factory updateFactory, DraftCommentResource rsrc, DraftInput in)
    throws RestApiException, UpdateException, OrmException {
  if (in == null || in.message == null || in.message.trim().isEmpty()) {
    return delete.applyImpl(updateFactory, rsrc, null);
  } else if (in.id != null && !rsrc.getId().equals(in.id)) {
    throw new BadRequestException("id must match URL");
  } else if (in.line != null && in.line < 0) {
    throw new BadRequestException("line must be >= 0");
  } else if (in.line != null && in.range != null && in.line != in.range.endLine) {
    throw new BadRequestException("range endLine must be on the same line as the comment");
  }

  try (BatchUpdate bu =
      updateFactory.create(
          db.get(), rsrc.getChange().getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
    Op op = new Op(rsrc.getComment().key, in);
    bu.addOp(rsrc.getChange().getId(), op);
    bu.execute();
    return Response.ok(
        commentJson.get().setFillAccounts(false).newCommentFormatter().format(op.comment));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:25,代码来源:PutDraftComment.java


示例17: applyImpl

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
protected Response<CommentInfo> applyImpl(
    BatchUpdate.Factory updateFactory, RevisionResource rsrc, DraftInput in)
    throws RestApiException, UpdateException, OrmException {
  if (Strings.isNullOrEmpty(in.path)) {
    throw new BadRequestException("path must be non-empty");
  } else if (in.message == null || in.message.trim().isEmpty()) {
    throw new BadRequestException("message must be non-empty");
  } else if (in.line != null && in.line < 0) {
    throw new BadRequestException("line must be >= 0");
  } else if (in.line != null && in.range != null && in.line != in.range.endLine) {
    throw new BadRequestException("range endLine must be on the same line as the comment");
  }

  try (BatchUpdate bu =
      updateFactory.create(db.get(), rsrc.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
    Op op = new Op(rsrc.getPatchSet().getId(), in);
    bu.addOp(rsrc.getChange().getId(), op);
    bu.execute();
    return Response.created(
        commentJson.get().setFillAccounts(false).newCommentFormatter().format(op.comment));
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:24,代码来源:CreateDraftComment.java


示例18: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<EditInfo> apply(FixResource fixResource, Void nothing)
    throws AuthException, OrmException, ResourceConflictException, IOException,
        ResourceNotFoundException, PermissionBackendException {
  RevisionResource revisionResource = fixResource.getRevisionResource();
  Project.NameKey project = revisionResource.getProject();
  ProjectState projectState = projectCache.checkedGet(project);
  PatchSet patchSet = revisionResource.getPatchSet();
  ObjectId patchSetCommitId = ObjectId.fromString(patchSet.getRevision().get());

  try (Repository repository = gitRepositoryManager.openRepository(project)) {
    List<TreeModification> treeModifications =
        fixReplacementInterpreter.toTreeModifications(
            repository, projectState, patchSetCommitId, fixResource.getFixReplacements());
    ChangeEdit changeEdit =
        changeEditModifier.combineWithModifiedPatchSetTree(
            repository, revisionResource.getNotes(), patchSet, treeModifications);
    return Response.ok(changeEditJson.toEditInfo(changeEdit, false));
  } catch (InvalidChangeOperationException e) {
    throw new ResourceConflictException(e.getMessage());
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:23,代码来源:ApplyFix.java


示例19: applyImpl

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
protected Response<?> applyImpl(
    BatchUpdate.Factory updateFactory, ChangeResource rsrc, Input input)
    throws RestApiException, UpdateException, PermissionBackendException {
  if (rsrc.getChange().getStatus() == Change.Status.MERGED) {
    throw new MethodNotAllowedException("delete not permitted");
  }
  rsrc.permissions().database(db).check(ChangePermission.DELETE);

  try (BatchUpdate bu =
      updateFactory.create(db.get(), rsrc.getProject(), rsrc.getUser(), TimeUtil.nowTs())) {
    Change.Id id = rsrc.getChange().getId();
    bu.setOrder(Order.DB_BEFORE_REPO);
    bu.addOp(id, opProvider.get());
    bu.execute();
  }
  return Response.none();
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:19,代码来源:DeleteChange.java


示例20: apply

import com.google.gerrit.extensions.restapi.Response; //导入依赖的package包/类
@Override
public Response<CommitInfo> apply(RevisionResource rsrc) throws IOException {
  Project.NameKey p = rsrc.getChange().getProject();
  try (Repository repo = repoManager.openRepository(p);
      RevWalk rw = new RevWalk(repo)) {
    String rev = rsrc.getPatchSet().getRevision().get();
    RevCommit commit = rw.parseCommit(ObjectId.fromString(rev));
    rw.parseBody(commit);
    CommitInfo info = json.noOptions().toCommit(rsrc.getProject(), rw, commit, addLinks, true);
    Response<CommitInfo> r = Response.ok(info);
    if (rsrc.isCacheable()) {
      r.caching(CacheControl.PRIVATE(7, TimeUnit.DAYS));
    }
    return r;
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:17,代码来源:GetCommit.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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