Line data Source code
1 : // Copyright (C) 2015 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.api.config; 16 : 17 : import static com.google.gerrit.server.api.ApiUtil.asRestApiException; 18 : 19 : import com.google.gerrit.common.Version; 20 : import com.google.gerrit.extensions.api.config.ConsistencyCheckInfo; 21 : import com.google.gerrit.extensions.api.config.ConsistencyCheckInput; 22 : import com.google.gerrit.extensions.api.config.Server; 23 : import com.google.gerrit.extensions.client.DiffPreferencesInfo; 24 : import com.google.gerrit.extensions.client.EditPreferencesInfo; 25 : import com.google.gerrit.extensions.client.GeneralPreferencesInfo; 26 : import com.google.gerrit.extensions.common.ServerInfo; 27 : import com.google.gerrit.extensions.restapi.RestApiException; 28 : import com.google.gerrit.extensions.webui.TopMenu; 29 : import com.google.gerrit.server.config.ConfigResource; 30 : import com.google.gerrit.server.restapi.config.CheckConsistency; 31 : import com.google.gerrit.server.restapi.config.GetDiffPreferences; 32 : import com.google.gerrit.server.restapi.config.GetEditPreferences; 33 : import com.google.gerrit.server.restapi.config.GetPreferences; 34 : import com.google.gerrit.server.restapi.config.GetServerInfo; 35 : import com.google.gerrit.server.restapi.config.ListTopMenus; 36 : import com.google.gerrit.server.restapi.config.SetDiffPreferences; 37 : import com.google.gerrit.server.restapi.config.SetEditPreferences; 38 : import com.google.gerrit.server.restapi.config.SetPreferences; 39 : import com.google.inject.Inject; 40 : import com.google.inject.Provider; 41 : import com.google.inject.Singleton; 42 : import java.util.List; 43 : 44 : @Singleton 45 : public class ServerImpl implements Server { 46 : private final GetPreferences getPreferences; 47 : private final SetPreferences setPreferences; 48 : private final GetDiffPreferences getDiffPreferences; 49 : private final SetDiffPreferences setDiffPreferences; 50 : private final GetEditPreferences getEditPreferences; 51 : private final SetEditPreferences setEditPreferences; 52 : private final GetServerInfo getServerInfo; 53 : private final Provider<CheckConsistency> checkConsistency; 54 : private final ListTopMenus listTopMenus; 55 : 56 : @Inject 57 : ServerImpl( 58 : GetPreferences getPreferences, 59 : SetPreferences setPreferences, 60 : GetDiffPreferences getDiffPreferences, 61 : SetDiffPreferences setDiffPreferences, 62 : GetEditPreferences getEditPreferences, 63 : SetEditPreferences setEditPreferences, 64 : GetServerInfo getServerInfo, 65 : Provider<CheckConsistency> checkConsistency, 66 149 : ListTopMenus listTopMenus) { 67 149 : this.getPreferences = getPreferences; 68 149 : this.setPreferences = setPreferences; 69 149 : this.getDiffPreferences = getDiffPreferences; 70 149 : this.setDiffPreferences = setDiffPreferences; 71 149 : this.getEditPreferences = getEditPreferences; 72 149 : this.setEditPreferences = setEditPreferences; 73 149 : this.getServerInfo = getServerInfo; 74 149 : this.checkConsistency = checkConsistency; 75 149 : this.listTopMenus = listTopMenus; 76 149 : } 77 : 78 : @Override 79 : public String getVersion() throws RestApiException { 80 1 : return Version.getVersion(); 81 : } 82 : 83 : @Override 84 : public ServerInfo getInfo() throws RestApiException { 85 : try { 86 2 : return getServerInfo.apply(new ConfigResource()).value(); 87 0 : } catch (Exception e) { 88 0 : throw asRestApiException("Cannot get server info", e); 89 : } 90 : } 91 : 92 : @Override 93 : public GeneralPreferencesInfo getDefaultPreferences() throws RestApiException { 94 : try { 95 1 : return getPreferences.apply(new ConfigResource()).value(); 96 0 : } catch (Exception e) { 97 0 : throw asRestApiException("Cannot get default general preferences", e); 98 : } 99 : } 100 : 101 : @Override 102 : public GeneralPreferencesInfo setDefaultPreferences(GeneralPreferencesInfo in) 103 : throws RestApiException { 104 : try { 105 2 : return setPreferences.apply(new ConfigResource(), in).value(); 106 0 : } catch (Exception e) { 107 0 : throw asRestApiException("Cannot set default general preferences", e); 108 : } 109 : } 110 : 111 : @Override 112 : public DiffPreferencesInfo getDefaultDiffPreferences() throws RestApiException { 113 : try { 114 1 : return getDiffPreferences.apply(new ConfigResource()).value(); 115 0 : } catch (Exception e) { 116 0 : throw asRestApiException("Cannot get default diff preferences", e); 117 : } 118 : } 119 : 120 : @Override 121 : public DiffPreferencesInfo setDefaultDiffPreferences(DiffPreferencesInfo in) 122 : throws RestApiException { 123 : try { 124 2 : return setDiffPreferences.apply(new ConfigResource(), in).value(); 125 0 : } catch (Exception e) { 126 0 : throw asRestApiException("Cannot set default diff preferences", e); 127 : } 128 : } 129 : 130 : @Override 131 : public EditPreferencesInfo getDefaultEditPreferences() throws RestApiException { 132 : try { 133 1 : return getEditPreferences.apply(new ConfigResource()).value(); 134 0 : } catch (Exception e) { 135 0 : throw asRestApiException("Cannot get default edit preferences", e); 136 : } 137 : } 138 : 139 : @Override 140 : public EditPreferencesInfo setDefaultEditPreferences(EditPreferencesInfo in) 141 : throws RestApiException { 142 : try { 143 1 : return setEditPreferences.apply(new ConfigResource(), in).value(); 144 0 : } catch (Exception e) { 145 0 : throw asRestApiException("Cannot set default edit preferences", e); 146 : } 147 : } 148 : 149 : @Override 150 : public ConsistencyCheckInfo checkConsistency(ConsistencyCheckInput in) throws RestApiException { 151 : try { 152 3 : return checkConsistency.get().apply(new ConfigResource(), in).value(); 153 1 : } catch (Exception e) { 154 1 : throw asRestApiException("Cannot check consistency", e); 155 : } 156 : } 157 : 158 : @Override 159 : public List<TopMenu.MenuEntry> topMenus() throws RestApiException { 160 : try { 161 1 : return listTopMenus.apply(new ConfigResource()).value(); 162 0 : } catch (Exception e) { 163 0 : throw asRestApiException("Cannot get top menus", e); 164 : } 165 : } 166 : }