File was renamed from src/com/gitblit/client/GitblitModel.java |
| | |
| | | import java.util.Map;
|
| | |
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.IStoredSettings;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.FederationModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.ServerSettings;
|
| | | import com.gitblit.models.ServerStatus;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.RpcUtils;
|
| | |
|
| | | public class GitblitModel implements Serializable {
|
| | | /**
|
| | | * GitblitClient is a object that retrieves data from a Gitblit server, caches
|
| | | * it for local operations, and allows updating or creating Gitblit objects.
|
| | | * |
| | | * @author James Moger
|
| | | * |
| | | */
|
| | | public class GitblitClient implements Serializable {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | |
| | |
|
| | | private final char[] password;
|
| | |
|
| | | private volatile boolean isAdmin;
|
| | | private volatile boolean allowManagement;
|
| | |
|
| | | private volatile IStoredSettings settings;
|
| | | private volatile boolean allowAdministration;
|
| | |
|
| | | private volatile ServerSettings settings;
|
| | |
|
| | | private final List<RepositoryModel> allRepositories;
|
| | |
|
| | |
| | |
|
| | | private final List<FederationModel> federationRegistrations;
|
| | |
|
| | | public GitblitModel(String url, String account, char[] password) {
|
| | | private ServerStatus status;
|
| | |
|
| | | public GitblitClient(String url, String account, char[] password) {
|
| | | this.url = url;
|
| | | this.account = account;
|
| | | this.password = password;
|
| | |
| | | refreshRepositories();
|
| | |
|
| | | try {
|
| | | settings = RpcUtils.getSettings(url, account, password);
|
| | | refreshUsers();
|
| | | refreshFederationRegistrations();
|
| | | isAdmin = true;
|
| | | allowManagement = true;
|
| | | } catch (UnauthorizedException e) {
|
| | | } catch (ForbiddenException e) {
|
| | | } catch (IOException e) {
|
| | | System.err.println(e.getMessage());
|
| | | }
|
| | |
|
| | | try {
|
| | | refreshSettings();
|
| | | status = RpcUtils.getStatus(url, account, password);
|
| | | allowAdministration = true;
|
| | | } catch (UnauthorizedException e) {
|
| | | } catch (ForbiddenException e) {
|
| | | } catch (IOException e) {
|
| | | System.err.println(e.getMessage());
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public boolean allowAdmin() {
|
| | | return isAdmin;
|
| | | public boolean allowManagement() {
|
| | | return allowManagement;
|
| | | }
|
| | |
|
| | | public boolean allowAdministration() {
|
| | | return allowAdministration;
|
| | | }
|
| | |
|
| | | public boolean isOwner(RepositoryModel model) {
|
| | | return account.equalsIgnoreCase(model.owner);
|
| | | return account != null && account.equalsIgnoreCase(model.owner);
|
| | | }
|
| | |
|
| | | public IStoredSettings getSettings() {
|
| | | public ServerSettings getSettings() {
|
| | | return settings;
|
| | | }
|
| | |
|
| | | public ServerStatus getStatus() {
|
| | | return status;
|
| | | }
|
| | |
|
| | | public String getSettingDescription(String key) {
|
| | | return settings.get(key).description;
|
| | | }
|
| | |
|
| | | public List<RepositoryModel> refreshRepositories() throws IOException {
|
| | |
| | | allUsers.clear();
|
| | | allUsers.addAll(users);
|
| | | return allUsers;
|
| | | }
|
| | |
|
| | | public ServerSettings refreshSettings() throws IOException {
|
| | | settings = RpcUtils.getSettings(url, account, password);
|
| | | return settings;
|
| | | }
|
| | |
|
| | | public List<FederationModel> refreshFederationRegistrations() throws IOException {
|
| | |
| | | }
|
| | |
|
| | | public List<String> getFederationSets() {
|
| | | return settings.getStrings(Keys.federation.sets);
|
| | | return settings.get(Keys.federation.sets).getStrings();
|
| | | }
|
| | |
|
| | | public List<RepositoryModel> getRepositories() {
|
| | |
| | | public boolean deleteUser(UserModel user) throws IOException {
|
| | | return RpcUtils.deleteUser(user, url, account, password);
|
| | | }
|
| | |
|
| | | public boolean updateSettings(Map<String, String> newSettings) throws IOException {
|
| | | return RpcUtils.updateSettings(newSettings, url, account, password);
|
| | | }
|
| | | }
|