Files
gerrit/java/com/google/gerrit/server/restapi/config/GetPreferences.java
Edwin Kempin 1b7bac945c Allow to update accounts and general preferences atomically
AccountsUpdate now also supports to update general preferences. This
means account properties and general preferences can now be updated in
the same transaction.

Reading and writing general preferences is now done via AccountConfig.
On load we always read the preferences.config file, but parsing it is
done lazily when the general preferences are accessed for the first
time. Most callers that load accounts are not interested in general
preferences and this avoids unneeded parsing effort for them.

PreferencesConfig encapsules all details about parsing and storing
general preferences and also provides means to read and update the
default general preferences.

Change-Id: Ic0f2adfe4e96311af0c5bfa061fc7c0ca60d91fa
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-01-09 09:31:27 +01:00

48 lines
1.8 KiB
Java

// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.restapi.config;
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.account.PreferencesConfig;
import com.google.gerrit.server.config.AllUsersName;
import com.google.gerrit.server.config.ConfigResource;
import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Repository;
@Singleton
public class GetPreferences implements RestReadView<ConfigResource> {
private final GitRepositoryManager gitMgr;
private final AllUsersName allUsersName;
@Inject
public GetPreferences(GitRepositoryManager gitMgr, AllUsersName allUsersName) {
this.gitMgr = gitMgr;
this.allUsersName = allUsersName;
}
@Override
public GeneralPreferencesInfo apply(ConfigResource rsrc)
throws IOException, ConfigInvalidException {
try (Repository git = gitMgr.openRepository(allUsersName)) {
return PreferencesConfig.readDefaultPreferences(git);
}
}
}