use of io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog in project datarouter by hotpads.
the class ClusterSettingsHandler method putSettingFromParams.
/*-------------------------------- private -------------------------------*/
private ClusterSettingActionResultJson putSettingFromParams() {
ClusterSettingKey clusterSettingKey = parseClusterSettingKeyFromParams();
Optional<String> comment = parseCommentFromParams();
String value = params.optional("value").orElse(null);
var newClusterSetting = new ClusterSetting(clusterSettingKey, value);
Optional<CachedSetting<?>> setting = settingRootFinder.getSettingByName(newClusterSetting.getName());
ClusterSettingLogAction action;
Optional<ClusterSetting> dbSetting = clusterSettingDao.find(clusterSettingKey);
if (dbSetting.isPresent()) {
action = ClusterSettingLogAction.UPDATED;
} else {
action = ClusterSettingLogAction.INSERTED;
}
var result = new ClusterSettingActionResultJson(action);
if (setting.isPresent() && !setting.get().isValid(newClusterSetting.getValue())) {
String badNewValue = newClusterSetting.getValue();
String error = "Invalid value detected, setting did not accept new value: \"" + badNewValue + "\"";
return result.markError(error);
}
String oldValue = dbSetting.map(ClusterSetting::getValue).orElse("?");
String changedBy = getRequestorsUsername();
var log = new ClusterSettingLog(newClusterSetting, action, changedBy, comment.orElse(null));
clusterSettingDao.put(newClusterSetting);
clusterSettingLogDao.put(log);
sendEmail(log, oldValue);
recordChangelog(log.getKey().getName(), log.getAction().getPersistentString(), log.getChangedBy(), Optional.ofNullable(log.getComment()));
return result.markSuccess();
}
use of io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog in project datarouter by hotpads.
the class ClusterSettingsHandler method delete.
@Handler
public ClusterSettingActionResultJson delete() {
ClusterSettingLogAction action = ClusterSettingLogAction.DELETED;
var result = new ClusterSettingActionResultJson(action);
ClusterSettingKey clusterSettingKey = parseClusterSettingKeyFromParams();
Optional<String> comment = parseCommentFromParams();
String changedBy = getRequestorsUsername();
ClusterSetting clusterSetting = clusterSettingDao.get(clusterSettingKey);
var clusterSettingLog = new ClusterSettingLog(clusterSetting, action, changedBy, comment.orElse(null));
clusterSettingDao.delete(clusterSettingKey);
clusterSettingLogDao.put(clusterSettingLog);
String oldValue = clusterSetting.getValue();
sendEmail(clusterSettingLog, oldValue);
recordChangelog(clusterSettingLog.getKey().getName(), clusterSettingLog.getAction().getPersistentString(), clusterSettingLog.getChangedBy(), comment);
return result.markSuccess();
}
use of io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog in project datarouter by hotpads.
the class ClusterSettingsHandler method logsForName.
@Handler
public Mav logsForName(String name) {
Mav mav = new Mav(files.jsp.admin.datarouter.setting.clusterSettingsLogJsp);
mav.put("showingAllSettings", false);
String settingName = name.endsWith(".") ? StringTool.getStringBeforeLastOccurrence('.', name) : name;
mav.put("nameParts", settingName.split("\\."));
Optional<SettingNode> node = getSettingNode(settingName);
mav.put("showingNodeSettings", node.isPresent());
Scanner<ClusterSettingLog> logScanner;
if (node.isPresent()) {
// logs for node and its descendants
List<ClusterSettingLogKey> prefixes = node.get().getListSettings().stream().map(Setting::getName).map(ClusterSettingLogKey::createPrefix).collect(Collectors.toList());
logScanner = clusterSettingLogDao.scanWithPrefixes(prefixes).sort(Comparator.comparing((ClusterSettingLog log) -> log.getKey().getCreated()).reversed());
} else {
// logs for single setting
ClusterSettingLogKey prefix = ClusterSettingLogKey.createPrefix(settingName);
logScanner = clusterSettingLogDao.scanWithPrefix(prefix);
}
logScanner.map(setting -> new ClusterSettingLogJspDto(setting, getUserZoneId())).flush(logs -> mav.put("logs", logs));
return mav;
}
Aggregations