String dashboardConfigFile = dashboardDiskRoot + File.separator + "dashboard.xml";
String gadgetsDiskLocation = dashboardDiskRoot + File.separator + "gadgets";
// Check whether the system dashboard is already available if not populate
UserRegistry registry = DashboardPopulatorContext.getRegistry(tenantId);
// Set permission for annonymous read. We do it here because it should happen always in order
// to support mounting a remote registry.
AuthorizationManager accessControlAdmin =
registry.getUserRealm().getAuthorizationManager();
if (!accessControlAdmin.isRoleAuthorized(CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME, RegistryConstants.CONFIG_REGISTRY_BASE_PATH +
GadgetPopulator.SYSTEM_GADGETS_PATH, ActionConstants.GET)) {
accessControlAdmin.authorizeRole(CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME, RegistryConstants.CONFIG_REGISTRY_BASE_PATH +
GadgetPopulator.SYSTEM_GADGETS_PATH, ActionConstants.GET);
}
String serverName = CarbonUtils.getServerConfiguration().getFirstProperty("Name");
/* String serverPrefix = serverName.indexOf("Business Activity Monitor") > -1 ? "bam" : "";
if (serverName.length() > 0) {
gadgetsPath = SYSTEM_GADGETS_PATH + "/" + serverPrefix;
}*/
if (!registry.resourceExists(REGISTRY_SYSTEM_DASHBOARDS_ROOT + "/" + serverName)) {
// Creating an OMElement from file
File dashboardConfigXml = new File(dashboardConfigFile);
if (dashboardConfigXml.exists()) {
FileReader dashboardConfigXmlReader = new FileReader(dashboardConfigXml);
// Restoring from file
registry.restore(REGISTRY_SYSTEM_DASHBOARDS_ROOT, dashboardConfigXmlReader);
log.info("Successfully populated the default Dashboards.");
} else {
log.info("Couldn't find a Dashboard at '" + dashboardConfigFile +
"'. Giving up.");
}
// Store gadgets
File gadgetsDir = new File(gadgetsDiskLocation);
if (gadgetsDir.exists()) {
GadgetPopulator.beginFileTansfer(gadgetsDir, tenantId);
log.info("Successfully populated the default Gadgets.");
} else {
log.info("Couldn't find contents at '" + gadgetsDiskLocation +
"'. Giving up.");
}
registry.put(REGISTRY_SYSTEM_DASHBOARDS_ROOT + "/" + serverName, registry.newResource());
}
} catch (Exception e) {
log.debug("Failed to activate Dashboard Populator for Governance bundle ");
}