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