public Response apply()

in java/com/google/gerrit/plugins/checks/api/PostCheck.java [82:124]


  public Response<CheckInfo> apply(RevisionResource rsrc, CheckInput input)
      throws StorageException, IOException, RestApiException, PermissionBackendException,
          ConfigInvalidException {
    if (!self.get().isIdentifiedUser()) {
      throw new AuthException("Authentication required");
    }
    permissionBackend.currentUser().check(permission);

    if (rsrc.getEdit().isPresent()) {
      throw new ResourceConflictException("checks are not supported on a change edit");
    }

    if (input == null) {
      input = new CheckInput();
    }
    if (input.checkerUuid == null) {
      throw new BadRequestException("checker UUID is required");
    }
    if (!CheckerUuid.isUuid(input.checkerUuid)) {
      throw new BadRequestException(String.format("invalid checker UUID: %s", input.checkerUuid));
    }

    CheckerUuid checkerUuid = CheckerUuid.parse(input.checkerUuid);

    CheckKey key = CheckKey.create(rsrc.getProject(), rsrc.getPatchSet().id(), checkerUuid);
    Optional<Check> check = checks.getCheck(key, GetCheckOptions.defaults());
    Check updatedCheck;
    CheckUpdate checkUpdate = toCheckUpdate(input);
    if (!check.isPresent()) {
      checkers
          .getChecker(checkerUuid)
          .orElseThrow(
              () ->
                  new UnprocessableEntityException(
                      String.format("checker %s not found", checkerUuid)));
      updatedCheck =
          checksUpdate.get().createCheck(key, checkUpdate, input.notify, input.notifyDetails);
    } else {
      updatedCheck =
          checksUpdate.get().updateCheck(key, checkUpdate, input.notify, input.notifyDetails);
    }
    return Response.ok(checkJsonFactory.noOptions().format(updatedCheck));
  }