use of io.datarouter.clustersetting.ClusterSettingLogAction 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.ClusterSettingLogAction 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();
}
Aggregations