in src/main/java/com/googlesource/gerrit/plugins/imagare/PutPreference.java [66:134]
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().get();
ProjectLevelConfig storage = projectCache.getAllProjects().getConfig(pluginName + ".config");
Config db = storage.get();
boolean modified = false;
String defaultProject = db.getString(PREFERENCE, username, KEY_DEFAULT_PROJECT);
if (Strings.emptyToNull(input.defaultProject) != null) {
if (projectCache.get(new Project.NameKey(input.defaultProject)) == null) {
throw new UnprocessableEntityException(
"project '" + input.defaultProject + "' does not exist");
}
if (!input.defaultProject.equals(defaultProject)) {
db.setString(PREFERENCE, username, KEY_DEFAULT_PROJECT, input.defaultProject);
modified = true;
}
} else {
if (defaultProject != null) {
db.unset(PREFERENCE, username, KEY_DEFAULT_PROJECT);
modified = true;
}
}
if (input.linkDecoration != null) {
LinkDecoration linkDecoration =
db.getEnum(PREFERENCE, username, KEY_LINK_DECORATION, LinkDecoration.NONE);
if (!input.linkDecoration.equals(linkDecoration)) {
db.setEnum(PREFERENCE, username, KEY_LINK_DECORATION, input.linkDecoration);
modified = true;
}
} else {
if (db.getNames(PREFERENCE, username).contains(KEY_LINK_DECORATION)) {
db.unset(PREFERENCE, username, KEY_LINK_DECORATION);
modified = true;
}
}
boolean stage = db.getBoolean(PREFERENCE, username, KEY_STAGE, false);
if (input.stage != null) {
if (input.stage != stage) {
db.setBoolean(PREFERENCE, username, KEY_STAGE, input.stage);
modified = true;
}
} else {
if (!stage) {
db.unset(PREFERENCE, username, KEY_STAGE);
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");
}