use of org.jboss.hal.flow.Task in project console by hal.
the class RoleColumn method removeScopedRole.
// ------------------------------------------------------ remove roles
private void removeScopedRole(Role role, String type) {
List<Task<FlowContext>> tasks = new ArrayList<>();
List<Assignment> assignments = accessControl.assignments().byRole(role).collect(toList());
if (!assignments.isEmpty()) {
tasks.add(new RemoveAssignments(dispatcher, assignments));
}
tasks.add(new CheckRoleMapping(dispatcher, role));
tasks.add(new RemoveRoleMapping(dispatcher, role, status -> status == 200));
tasks.add(new RemoveScopedRole(dispatcher, role));
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().removeResourceSuccess(type, role.getName())));
accessControl.reload(() -> {
refresh(RefreshMode.CLEAR_SELECTION);
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
}
use of org.jboss.hal.flow.Task in project console by hal.
the class RoleColumn method addScopedRole.
// ------------------------------------------------------ add roles
@SuppressWarnings("ConstantConditions")
private void addScopedRole(Role.Type type, String typeName, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).addOnly().unboundFormItem(new NameItem(), 0).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 3, resources.messages().includeAllHelpText()).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;
}).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.attach();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(typeName), form, (name, model) -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(new AddScopedRole(dispatcher, type, name, model));
Boolean includeAll = form.<Boolean>getFormItem(INCLUDE_ALL).getValue();
Role transientRole = new Role(name, null, type, null);
// We only need the role name in the functions,
// so it's ok to setup a transient role w/o the other attributes.
tasks.add(new CheckRoleMapping(dispatcher, transientRole));
tasks.add(new AddRoleMapping(dispatcher, transientRole, status -> status == 404));
if (includeAll != null && includeAll) {
tasks.add(new ModifyIncludeAll(dispatcher, transientRole, 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().addResourceSuccess(typeName, name)));
accessControl.reload(() -> {
refresh(Ids.role(name));
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
});
dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
dialog.show();
}
use of org.jboss.hal.flow.Task in project console by hal.
the class PrincipalColumn method collectTasks.
private void collectTasks(List<Task<FlowContext>> tasks, Principal.Type type, String name, boolean include, ModelNode modelNode, String attribute) {
String realm = modelNode.hasDefined(REALM) ? modelNode.get(REALM).asString() : null;
String resourceName = Principal.buildResourceName(type, name, realm);
Principal principal = new Principal(type, resourceName, name, realm);
if (modelNode.hasDefined(attribute)) {
modelNode.get(attribute).asList().stream().map(nameNode -> accessControl.roles().get(Ids.role(nameNode.asString()))).forEach(role -> {
if (role != null) {
tasks.add(new CheckRoleMapping(dispatcher, role));
tasks.add(new AddRoleMapping(dispatcher, role, status -> status == 404));
tasks.add(new AddAssignment(dispatcher, role, principal, include));
}
});
}
}
use of org.jboss.hal.flow.Task in project console by hal.
the class ServerGroupDeploymentPresenter method reload.
@Override
protected void reload() {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(new ReadServerGroupDeployments(environment, dispatcher, serverGroup, deployment));
tasks.addAll(runningServers(environment, dispatcher, properties(SERVER_GROUP, serverGroup)));
tasks.add(new LoadDeploymentsFromRunningServer(environment, dispatcher));
series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().deploymentReadError(deployment)));
}
@Override
public void onSuccess(FlowContext context) {
List<ServerGroupDeployment> serverGroupDeployments = context.get(DeploymentTasks.SERVER_GROUP_DEPLOYMENTS);
if (!serverGroupDeployments.isEmpty()) {
ServerGroupDeployment serverGroupDeployment = serverGroupDeployments.get(0);
getView().update(serverGroup, serverGroupDeployment);
} else {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().deploymentReadError(deployment)));
}
}
});
}
use of org.jboss.hal.flow.Task in project console by hal.
the class TestStep method testConnection.
private void testConnection() {
Context context = wizard().getContext();
List<Task<FlowContext>> tasks = new ArrayList<>();
if (!context.isCreated()) {
// add data source
tasks.add(flowContext -> dispatcher.execute(addOperation(context, statementContext)).doOnSuccess((CompositeResult result) -> context.setCreated(true)).doOnError(throwable -> {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, resources.messages().dataSourceAddError());
}).toCompletable());
}
// check running server(s)
tasks.addAll(runningServers(environment, dispatcher, properties(PROFILE_NAME, statementContext.selectedProfile())));
// test connection
tasks.add(flowContext -> {
List<Server> servers = flowContext.get(TopologyTasks.SERVERS);
ResourceAddress address;
if (!servers.isEmpty()) {
Server server = servers.get(0);
address = server.getServerAddress();
} else if (environment.isStandalone()) {
address = ResourceAddress.root();
} else {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, SafeHtmlUtils.fromString(resources.constants().noRunningServers()));
return Completable.error(new FlowException(resources.messages().testConnectionErrorDomain(), flowContext));
}
address.add(SUBSYSTEM, DATASOURCES).add(context.dataSource.isXa() ? XA_DATA_SOURCE : DATA_SOURCE, context.dataSource.getName());
Operation operation = new Operation.Builder(address, TEST_CONNECTION_IN_POOL).build();
return dispatcher.execute(operation).doOnError(throwable -> {
flowContext.set(WIZARD_TITLE, resources.constants().testConnectionError());
flowContext.set(WIZARD_TEXT, resources.messages().testConnectionError(context.dataSource.getName()));
}).toCompletable();
});
series(new FlowContext(progress.get()), tasks).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext flowContext, Throwable error) {
String title;
SafeHtml text;
if (flowContext == null) {
title = resources.constants().unknownError();
text = resources.messages().unknownError();
} else {
title = flowContext.get(WIZARD_TITLE);
text = flowContext.get(WIZARD_TEXT);
}
wizard().showError(title, text, error.getMessage(), false);
}
@Override
public void onSuccess(FlowContext flowContext) {
wizard().showSuccess(resources.constants().testConnectionSuccess(), resources.messages().testConnectionSuccess(context.dataSource.getName()), false);
}
});
}
Aggregations