public Response apply()

in src/main/java/com/googlesource/gerrit/plugins/emoticons/PutPreference.java [62:99]


  public Response<String> apply(AccountResource rsrc, Input input)
      throws AuthException, RepositoryNotFoundException, IOException, UnprocessableEntityException,
          PermissionBackendException {
    if (self.get() != rsrc.getUser()) {
      permissionBackend.currentUser().check(ADMINISTRATE_SERVER);
    }
    if (input == null) {
      input = new Input();
    }

    String username = self.get().getUserName().orElse(null);

    ProjectLevelConfig storage = projectCache.getAllProjects().getConfig(pluginName + ".config");
    Config db = storage.get();
    boolean modified = false;

    boolean showEmoticons = db.getBoolean(PREFERENCE, username, KEY_SHOW_EMOTICONS, true);
    if (input.showEmoticons != null) {
      if (input.showEmoticons != showEmoticons) {
        db.setBoolean(PREFERENCE, username, KEY_SHOW_EMOTICONS, input.showEmoticons);
        modified = true;
      }
    } else {
      if (!showEmoticons) {
        db.unset(PREFERENCE, username, KEY_SHOW_EMOTICONS);
        modified = true;
      }
    }

    if (modified) {
      MetaDataUpdate md =
          metaDataUpdateFactory.create(projectCache.getAllProjects().getProject().getNameKey());
      md.setMessage("Update " + pluginName + " Preferences for '" + username + "'\n");
      storage.commit(md);
    }

    return Response.<String>ok("OK");
  }