use of com.google.gerrit.extensions.api.accounts.AccountApi in project gerrit by GerritCodeReview.
the class IndexHtmlUtil method dynamicTemplateData.
/**
* Returns dynamic parameters of {@code index.html}.
*/
public static ImmutableMap<String, Object> dynamicTemplateData(GerritApi gerritApi, String requestedURL) throws RestApiException, URISyntaxException {
ImmutableMap.Builder<String, Object> data = ImmutableMap.builder();
Map<String, SanitizedContent> initialData = new HashMap<>();
Server serverApi = gerritApi.config().server();
initialData.put("\"/config/server/info\"", serializeObject(GSON, serverApi.getInfo()));
initialData.put("\"/config/server/version\"", serializeObject(GSON, serverApi.getVersion()));
initialData.put("\"/config/server/top-menus\"", serializeObject(GSON, serverApi.topMenus()));
String requestedPath = IndexPreloadingUtil.getPath(requestedURL);
IndexPreloadingUtil.RequestedPage page = IndexPreloadingUtil.parseRequestedPage(requestedPath);
switch(page) {
case CHANGE:
data.put("defaultChangeDetailHex", ListOption.toHex(IndexPreloadingUtil.CHANGE_DETAIL_OPTIONS));
data.put("changeRequestsPath", IndexPreloadingUtil.computeChangeRequestsPath(requestedPath, page).get());
break;
case DIFF:
data.put("defaultChangeDetailHex", ListOption.toHex(IndexPreloadingUtil.CHANGE_DETAIL_OPTIONS));
data.put("changeRequestsPath", IndexPreloadingUtil.computeChangeRequestsPath(requestedPath, page).get());
break;
case DASHBOARD:
// Dashboard is preloaded queries are added later when we check user is authenticated.
case PAGE_WITHOUT_PRELOADING:
break;
}
try {
AccountApi accountApi = gerritApi.accounts().self();
initialData.put("\"/accounts/self/detail\"", serializeObject(GSON, accountApi.get()));
initialData.put("\"/accounts/self/preferences\"", serializeObject(GSON, accountApi.getPreferences()));
initialData.put("\"/accounts/self/preferences.diff\"", serializeObject(GSON, accountApi.getDiffPreferences()));
initialData.put("\"/accounts/self/preferences.edit\"", serializeObject(GSON, accountApi.getEditPreferences()));
data.put("userIsAuthenticated", true);
if (page == RequestedPage.DASHBOARD) {
data.put("defaultDashboardHex", ListOption.toHex(IndexPreloadingUtil.DASHBOARD_OPTIONS));
data.put("dashboardQuery", IndexPreloadingUtil.computeDashboardQueryList(serverApi));
}
} catch (AuthException e) {
logger.atFine().log("Can't inline account-related data because user is unauthenticated");
// Don't render data
}
data.put("gerritInitialData", initialData);
return data.build();
}
Aggregations