use of org.jboss.hal.dmr.dispatch.Dispatcher 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.dmr.dispatch.Dispatcher 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.dmr.dispatch.Dispatcher in project console by hal.
the class MembershipColumn method columnActionHandler.
private ColumnActionHandler<Assignment> columnActionHandler(Principal principal, boolean include) {
return column -> {
Role role = findRole(getFinder().getContext().getPath());
if (role != 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 org.jboss.hal.core.SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
String type = principal.getType() == Principal.Type.USER ? resources.constants().user() : resources.constants().group();
SafeHtml message = include ? resources.messages().assignmentIncludeSuccess(type, principal.getName()) : resources.messages().assignmentExcludeSuccess(type, principal.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 ContentColumn method uploadContent.
private void uploadContent() {
Metadata metadata = metadataRegistry.lookup(CONTENT_TEMPLATE);
Wizard<DeploymentContext, DeploymentState> wizard = new Wizard.Builder<DeploymentContext, DeploymentState>(resources.messages().addResourceTitle(resources.constants().content()), new DeploymentContext()).addStep(UPLOAD, new UploadContentStep(resources)).addStep(NAMES, new NamesStep(environment, metadata, resources)).onBack((context, currentState) -> currentState == NAMES ? UPLOAD : null).onNext((context, currentState) -> currentState == UPLOAD ? NAMES : null).stayOpenAfterFinish().onFinish((wzd, context) -> {
String name = context.name;
String runtimeName = context.runtimeName;
wzd.showProgress(resources.constants().uploadInProgress(), resources.messages().uploadInProgress(name));
series(new FlowContext(progress.get()), new CheckDeployment(dispatcher, name), new UploadOrReplace(environment, dispatcher, name, runtimeName, context.file, false)).subscribe(new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
wzd.showError(resources.constants().uploadError(), resources.messages().uploadError(name), error.getMessage());
}
@Override
public void onSuccess(FlowContext context) {
refresh(Ids.content(name));
wzd.showSuccess(resources.constants().uploadSuccessful(), resources.messages().uploadSuccessful(name), resources.messages().view(resources.constants().content()), cxt -> {
/* nothing to do, content is already selected */
});
}
});
}).build();
wizard.show();
}
use of org.jboss.hal.dmr.dispatch.Dispatcher in project console by hal.
the class ServerGroupDeploymentColumn method addDeploymentFromContentRepository.
private void addDeploymentFromContentRepository() {
Outcome<FlowContext> outcome = new Outcome<FlowContext>() {
@Override
public void onError(FlowContext context, Throwable error) {
MessageEvent.fire(eventBus, Message.error(resources.messages().loadContentError(), error.getMessage()));
}
@Override
public void onSuccess(FlowContext context) {
// extract content which is not deployed on statementContext.selectedServerGroup()
String serverGroup = statementContext.selectedServerGroup();
List<Content> content = context.pop();
List<Content> undeployedContentOnSelectedServerGroup = content.stream().filter(c -> !c.isDeployedTo(serverGroup)).collect(toList());
if (undeployedContentOnSelectedServerGroup.isEmpty()) {
MessageEvent.fire(eventBus, Message.warning(resources.messages().allContentAlreadyDeployedToServerGroup(serverGroup)));
} else {
new DeployContentDialog2(serverGroup, undeployedContentOnSelectedServerGroup, resources, (sg, cnt, enable) -> {
List<Operation> operations = cnt.stream().map(c -> {
ResourceAddress resourceAddress = new ResourceAddress().add(SERVER_GROUP, serverGroup).add(DEPLOYMENT, c.getName());
return new Operation.Builder(resourceAddress, ADD).param(RUNTIME_NAME, c.getRuntimeName()).param(ENABLED, enable).build();
}).collect(toList());
if (enable) {
progress.get().reset();
progress.get().tick();
}
dispatcher.execute(new Composite(operations), (CompositeResult cr) -> {
if (enable) {
progress.get().finish();
}
refresh(Ids.serverGroupDeployment(serverGroup, cnt.get(0).getName()));
MessageEvent.fire(eventBus, Message.success(resources.messages().contentDeployed2(serverGroup)));
});
}).show();
}
}
};
series(new FlowContext(progress.get()), new LoadContent(dispatcher)).subscribe(outcome);
}
Aggregations