use of org.jboss.hal.dmr.dispatch.Dispatcher in project console by hal.
the class OtherSettingsPresenter method addSecurityDomain.
// -------------------------------------------- Security Domain
void addSecurityDomain() {
Metadata metadata = metadataRegistry.lookup(SECURITY_DOMAIN_TEMPLATE);
// emulate capability-reference on default-realm
String capabilityReference = metadata.getDescription().findAttribute(ATTRIBUTES + "/" + REALMS + "/" + VALUE_TYPE, REALM).getValue().get(CAPABILITY_REFERENCE).asString();
String id = Ids.build(Ids.ELYTRON_SECURITY_DOMAIN, Ids.ADD);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).addOnly().unboundFormItem(nameItem, 0).include(DEFAULT_REALM).unsorted().build();
form.getFormItem(DEFAULT_REALM).setRequired(true);
form.getFormItem(DEFAULT_REALM).registerSuggestHandler(new SuggestCapabilitiesAutoComplete(dispatcher, statementContext, capabilityReference, metadata.getTemplate()));
new AddResourceDialog(resources.messages().addResourceTitle(Names.SECURITY_DOMAIN), form, (name, model) -> {
if (model != null) {
// add the default-realm in the list of realms
ModelNode realm = new ModelNode();
realm.get(REALM).set(model.get(DEFAULT_REALM).asString());
model.get(REALMS).add(realm);
}
ResourceAddress address = SECURITY_DOMAIN_TEMPLATE.resolve(statementContext, nameItem.getValue());
crud.add(Names.SECURITY_DOMAIN, name, address, model, (n, a) -> reload(SECURITY_DOMAIN, nodes -> getView().updateResourceElement(SECURITY_DOMAIN, nodes)));
}).show();
}
use of org.jboss.hal.dmr.dispatch.Dispatcher in project console by hal.
the class RoleColumn method editScopedRole.
private void editScopedRole(Role role, String type, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).include(BASE_ROLE, scopeAttribute).customFormItem(BASE_ROLE, attributeDescription -> {
SingleSelectBoxItem item = new SingleSelectBoxItem(BASE_ROLE, new LabelBuilder().label(BASE_ROLE), standardRoleNames, false);
item.setRequired(true);
return item;
}).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 2, resources.messages().includeAllHelpText()).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.getFormItem(INCLUDE_ALL).setValue(role.isIncludeAll());
form.attach();
ModelNode modelNode = new ModelNode();
modelNode.get(BASE_ROLE).set(role.getBaseRole().getName());
role.getScope().forEach(scope -> modelNode.get(scopeAttribute).add(scope));
new ModifyResourceDialog(resources.messages().modifyResourceTitle(type), form, (frm, changedValues) -> {
boolean includeAll = frm.<Boolean>getFormItem(INCLUDE_ALL).getValue();
boolean includeAllChanged = includeAll != role.isIncludeAll();
List<Task<FlowContext>> tasks = new ArrayList<>();
if (!changedValues.isEmpty()) {
tasks.add(new ModifyScopedRole(dispatcher, role, changedValues, metadata));
}
if (includeAllChanged) {
tasks.add(new ModifyIncludeAll(dispatcher, role, includeAll));
}
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(eventBus, Message.success(resources.messages().modifyResourceSuccess(type, role.getName())));
accessControl.reload(() -> {
refresh(role.getId());
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
}).show(modelNode);
}
use of org.jboss.hal.dmr.dispatch.Dispatcher in project console by hal.
the class AssignmentColumn method columnActionHandler.
private ColumnActionHandler<Assignment> columnActionHandler(Role role, boolean include) {
return column -> {
Principal principal = findPrincipal(getFinder().getContext().getPath());
if (principal != null) {
series(new FlowContext(progress.get()), new CheckRoleMapping(dispatcher, role), new AddRoleMapping(dispatcher, role, status -> status == 404), new AddAssignment(dispatcher, role, principal, include)).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
String type = resources.constants().role();
SafeHtml message = include ? resources.messages().assignmentIncludeSuccess(type, role.getName()) : resources.messages().assignmentExcludeSuccess(type, role.getName());
MessageEvent.fire(eventBus, Message.success(message));
accessControl.reload(() -> {
refresh(RefreshMode.RESTORE_SELECTION);
if (isCurrentUser(principal)) {
eventBus.fireEvent(new UserChangedEvent());
}
});
}
});
}
};
}
use of org.jboss.hal.dmr.dispatch.Dispatcher in project console by hal.
the class DataSourceColumn method prepareWizard.
private void prepareWizard(boolean xa) {
Task<FlowContext> readDataSources = context -> crud.readChildren(DATA_SOURCE_SUBSYSTEM_TEMPLATE, xa ? XA_DATA_SOURCE : DATA_SOURCE).doOnSuccess(children -> {
List<DataSource> dataSources = children.stream().map(property -> new DataSource(property, xa)).collect(toList());
context.set(DATASOURCES, dataSources);
}).toCompletable();
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(readDataSources);
tasks.addAll(runningServers(environment, dispatcher, properties(PROFILE_NAME, statementContext.selectedProfile())));
tasks.add(new JdbcDriverTasks.ReadRuntime(environment, dispatcher));
tasks.add(new JdbcDriverTasks.CombineDriverResults());
series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
showWizard(Collections.emptyList(), Collections.emptyList(), xa);
}
@Override
public void onSuccess(FlowContext context) {
List<DataSource> dataSources = context.get(DATASOURCES);
List<JdbcDriver> drivers = context.get(JdbcDriverTasks.DRIVERS);
showWizard(dataSources, drivers, xa);
}
});
}
use of org.jboss.hal.dmr.dispatch.Dispatcher in project console by hal.
the class TopologyPreview method update.
// ------------------------------------------------------ dmr functions
@Override
public void update(StaticItem item) {
// remember selection
HTMLElement element = (HTMLElement) document.querySelector(DOT + topology + " ." + selected);
String hostName = element != null ? String.valueOf(element.dataset.get("host")) : null;
String serverGroupName = element != null ? String.valueOf(element.dataset.get("serverGroup")) : null;
String serverName = element != null ? String.valueOf(element.dataset.get("server")) : null;
clearSelected();
setVisible(loadingSection, false);
setVisible(topologySection, false);
hideDetails();
// show the loading indicator if the operations take too long
double timeoutHandle = setTimeout((o) -> setVisible(loadingSection, true), MEDIUM_TIMEOUT);
series(new FlowContext(progress.get()), topology(environment, dispatcher)).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
clearTimeout(timeoutHandle);
setVisible(loadingSection, false);
MessageEvent.fire(eventBus, Message.error(resources.messages().topologyError(), error.getMessage()));
}
@Override
public void onSuccess(FlowContext context) {
clearTimeout(timeoutHandle);
setVisible(loadingSection, false);
Elements.removeChildrenFrom(topologySection);
List<Host> hosts = context.get(TopologyTasks.HOSTS);
List<ServerGroup> serverGroups = context.get(TopologyTasks.SERVER_GROUPS);
List<Server> servers = context.get(TopologyTasks.SERVERS);
topologySection.appendChild(buildTable(hosts, serverGroups, servers));
setVisible(topologySection, true);
adjustTdHeight();
// restore selection
if (hostName != null) {
hosts.stream().filter(host -> hostName.equals(host.getName())).findAny().ifPresent(host -> hostDetails(host));
}
if (serverGroupName != null) {
serverGroups.stream().filter(serverGroup -> serverGroupName.equals(serverGroup.getName())).findAny().ifPresent(serverGroup -> serverGroupDetails(serverGroup));
}
if (serverName != null) {
servers.stream().filter(server -> serverName.equals(server.getName())).findAny().ifPresent(server -> serverDetails(server));
}
}
});
}
Aggregations