public Response apply()

in src/main/java/com/googlesource/gerrit/plugins/serviceuser/PutEmail.java [75:113]


  public Response<?> apply(ServiceUserResource rsrc, Input input)
      throws ConfigInvalidException, EmailException, IOException, PermissionBackendException,
          RestApiException {
    Boolean emailAllowed;
    try {
      emailAllowed = getConfig.get().apply(new ConfigResource()).value().allowEmail;
    } catch (Exception e) {
      throw asRestApiException("Cannot get configuration", e);
    }
    if ((emailAllowed == null || !emailAllowed)) {
      permissionBackend.user(self.get()).check(ADMINISTRATE_SERVER);
    }

    String email;
    try {
      email = getEmail.get().apply(rsrc).value();
    } catch (Exception e) {
      throw asRestApiException("Cannot get email", e);
    }

    if (Strings.emptyToNull(input.email) == null) {
      if (Strings.emptyToNull(email) == null) {
        return Response.none();
      }
      return deleteEmail.get().apply(rsrc.getUser(), email);
    } else if (email != null && email.equals(input.email)) {
      return Response.ok(email);
    } else {
      if (email != null) {
        deleteEmail.get().apply(rsrc.getUser(), email);
      }
      EmailInput in = new EmailInput();
      in.email = input.email;
      in.noConfirmation = true;
      createEmail.get().apply(rsrc.getUser(), IdString.fromDecoded(in.email), in);
      putPreferred.get().apply(rsrc.getUser(), input.email);
      return Response.ok(input.email);
    }
  }