Search in sources :

Example 1 with OptionalString

use of io.datarouter.web.handler.types.optional.OptionalString in project datarouter by hotpads.

the class ClusterSettingsHandler method browseSettings.

@Handler
public Mav browseSettings(OptionalString name) {
    Mav mav = new Mav(files.jsp.admin.datarouter.setting.browseSettingsJsp);
    String path = servletContext.getContextPath() + paths.datarouter.settings.customSettings.toSlashedString();
    mav.put("customSettingsPath", path);
    String requestedNodeName = name.orElse(settingRootFinder.getName());
    mav.put("nodeName", name.orElse(""));
    Map<SimpleSettingCategory, Set<SettingNodeJspDto>> categoryMap = new LinkedHashMap<>();
    for (Entry<SimpleSettingCategory, Set<SettingRoot>> entry : settingRootFinder.getRootNodesByCategory().entrySet()) {
        var nodes = entry.getValue().stream().map(SettingNodeJspDto::new).collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SettingNodeJspDto::getShortName))));
        categoryMap.put(entry.getKey(), nodes);
    }
    Optional<String> currentCategory = settingRootFinder.getRootNodesByCategory().entrySet().stream().findFirst().map(Entry::getKey).map(SimpleSettingCategory::getDisplay);
    mav.put("currentCategory", currentCategory.orElse(""));
    mav.put("categoryMap", categoryMap);
    mav.put("serverTypeOptions", serverTypes.getHtmlSelectOptionsVarNames());
    Optional<SettingNode> node = getSettingNode(requestedNodeName);
    // if the node was not found, get the most recent ancestor to search its settings list
    boolean trySearchingForSpecificSetting = node.isEmpty();
    if (trySearchingForSpecificSetting) {
        node = getMostRecentAncestorSettingNode(requestedNodeName);
    }
    if (node.isEmpty()) {
        return mav;
    }
    node.ifPresent(settingNode -> {
        String rootName = StringTool.getStringBeforeFirstOccurrence('.', settingNode.getName());
        settingRootFinder.getRootNodesSortedByShortName().stream().filter(rootNode -> rootNode.getShortName().equals(rootName)).findFirst().map(SettingRoot.class::cast).map(SettingRoot::getSettingCategory).map(SettingCategory::getDisplay).ifPresent(category -> mav.put("currentCategory", category));
        mav.put("currentRootName", rootName);
    });
    mav.put("ancestors", Scanner.of(settingRootFinder.getDescendants(node.get().getName())).map(SettingNodeJspDto::new).list());
    mav.put("currentRootName", node.get().getName().substring(0, node.get().getName().indexOf('.')));
    mav.put("children", Scanner.of(node.get().getListChildren()).map(SettingNodeJspDto::new).list());
    List<CachedSetting<?>> settingsList = node.get().getListSettings();
    if (trySearchingForSpecificSetting) {
        settingsList = settingsList.stream().filter(setting -> setting.getName().equals(requestedNodeName)).collect(Collectors.toList());
    }
    Map<String, List<ClusterSettingJspDto>> customSettingsByName = new HashMap<>();
    for (CachedSetting<?> setting : settingsList) {
        ClusterSettingKey settingKey = new ClusterSettingKey(setting.getName(), null, null, null);
        List<ClusterSetting> settingsInDb = clusterSettingDao.scanWithPrefix(settingKey).list();
        Optional<ClusterSetting> mostSpecificSetting = clusterSettingService.getMostSpecificClusterSetting(settingsInDb);
        boolean isActive = setting.getMostSpecificDatabeanValue().isPresent();
        Scanner.of(settingsInDb).map(settingFromDb -> {
            boolean isWinner = mostSpecificSetting.isPresent() && settingFromDb.equals(mostSpecificSetting.get());
            ClusterSettingJspDto jspDto = new ClusterSettingJspDto(settingFromDb, isActive, isWinner);
            return jspDto;
        }).flush(customSettings -> customSettingsByName.put(setting.getName(), customSettings));
    }
    mav.put("listSettings", Scanner.of(settingsList).map(SettingJspDto::new).list());
    mav.put("mightBeDevelopment", datarouterServerTypeDetector.mightBeDevelopment());
    mav.put("mapListsCustomSettings", customSettingsByName);
    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) CachedSetting(io.datarouter.storage.setting.cached.CachedSetting) SettingNodeJspDto(io.datarouter.clustersetting.web.dto.SettingNodeJspDto) Mav(io.datarouter.web.handler.mav.Mav) Set(java.util.Set) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) SettingNode(io.datarouter.storage.setting.SettingNode) LinkedHashMap(java.util.LinkedHashMap) DatarouterClusterSettingRoot(io.datarouter.clustersetting.config.DatarouterClusterSettingRoot) SettingRoot(io.datarouter.storage.setting.SettingRoot) SettingJspDto(io.datarouter.clustersetting.web.dto.SettingJspDto) ClusterSettingJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingJspDto) TreeSet(java.util.TreeSet) List(java.util.List) ArrayList(java.util.ArrayList) ClusterSettingKey(io.datarouter.clustersetting.storage.clustersetting.ClusterSettingKey) SimpleSettingCategory(io.datarouter.storage.setting.SettingCategory.SimpleSettingCategory) ClusterSettingJspDto(io.datarouter.clustersetting.web.dto.ClusterSettingJspDto) ClusterSetting(io.datarouter.clustersetting.storage.clustersetting.ClusterSetting) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 2 with OptionalString

use of io.datarouter.web.handler.types.optional.OptionalString in project datarouter by hotpads.

the class ClusterSettingsHandler method logsForAll.

@Handler
public Mav logsForAll(OptionalString explicitStartIso, OptionalBoolean inclusiveStart) {
    Mav mav = new Mav(files.jsp.admin.datarouter.setting.clusterSettingsLogJsp);
    mav.put("showingAllSettings", true);
    long startCreatedMs = explicitStartIso.map(isoDate -> LocalDateTime.parse(isoDate, DateTimeFormatter.ISO_LOCAL_DATE_TIME)).map(localDate -> localDate.atZone(ZoneId.systemDefault())).map(ZonedDateTime::toInstant).map(Instant::toEpochMilli).orElseGet(System::currentTimeMillis);
    long reverseStartCreatedMs = Long.MAX_VALUE - startCreatedMs;
    Range<ClusterSettingLogByReversedCreatedMsKey> range = new Range<>(new ClusterSettingLogByReversedCreatedMsKey(reverseStartCreatedMs, null), inclusiveStart.orElse(false));
    clusterSettingLogDao.scanByReversedCreatedMs(range, CLUSTER_SETTING_LOGS_PAGE_SIZE).map(setting -> new ClusterSettingLogJspDto(setting, getUserZoneId())).flush(logs -> mav.put("logs", logs)).flush(logs -> mav.put("hasNextPage", logs.size() == CLUSTER_SETTING_LOGS_PAGE_SIZE));
    mav.put("hasPreviousPage", explicitStartIso.isPresent());
    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) ClusterSettingLogByReversedCreatedMsKey(io.datarouter.clustersetting.storage.clustersettinglog.ClusterSettingLogByReversedCreatedMsKey) ZonedDateTime(java.time.ZonedDateTime) Range(io.datarouter.util.tuple.Range) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 3 with OptionalString

use of io.datarouter.web.handler.types.optional.OptionalString in project datarouter by hotpads.

the class JobHandler method list.

@Handler
Mav list(OptionalString category, OptionalString keyword, OptionalBoolean enabled, OptionalBoolean disabled) {
    Optional<String> message = params.optional("jobTriggerResponseMessage");
    Mav mav = new Mav(files.jsp.admin.datarouter.job.triggersJsp);
    if (message.isPresent()) {
        mav.put("message", message.get());
    }
    Optional<String> jobCategoryName = category.getOptional();
    boolean hideEnabled = enabled.orElse(false);
    boolean hideDisabled = disabled.orElse(false);
    mav.put("serverName", serverName.get());
    mav.put("categoryRows", getJobCategoryDtos(jobCategoryName));
    LongRunningTaskSummaryDto longRunningTaskSummary = longRunningTaskService.getSummary();
    AtomicInteger rowId = new AtomicInteger();
    List<TriggerJspDto> triggerRows = jobPackageFilter.streamMatches(jobCategoryName.orElse(""), keyword.orElse(""), hideEnabled, hideDisabled).map(jobClass -> jobToTriggerJspDto(rowId.incrementAndGet(), jobClass, longRunningTaskSummary)).collect(Collectors.toList());
    mav.put("triggerRows", triggerRows);
    mav.put("legend", LongRunningTasksHandler.legend().renderFormatted());
    return mav;
}
Also used : Scanner(io.datarouter.scanner.Scanner) LongRunningTaskTrackerFactory(io.datarouter.tasktracker.service.LongRunningTaskTrackerFactory) Date(java.util.Date) JobCategoryTracker(io.datarouter.job.scheduler.JobCategoryTracker) DurationTool(io.datarouter.util.time.DurationTool) LoggerFactory(org.slf4j.LoggerFactory) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) ServerName(io.datarouter.storage.config.properties.ServerName) TreeSet(java.util.TreeSet) ChangelogRecorder(io.datarouter.instrumentation.changelog.ChangelogRecorder) Inject(javax.inject.Inject) LongRunningTaskService(io.datarouter.tasktracker.service.LongRunningTaskService) StringMav(io.datarouter.web.handler.mav.imp.StringMav) LongRunningTasksHandler(io.datarouter.tasktracker.web.LongRunningTasksHandler) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobScheduler(io.datarouter.job.scheduler.JobScheduler) Duration(java.time.Duration) JobStopperService(io.datarouter.job.service.JobStopperService) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) LongRunningTaskSummaryDto(io.datarouter.tasktracker.service.LongRunningTaskService.LongRunningTaskSummaryDto) Logger(org.slf4j.Logger) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder) BaseJob(io.datarouter.job.BaseJob) DatarouterJobFiles(io.datarouter.job.config.DatarouterJobFiles) Mav(io.datarouter.web.handler.mav.Mav) Set(java.util.Set) StringTool(io.datarouter.util.string.StringTool) Collectors(java.util.stream.Collectors) OptionalBoolean(io.datarouter.web.handler.types.optional.OptionalBoolean) List(java.util.List) DatarouterJobPaths(io.datarouter.job.config.DatarouterJobPaths) JobPackage(io.datarouter.job.scheduler.JobPackage) BaseHandler(io.datarouter.web.handler.BaseHandler) Optional(java.util.Optional) Require(io.datarouter.util.Require) LongRunningTask(io.datarouter.tasktracker.storage.LongRunningTask) LongRunningTaskHeartBeatStatus(io.datarouter.tasktracker.storage.LongRunningTaskHeartBeatStatus) StringMav(io.datarouter.web.handler.mav.imp.StringMav) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) Mav(io.datarouter.web.handler.mav.Mav) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) LongRunningTaskSummaryDto(io.datarouter.tasktracker.service.LongRunningTaskService.LongRunningTaskSummaryDto) LongRunningTasksHandler(io.datarouter.tasktracker.web.LongRunningTasksHandler) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 4 with OptionalString

use of io.datarouter.web.handler.types.optional.OptionalString in project datarouter by hotpads.

the class DatarouterPermissionRequestHandler method showForm.

@Handler(defaultHandler = true)
private Mav showForm(OptionalString deniedUrl, OptionalString allowedRoles) {
    if (!authenticationConfig.useDatarouterAuthentication()) {
        return new MessageMav(noDatarouterAuthentication());
    }
    Mav mav = new Mav(files.jsp.authentication.permissionRequestJsp);
    mav.put("serviceName", serviceName.get());
    mav.put("permissionRequestPath", paths.permissionRequest.toSlashedString());
    Optional<String> defaultSpecifics = deniedUrl.map(url -> {
        return "I tried to go to this URL: " + url + "." + allowedRoles.map(" These are its allowed roles at the time of this request: "::concat).orElse("");
    });
    mav.put("defaultSpecifics", defaultSpecifics);
    DatarouterUser user = getCurrentUser();
    mav.put("currentRequest", datarouterPermissionRequestDao.scanOpenPermissionRequestsForUser(user.getId()).findMax(Comparator.comparing(request -> request.getKey().getRequestTime())).orElse(null));
    Set<String> emails = new HashSet<>();
    if (serverTypeDetector.mightBeProduction()) {
        emails.addAll(permissionRequestEmailType.tos);
    }
    emails.add(adminEmail.get());
    if (subscribersSettings.includeSubscribers.get()) {
        emails.addAll(subscibersEmail.get());
    }
    mav.put("email", emails);
    mav.put("submitPath", paths.permissionRequest.submit.join("/"));
    mav.put("declinePath", paths.permissionRequest.declineAll.join("/"));
    return mav;
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) DatarouterUserExternalDetailService(io.datarouter.web.user.detail.DatarouterUserExternalDetailService) Date(java.util.Date) DatarouterEmailSubscriberSettings(io.datarouter.storage.config.setting.DatarouterEmailSubscriberSettings) DatarouterHtmlEmailService(io.datarouter.web.email.DatarouterHtmlEmailService) LoggerFactory(org.slf4j.LoggerFactory) DatarouterUserInfo(io.datarouter.auth.service.DatarouterUserInfo) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) ServiceName(io.datarouter.web.config.service.ServiceName) DatarouterAuthFiles(io.datarouter.auth.config.DatarouterAuthFiles) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) DatarouterUserService(io.datarouter.auth.service.DatarouterUserService) DatarouterUserRole(io.datarouter.web.user.role.DatarouterUserRole) GlobalRedirectMav(io.datarouter.web.handler.mav.imp.GlobalRedirectMav) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) ServerTypeDetector(io.datarouter.storage.servertype.ServerTypeDetector) TagCreator.table(j2html.TagCreator.table) Set(java.util.Set) Instant(java.time.Instant) ZoneId(java.time.ZoneId) DatarouterPermissionRequest(io.datarouter.auth.storage.permissionrequest.DatarouterPermissionRequest) DatarouterAuthenticationConfig(io.datarouter.web.user.authenticate.config.DatarouterAuthenticationConfig) ContainerTag(j2html.tags.ContainerTag) Objects(java.util.Objects) Optional(java.util.Optional) TagCreator.text(j2html.TagCreator.text) HashSet(java.util.HashSet) Inject(javax.inject.Inject) DatarouterUser(io.datarouter.web.user.databean.DatarouterUser) AdminEmail(io.datarouter.storage.config.properties.AdminEmail) DatarouterUserEditService(io.datarouter.auth.service.DatarouterUserEditService) TagCreator.p(j2html.TagCreator.p) Logger(org.slf4j.Logger) DatarouterAuthPaths(io.datarouter.auth.config.DatarouterAuthPaths) Mav(io.datarouter.web.handler.mav.Mav) TagCreator.b(j2html.TagCreator.b) StringTool(io.datarouter.util.string.StringTool) TagCreator.a(j2html.TagCreator.a) OptionalLong(io.datarouter.web.handler.types.optional.OptionalLong) ZonedDateFormatterTool(io.datarouter.util.time.ZonedDateFormatterTool) DomContent(j2html.tags.DomContent) DatarouterPermissionRequestDao(io.datarouter.auth.storage.permissionrequest.DatarouterPermissionRequestDao) TagCreator.td(j2html.TagCreator.td) PermissionRequestEmailType(io.datarouter.email.type.DatarouterEmailTypes.PermissionRequestEmailType) BaseHandler(io.datarouter.web.handler.BaseHandler) TagCreator.tr(j2html.TagCreator.tr) TagCreator.tbody(j2html.TagCreator.tbody) Comparator(java.util.Comparator) DatarouterSubscribersSupplier(io.datarouter.storage.config.DatarouterSubscribersSupplier) TagCreator.div(j2html.TagCreator.div) MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) GlobalRedirectMav(io.datarouter.web.handler.mav.imp.GlobalRedirectMav) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) Mav(io.datarouter.web.handler.mav.Mav) DatarouterUser(io.datarouter.web.user.databean.DatarouterUser) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) HashSet(java.util.HashSet) BaseHandler(io.datarouter.web.handler.BaseHandler)

Example 5 with OptionalString

use of io.datarouter.web.handler.types.optional.OptionalString in project datarouter by hotpads.

the class DatarouterPermissionRequestHandler method submit.

@Handler
private Mav submit(OptionalString specifics) {
    if (!authenticationConfig.useDatarouterAuthentication()) {
        return new MessageMav(noDatarouterAuthentication());
    }
    String reason = params.required(P_REASON);
    if (StringTool.isEmpty(reason)) {
        throw new IllegalArgumentException("Reason is required.");
    }
    String specificString = specifics.orElse("");
    DatarouterUser user = getCurrentUser();
    datarouterPermissionRequestDao.createPermissionRequest(new DatarouterPermissionRequest(user.getId(), new Date(), "reason: " + reason + ", specifics: " + specificString, null, null));
    sendRequestEmail(user, reason, specificString);
    // not just requestor, so send them to the home page after they make their request
    if (user.getRoles().size() > 1) {
        return new InContextRedirectMav(request, paths.home);
    }
    return showForm(new OptionalString(null), new OptionalString(null));
}
Also used : MessageMav(io.datarouter.web.handler.mav.imp.MessageMav) DatarouterUser(io.datarouter.web.user.databean.DatarouterUser) DatarouterPermissionRequest(io.datarouter.auth.storage.permissionrequest.DatarouterPermissionRequest) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) InContextRedirectMav(io.datarouter.web.handler.mav.imp.InContextRedirectMav) OptionalString(io.datarouter.web.handler.types.optional.OptionalString) Date(java.util.Date) BaseHandler(io.datarouter.web.handler.BaseHandler)

Aggregations

BaseHandler (io.datarouter.web.handler.BaseHandler)25 OptionalString (io.datarouter.web.handler.types.optional.OptionalString)25 Mav (io.datarouter.web.handler.mav.Mav)19 Inject (javax.inject.Inject)16 StringTool (io.datarouter.util.string.StringTool)14 HtmlForm (io.datarouter.web.html.form.HtmlForm)14 ContainerTag (j2html.tags.ContainerTag)14 List (java.util.List)14 TagCreator.div (j2html.TagCreator.div)13 Scanner (io.datarouter.scanner.Scanner)12 Param (io.datarouter.web.handler.types.Param)10 Bootstrap4FormHtml (io.datarouter.web.html.j2html.bootstrap4.Bootstrap4FormHtml)10 Bootstrap4PageFactory (io.datarouter.web.html.j2html.bootstrap4.Bootstrap4PageFactory)10 NumberFormatter (io.datarouter.util.number.NumberFormatter)9 TagCreator.br (j2html.TagCreator.br)7 TagCreator.h2 (j2html.TagCreator.h2)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 TagCreator.a (j2html.TagCreator.a)6 ArrayList (java.util.ArrayList)6