Search in sources :

Example 1 with ClusterSettingLog

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();
}
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 ClusterSettingLog

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();
}
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)

Example 3 with ClusterSettingLog

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;
}
Also used : Scanner(io.datarouter.scanner.Scanner) ServerTypes(io.datarouter.storage.servertype.ServerTypes) ServerType(io.datarouter.storage.servertype.ServerType) ClusterSettingLogKey(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogKey) ObjectTool(io.datarouter.util.lang.ObjectTool) DatarouterHtmlEmailService(io.datarouter.web.email.DatarouterHtmlEmailService) ZonedDateTime(java.time.ZonedDateTime) CachedSetting(io.datarouter.storage.setting.cached.CachedSetting) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) DatarouterClusterSettingRoot(io.datarouter.clustersetting.config.DatarouterClusterSettingRoot) DatarouterSettingTag(io.datarouter.storage.setting.DatarouterSettingTag) ClusterSettingLogAction(io.datarouter.clustersetting.ClusterSettingLogAction) ChangelogRecorder(io.datarouter.instrumentation.changelog.ChangelogRecorder) ClusterSetting(io.datarouter.clustersetting.storage.clustersetting.ClusterSetting) ClusterSettingEmailType(io.datarouter.email.type.DatarouterEmailTypes.ClusterSettingEmailType) DatarouterServerTypeDetector(io.datarouter.storage.servertype.DatarouterServerTypeDetector) Map(java.util.Map) J2HtmlDatarouterEmailBuilder(io.datarouter.email.html.J2HtmlDatarouterEmailBuilder) SimpleSettingCategory(io.datarouter.storage.setting.SettingCategory.SimpleSettingCategory) SettingRootFinder(io.datarouter.storage.setting.SettingRoot.SettingRootFinder) ClusterSettingLogByReversedCreatedMsKey(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogByReversedCreatedMsKey) DatarouterEmailLinkBuilder(io.datarouter.email.email.DatarouterEmailLinkBuilder) ServerTypeDetector(io.datarouter.storage.servertype.ServerTypeDetector) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) Set(java.util.Set) ClusterSettingValidity(io.datarouter.clustersetting.ClusterSettingValidity) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) ContainerTag(j2html.tags.ContainerTag) Range(io.datarouter.util.tuple.Range) List(java.util.List) Setting(io.datarouter.storage.setting.Setting) ClusterSettingLogJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingLogJspDto) SettingNode(io.datarouter.storage.setting.SettingNode) Entry(java.util.Map.Entry) Optional(java.util.Optional) DatarouterClusterSettingFiles(io.datarouter.clustersetting.config.DatarouterClusterSettingFiles) DatarouterClusterSettingPaths(io.datarouter.clustersetting.config.DatarouterClusterSettingPaths) SettingNameMatchResult(io.datarouter.clustersetting.service.ClusterSettingSearchService.SettingNameMatchResult) ClusterSettingService(io.datarouter.clustersetting.service.ClusterSettingService) TagCreator.text(j2html.TagCreator.text) SettingJspDto(io.datarouter.clustersetting.web.dto.SettingJspDto) ClusterSettingJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingJspDto) LocalDateTime(java.time.LocalDateTime) DatarouterClusterSettingLogDao(io.datarouter.clustersetting.storage.clustersettinglog.DatarouterClusterSettingLogDao) HashMap(java.util.HashMap) ClusterSettingSearchService(io.datarouter.clustersetting.service.ClusterSettingSearchService) TreeSet(java.util.TreeSet) ClusterSettingScope(io.datarouter.clustersetting.ClusterSettingScope) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) SettingRoot(io.datarouter.storage.setting.SettingRoot) CachedClusterSettingTags(io.datarouter.storage.setting.cached.CachedClusterSettingTags) SettingNodeJspDto(io.datarouter.clustersetting.web.dto.SettingNodeJspDto) ClusterSettingKey(io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey) DatarouterWebPaths(io.datarouter.web.config.DatarouterWebPaths) StandardDatarouterEmailHeaderService(io.datarouter.web.email.StandardDatarouterEmailHeaderService) Mav(io.datarouter.web.handler.mav.Mav) SettingCategory(io.datarouter.storage.setting.SettingCategory) StringTool(io.datarouter.util.string.StringTool) TagCreator.a(j2html.TagCreator.a) ZonedDateFormatterTool(io.datarouter.util.time.ZonedDateFormatterTool) OptionalBoolean(io.datarouter.web.handler.types.optional.OptionalBoolean) DomContent(j2html.tags.DomContent) DatarouterClusterSettingDao(io.datarouter.clustersetting.storage.clustersetting.DatarouterClusterSettingDao) J2HtmlLegendTable(io.datarouter.web.html.j2html.J2HtmlLegendTable) ClusterSettingLog(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog) DateTimeFormatter(java.time.format.DateTimeFormatter) BaseHandler(io.datarouter.web.handler.BaseHandler) Comparator(java.util.Comparator) Pair(io.datarouter.util.tuple.Pair) Mav(io.datarouter.web.handler.mav.Mav) ClusterSettingLogJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingLogJspDto) ClusterSettingLog(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog) CachedSetting(io.datarouter.storage.setting.cached.CachedSetting) ClusterSetting(io.datarouter.clustersetting.storage.clustersetting.ClusterSetting) Setting(io.datarouter.storage.setting.Setting) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) SettingNode(io.datarouter.storage.setting.SettingNode) ClusterSettingLogKey(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogKey) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

ClusterSettingLogAction (io.datarouter.clustersetting.ClusterSettingLogAction)3 ClusterSetting (io.datarouter.clustersetting.storage.clustersetting.ClusterSetting)3 ClusterSettingKey (io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey)3 ClusterSettingLog (io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLog)3 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)3 CachedSetting (io.datarouter.storage.setting.cached.CachedSetting)2 BaseHandler (io.datarouter.web.handler.BaseHandler)2 ClusterSettingScope (io.datarouter.clustersetting.ClusterSettingScope)1 ClusterSettingValidity (io.datarouter.clustersetting.ClusterSettingValidity)1 DatarouterClusterSettingFiles (io.datarouter.clustersetting.config.DatarouterClusterSettingFiles)1 DatarouterClusterSettingPaths (io.datarouter.clustersetting.config.DatarouterClusterSettingPaths)1 DatarouterClusterSettingRoot (io.datarouter.clustersetting.config.DatarouterClusterSettingRoot)1 ClusterSettingSearchService (io.datarouter.clustersetting.service.ClusterSettingSearchService)1 SettingNameMatchResult (io.datarouter.clustersetting.service.ClusterSettingSearchService.SettingNameMatchResult)1 ClusterSettingService (io.datarouter.clustersetting.service.ClusterSettingService)1 DatarouterClusterSettingDao (io.datarouter.clustersetting.storage.clustersetting.DatarouterClusterSettingDao)1 ClusterSettingLogByReversedCreatedMsKey (io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogByReversedCreatedMsKey)1 ClusterSettingLogKey (io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogKey)1 DatarouterClusterSettingLogDao (io.datarouter.clustersetting.storage.clustersettinglog.DatarouterClusterSettingLogDao)1 ClusterSettingJspDto (io.datarouter.clustersetting.web.dto.ClusterSettingJspDto)1