Search in sources :

Example 1 with ClusterSettingLogAction

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();
}
Also used : CachedSetting(io.datarouter.storage.setting.cached.CachedSetting) ClusterSetting(io.datarouter.clustersetting.storage.clustersetting.ClusterSetting) ClusterSettingKey(io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey) ClusterSettingLog(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) ClusterSettingLogAction(io.datarouter.clustersetting.ClusterSettingLogAction)

Example 2 with ClusterSettingLogAction

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();
}
Also used : ClusterSetting(io.datarouter.clustersetting.storage.clustersetting.ClusterSetting) ClusterSettingKey(io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey) ClusterSettingLog(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) ClusterSettingLogAction(io.datarouter.clustersetting.ClusterSettingLogAction) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

ClusterSettingLogAction (io.datarouter.clustersetting.ClusterSettingLogAction)2 ClusterSetting (io.datarouter.clustersetting.storage.clustersetting.ClusterSetting)2 ClusterSettingKey (io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey)2 ClusterSettingLog (io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog)2 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)2 CachedSetting (io.datarouter.storage.setting.cached.CachedSetting)1 BaseHandler (io.datarouter.web.handler.BaseHandler)1