Search in sources :

Example 1 with Wizard

use of org.jboss.hal.ballroom.wizard.Wizard in project console by hal.

the class EnableSSLWizard method show.

public void show() {
    Constants constants = resources.constants();
    AddressTemplate template = undertowHttps ? UNDERTOW_HTTPS_LISTENER_TEMPLATE : HTTP_INTERFACE_TEMPLATE;
    Wizard.Builder<EnableSSLContext, EnableSSLState> wb = new Wizard.Builder<>(constants.enableSSLManagementTitle(), new EnableSSLContext());
    wb.addStep(EnableSSLState.DEFINE_STRATEGY, new DefineStrategyStep(resources, environment.isStandalone(), undertowHttps)).addStep(EnableSSLState.CONFIGURATION, new ConfigurationStep(existingResources, resources, environment, undertowHttps, template)).addStep(EnableSSLState.REVIEW, new ReviewStep(dispatcher, statementContext, resources, environment, undertowHttps, template)).onBack((context, currentState) -> {
        EnableSSLState previous = null;
        switch(currentState) {
            case DEFINE_STRATEGY:
                break;
            case CONFIGURATION:
                previous = EnableSSLState.DEFINE_STRATEGY;
                break;
            case REVIEW:
                previous = EnableSSLState.CONFIGURATION;
                break;
            default:
                break;
        }
        return previous;
    }).onNext((context, currentState) -> {
        EnableSSLState next = null;
        switch(currentState) {
            case DEFINE_STRATEGY:
                next = EnableSSLState.CONFIGURATION;
                break;
            case CONFIGURATION:
                next = EnableSSLState.REVIEW;
                break;
            case REVIEW:
                break;
            default:
                break;
        }
        return next;
    }).stayOpenAfterFinish().onFinish((wizard, context) -> {
        ModelNode model = context.model;
        ModelNode credRef = new ModelNode();
        credRef.get(CLEAR_TEXT).set(asString(model, AbstractConfiguration.KEY_STORE_PASSWORD));
        // use Flow tasks to run DMR operations as there are resources that must exists before next
        // operations are called, as in the example of a generate-key-pair and import-certificate
        // the key-store must exists. For this case, the Composite doesn't work.
        List<Task<FlowContext>> tasks = new ArrayList<>();
        // key-store is only created when user chooses to create all resources or create a key-store based on
        // an existing JKS file
        boolean createKeyStore = !context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_RESOURCE_EXISTS);
        String keyStoreName = createKeyStore ? asString(model, AbstractConfiguration.KEY_STORE_NAME) : asString(model, KEY_STORE);
        if (createKeyStore) {
            if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_CREATE)) {
                ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                tasks.add(flowContext -> {
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE));
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
                tasks.add(flowContext -> {
                    Composite composite = new Composite();
                    // the generate-key=pair can only be called on an existing key-store
                    String dn = "CN=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_CN) + ", OU=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_OU) + ", O=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_O) + ", L=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_L) + ", ST=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_ST) + ", C=" + asString(model, AbstractConfiguration.PRIVATE_KEY_DN_C);
                    Operation genKeyOp = new Operation.Builder(ksAddress, GENERATE_KEY_PAIR).param(ALIAS, asString(model, AbstractConfiguration.PRIVATE_KEY_ALIAS)).param(DISTINGUISHED_NAME, dn).param(VALIDITY, asString(model, AbstractConfiguration.PRIVATE_KEY_VALIDITY)).param(ModelDescriptionConstants.ALGORITHM, asString(model, AbstractConfiguration.PRIVATE_KEY_ALGORITHM)).build();
                    composite.add(genKeyOp);
                    Operation storeOp = new Operation.Builder(ksAddress, STORE).build();
                    composite.add(storeOp);
                    return dispatcher.execute(composite).toCompletable();
                });
            } else if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_FILE_EXISTS)) {
                tasks.add(flowContext -> {
                    ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE)).param(REQUIRED, true);
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
            } else if (context.strategy.equals(EnableSSLContext.Strategy.KEYSTORE_OBTAIN_LETSENCRYPT)) {
                ResourceAddress ksAddress = keyStoreTemplate().resolve(statementContext, keyStoreName);
                tasks.add(flowContext -> {
                    Operation.Builder builder = new Operation.Builder(ksAddress, ADD).param(PATH, asString(model, KEY_STORE_PATH)).param(CREDENTIAL_REFERENCE, credRef).param(TYPE, asString(model, AbstractConfiguration.KEY_STORE_TYPE));
                    if (model.hasDefined(AbstractConfiguration.KEY_STORE_RELATIVE_TO)) {
                        builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.KEY_STORE_RELATIVE_TO));
                    }
                    Operation keyStoreOp = builder.build();
                    return dispatcher.execute(keyStoreOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addKeyStoreError(keyStoreName), exception.getMessage(), false)).toCompletable();
                });
                String caaName = asString(model, CAA_NAME);
                ResourceAddress caaAddress = certificateAuthorityAccountTemplate().resolve(statementContext, caaName);
                tasks.add(flowContext -> {
                    Operation caaOp = new Operation.Builder(caaAddress, ADD).param(KEY_STORE, keyStoreName).param(ALIAS, asString(model, CAA_ALIAS)).build();
                    return dispatcher.execute(caaOp).doOnError(exception -> wizard.showError(constants.failed(), resources.messages().addResourceError(caaName, exception.getMessage()), false)).toCompletable();
                });
                tasks.add(flowContext -> {
                    Composite composite = new Composite();
                    String obtainAlias = asString(model, PRIVATE_KEY_ALIAS);
                    Operation obtainOp = new Operation.Builder(ksAddress, OBTAIN_CERTIFICATE).param(ALIAS, obtainAlias).param(CERTIFICATE_AUTHORITY_ACCOUNT, caaName).param("domain-names", model.get(CAA_DOMAIN_NAMES)).param("agree-to-terms-of-service", true).param("staging", asString(model, CAA_STAGING)).build();
                    composite.add(obtainOp);
                    Operation storeOp = new Operation.Builder(ksAddress, STORE).build();
                    composite.add(storeOp);
                    return dispatcher.execute(composite).doOnError(ex -> wizard.showError(constants.failed(), resources.messages().obtainCertificateError(obtainAlias, keyStoreName, ex.getMessage()), false)).toCompletable();
                });
            }
        }
        String trustManagerName = model.hasDefined(TRUST_MANAGER) ? asString(model, TRUST_MANAGER) : null;
        if (context.mutualAuthentication) {
            ModelNode tsCredRef = new ModelNode();
            tsCredRef.get(CLEAR_TEXT).set(asString(model, AbstractConfiguration.TRUST_STORE_PASSWORD));
            String trustStoreName = asString(model, AbstractConfiguration.TRUST_STORE_NAME);
            ResourceAddress tsAddress = keyStoreTemplate().resolve(statementContext, trustStoreName);
            tasks.add(flowContext -> {
                Operation.Builder builder = new Operation.Builder(tsAddress, ADD).param(PATH, asString(model, AbstractConfiguration.TRUST_STORE_PATH)).param(CREDENTIAL_REFERENCE, tsCredRef).param(TYPE, asString(model, AbstractConfiguration.TRUST_STORE_TYPE));
                if (model.hasDefined(AbstractConfiguration.TRUST_STORE_RELATIVE_TO)) {
                    builder.param(RELATIVE_TO, asString(model, AbstractConfiguration.TRUST_STORE_RELATIVE_TO));
                }
                Operation trustStoreOp = builder.build();
                return dispatcher.execute(trustStoreOp).toCompletable();
            });
            tasks.add(flowContext -> {
                Composite composite = new Composite();
                Operation importCertOp = new Operation.Builder(tsAddress, IMPORT_CERTIFICATE).param(ALIAS, asString(model, AbstractConfiguration.CLIENT_CERTIFICATE_ALIAS)).param(PATH, asString(model, AbstractConfiguration.CLIENT_CERTIFICATE_PATH)).param(CREDENTIAL_REFERENCE, tsCredRef).param(VALIDATE, model.get(AbstractConfiguration.CLIENT_CERTIFICATE_VALIDATE).asBoolean(false)).param(TRUST_CACERTS, model.get(AbstractConfiguration.CLIENT_CERTIFICATE_TRUST).asBoolean(false)).build();
                composite.add(importCertOp);
                Operation storeOp = new Operation.Builder(tsAddress, STORE).build();
                composite.add(storeOp);
                ResourceAddress etmAddress = trustManagerTemplate().resolve(statementContext, trustManagerName);
                Operation trustManagerOp = new Operation.Builder(etmAddress, ADD).param(KEY_STORE, trustStoreName).param(ModelDescriptionConstants.ALGORITHM, KEY_MANAGER_ALGORITHM).build();
                composite.add(trustManagerOp);
                return dispatcher.execute(composite).toCompletable();
            });
        }
        Composite composite = new Composite();
        String keyManager = asString(model, KEY_MANAGER);
        ResourceAddress ekmAddress = keyManagerTemplate().resolve(statementContext, keyManager);
        Operation keyManagerOp = new Operation.Builder(ekmAddress, ADD).param(KEY_STORE, keyStoreName).param(ModelDescriptionConstants.ALGORITHM, KEY_MANAGER_ALGORITHM).param(CREDENTIAL_REFERENCE, credRef).build();
        composite.add(keyManagerOp);
        ModelNode protocols = new ModelNode();
        protocols.add(KEY_MANAGER_TLSV1_2);
        String serverSslContext = asString(model, SERVER_SSL_CONTEXT);
        ResourceAddress sslCtxAddress = sslContextTemplate().resolve(statementContext, serverSslContext);
        Operation.Builder sslCtxBuilder = new Operation.Builder(sslCtxAddress, ADD).param(KEY_MANAGER, keyManager).param(PROTOCOLS, protocols);
        if (context.mutualAuthentication) {
            sslCtxBuilder.param(TRUST_MANAGER, trustManagerName);
            sslCtxBuilder.param(WANT_CLIENT_AUTH, true);
        }
        Operation sslCtxOp = sslCtxBuilder.build();
        composite.add(sslCtxOp);
        if (undertowHttps) {
            ResourceAddress httpsAddress = UNDERTOW_HTTPS_LISTENER_TEMPLATE.resolve(statementContext, undertowServer, httpsListener);
            Operation writeSslCtxOp = new Operation.Builder(httpsAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).param(VALUE, serverSslContext).build();
            composite.add(writeSslCtxOp);
            // undefine the "alternatives" attributes
            composite.add(undefineAttribute(httpsAddress, SECURITY_REALM));
            composite.add(undefineAttribute(httpsAddress, "verify-client"));
            composite.add(undefineAttribute(httpsAddress, "enabled-cipher-suites"));
            composite.add(undefineAttribute(httpsAddress, "enabled-protocols"));
            composite.add(undefineAttribute(httpsAddress, "ssl-session-cache-size"));
            composite.add(undefineAttribute(httpsAddress, "ssl-session-timeout"));
        } else {
            ResourceAddress httpInterfaceAddress = HTTP_INTERFACE_TEMPLATE.resolve(statementContext);
            Operation writeSslCtxOp = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).param(VALUE, serverSslContext).build();
            composite.add(writeSslCtxOp);
            if (environment.isStandalone()) {
                Operation writeSecureSocketBinding = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SECURE_SOCKET_BINDING).param(VALUE, asString(model, SECURE_SOCKET_BINDING)).build();
                composite.add(writeSecureSocketBinding);
            } else {
                Operation writeSecurePortOp = new Operation.Builder(httpInterfaceAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SECURE_PORT).param(VALUE, asString(model, SECURE_PORT)).build();
                composite.add(writeSecurePortOp);
            }
        }
        tasks.add(flowContext -> dispatcher.execute(composite).toCompletable());
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                if (undertowHttps) {
                    wizard.showSuccess(resources.constants().success(), resources.messages().enableSSLResultsSuccessUndertow(httpsListener, serverSslContext), context1 -> presenter.reloadView(), true);
                } else {
                    // constructs the http management console url
                    String serverName = environment.isStandalone() ? Names.STANDALONE_SERVER : Names.DOMAIN_CONTROLLER;
                    String label = resources.constants().reload() + " " + serverName;
                    SafeHtml description;
                    StringBuilder location = new StringBuilder("https://" + window.location.getHostname() + ":");
                    if (environment.isStandalone()) {
                        location.append(context.securePort);
                        description = resources.messages().enableSSLResultsSuccessStandalone(location.toString());
                    } else {
                        location.append(asString(model, SECURE_PORT));
                        description = resources.messages().enableSSLResultsSuccessDomain(location.toString());
                    }
                    // extracts the url search path, so the url shows the view the user is located
                    String urlSuffix = window.location.getHref();
                    urlSuffix = urlSuffix.substring(urlSuffix.indexOf("//") + 2);
                    urlSuffix = urlSuffix.substring(urlSuffix.indexOf("/"));
                    location.append(urlSuffix);
                    wizard.showSuccess(resources.constants().success(), description, label, // reloads the server/host if user clicks on the success action
                    context1 -> presenter.reloadServer(host, location.toString()), // reload only the view and displays a success message
                    context2 -> {
                        presenter.reloadView();
                        MessageEvent.fire(eventBus, Message.success(resources.messages().enableSSLSuccess()));
                    }, true);
                }
            }

            @Override
            public void onError(FlowContext context, Throwable exception) {
                wizard.showError(resources.constants().failed(), resources.messages().enableSSLResultsError(), exception.getMessage(), false);
            }
        });
    });
    Wizard<EnableSSLContext, EnableSSLState> wizard = wb.build();
    wizard.show();
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) ModelNode(org.jboss.hal.dmr.ModelNode) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) AbstractConfiguration(org.jboss.hal.client.shared.sslwizard.AbstractConfiguration) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Constants(org.jboss.hal.resources.Constants) Map(java.util.Map) Message(org.jboss.hal.spi.Message) Names(org.jboss.hal.resources.Names) Operation(org.jboss.hal.dmr.Operation) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) DomGlobal.window(elemental2.dom.DomGlobal.window) Composite(org.jboss.hal.dmr.Composite) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Resources(org.jboss.hal.resources.Resources) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Host(org.jboss.hal.core.runtime.host.Host) Task(org.jboss.hal.flow.Task) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) FlowContext(org.jboss.hal.flow.FlowContext) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Constants(org.jboss.hal.resources.Constants) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) ModelNode(org.jboss.hal.dmr.ModelNode) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Example 2 with Wizard

use of org.jboss.hal.ballroom.wizard.Wizard in project console by hal.

the class PasswordWizard method show.

public void show() {
    Constants constants = resources.constants();
    Wizard.Builder<PasswordContext, PasswordState> wb = new Wizard.Builder<>(constants.setIdentityPasswordTitle(), new PasswordContext());
    wb.addStep(PasswordState.CHOOSE_PASSWORD_TYPE, new ChoosePasswordTypeStep(resources)).addStep(PasswordState.CONFIGURATION, new ConfigurePasswordStep(resources, metadata)).addStep(PasswordState.REVIEW, new ReviewPasswordStep(resources, metadata)).onBack((context, currentState) -> {
        PasswordState previous = null;
        switch(currentState) {
            case CHOOSE_PASSWORD_TYPE:
                break;
            case CONFIGURATION:
                previous = PasswordState.CHOOSE_PASSWORD_TYPE;
                break;
            case REVIEW:
                previous = PasswordState.CONFIGURATION;
                break;
            default:
                break;
        }
        return previous;
    }).onNext((context, currentState) -> {
        PasswordState next = null;
        switch(currentState) {
            case CHOOSE_PASSWORD_TYPE:
                next = PasswordState.CONFIGURATION;
                break;
            case CONFIGURATION:
                next = PasswordState.REVIEW;
                break;
            case REVIEW:
                break;
            default:
                break;
        }
        return next;
    }).onFinish((wizard, context) -> {
        ResourceAddress address = metadata.getTemplate().resolve(statementContext, selectedRealm);
        Operation operation = new Operation.Builder(address, SET_PASSWORD).param(IDENTITY, selectedIdentity).param(context.type.name, context.model).build();
        LabelBuilder labelBuilder = new LabelBuilder();
        String type = labelBuilder.label(metadata.getTemplate().lastName());
        String resourceName = type + "" + selectedRealm;
        dispatcher.execute(operation, result -> MessageEvent.fire(eventBus, Message.success(resources.messages().setIdentityPasswordSuccess(selectedIdentity, resourceName))), (operation1, failure) -> MessageEvent.fire(eventBus, Message.error(resources.messages().setIdentityPasswordError(selectedIdentity, resourceName, failure))), (operation1, exception) -> MessageEvent.fire(eventBus, Message.error(resources.messages().setIdentityPasswordError(selectedIdentity, resourceName, exception.getMessage()))));
    });
    Wizard<PasswordContext, PasswordState> wizard = wb.build();
    wizard.show();
}
Also used : IDENTITY(org.jboss.hal.dmr.ModelDescriptionConstants.IDENTITY) Operation(org.jboss.hal.dmr.Operation) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Resources(org.jboss.hal.resources.Resources) Constants(org.jboss.hal.resources.Constants) SET_PASSWORD(org.jboss.hal.dmr.ModelDescriptionConstants.SET_PASSWORD) Message(org.jboss.hal.spi.Message) Metadata(org.jboss.hal.meta.Metadata) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Constants(org.jboss.hal.resources.Constants) Operation(org.jboss.hal.dmr.Operation) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Example 3 with Wizard

use of org.jboss.hal.ballroom.wizard.Wizard in project console by hal.

the class ApplyPatchWizard method show.

public void show() {
    Messages messages = resources.messages();
    Wizard.Builder<PatchContext, PatchState> wb = new Wizard.Builder<>(messages.addResourceTitle(Names.PATCH), new PatchContext());
    checkServersState(servers -> {
        if (servers != null) {
            wb.addStep(CHECK_SERVERS, new CheckRunningServersStep(resources, servers, statementContext.selectedHost()));
        }
        wb.addStep(UPLOAD, new UploadPatchStep(resources)).addStep(CONFIGURE, new ConfigurationStep(metadata, resources)).onBack((context, currentState) -> {
            PatchState previous = null;
            switch(currentState) {
                case CHECK_SERVERS:
                    break;
                case UPLOAD:
                    previous = CHECK_SERVERS;
                    break;
                case CONFIGURE:
                    previous = UPLOAD;
                    break;
                default:
                    break;
            }
            return previous;
        }).onNext((context, currentState) -> {
            PatchState next = null;
            switch(currentState) {
                case CHECK_SERVERS:
                    next = UPLOAD;
                    break;
                case UPLOAD:
                    next = CONFIGURE;
                    break;
                case CONFIGURE:
                    break;
                default:
                    break;
            }
            return next;
        }).stayOpenAfterFinish().onFinish((wzd, context) -> {
            String name = context.file.name;
            wzd.showProgress(resources.constants().patchInProgress(), messages.patchInProgress(name));
            series(new FlowContext(progress.get()), new UploadPatch(statementContext, dispatcher, serverActions, context)).subscribe(new Outcome<FlowContext>() {

                @Override
                public void onError(FlowContext flowContext, Throwable error) {
                    wzd.showError(resources.constants().patchError(), messages.patchAddError(name, error.getMessage()), error.getMessage());
                }

                @Override
                public void onSuccess(FlowContext context) {
                    callback.execute();
                    wzd.showSuccess(resources.constants().patchSuccessful(), messages.patchSucessfullyApplied(name), messages.view(Names.PATCH), cxt -> {
                    /* nothing to do, content is already selected */
                    });
                }
            });
        });
        Wizard<PatchContext, PatchState> wizard = wb.build();
        wizard.show();
    });
}
Also used : Completable(rx.Completable) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) Messages(org.jboss.hal.resources.Messages) UPLOAD(org.jboss.hal.client.patching.wizard.PatchState.UPLOAD) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) Property(org.jboss.hal.dmr.Property) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) PATCHING_TEMPLATE(org.jboss.hal.client.patching.PatchesColumn.PATCHING_TEMPLATE) Server(org.jboss.hal.core.runtime.server.Server) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) ServerActions(org.jboss.hal.core.runtime.server.ServerActions) Operation(org.jboss.hal.dmr.Operation) CONFIGURE(org.jboss.hal.client.patching.wizard.PatchState.CONFIGURE) Wizard(org.jboss.hal.ballroom.wizard.Wizard) CHECK_SERVERS(org.jboss.hal.client.patching.wizard.PatchState.CHECK_SERVERS) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Callback(org.jboss.hal.spi.Callback) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Flow.series(org.jboss.hal.flow.Flow.series) Messages(org.jboss.hal.resources.Messages) FlowContext(org.jboss.hal.flow.FlowContext) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Example 4 with Wizard

use of org.jboss.hal.ballroom.wizard.Wizard in project console by hal.

the class ModelBrowser method add.

void add(Node<Context> parent, List<String> children) {
    if (parent.data.hasSingletons()) {
        if (parent.data.getSingletons().size() == children.size()) {
            MessageEvent.fire(eventBus, Message.warning(resources.messages().allSingletonsExist()));
        } else if (parent.data.getSingletons().size() - children.size() == 1) {
            // no need to show a wizard - find the missing singleton
            HashSet<String> singletons = Sets.newHashSet(parent.data.getSingletons());
            singletons.removeAll(children);
            String singleton = singletons.iterator().next();
            ResourceAddress singletonAddress = parent.data.getAddress().getParent().add(parent.text, singleton);
            AddressTemplate template = asGenericTemplate(parent, singletonAddress);
            String id = Ids.build(parent.id, "singleton", Ids.ADD);
            crud.addSingleton(id, singleton, template, address -> refresh(parent));
        } else {
            // open wizard to choose the singleton
            Wizard<SingletonContext, SingletonState> wizard = new Wizard.Builder<SingletonContext, SingletonState>(resources.messages().addResourceTitle(parent.text), new SingletonContext(parent, children)).addStep(CHOOSE, new ChooseSingletonStep(parent, children, resources)).addStep(CREATE, new CreateSingletonStep(parent, metadataProcessor, progress, eventBus, resources)).onBack((context, currentState) -> currentState == CREATE ? CHOOSE : null).onNext((context, currentState) -> currentState == CHOOSE ? CREATE : null).onFinish((wzrd, context) -> {
                Operation.Builder builder = new Operation.Builder(fqAddress(parent, context.singleton), ADD);
                if (context.modelNode != null) {
                    builder.payload(context.modelNode);
                }
                dispatcher.execute(builder.build(), result -> {
                    MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(parent.text, context.singleton)));
                    refresh(parent);
                });
            }).build();
            wizard.show();
        }
    } else {
        AddressTemplate template = asGenericTemplate(parent, parent.data.getAddress());
        metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {

            @Override
            public void onMetadata(Metadata metadata) {
                flattenDescription(metadata.getDescription().get(OPERATIONS).get(ADD).get(REQUEST_PROPERTIES));
                String title = new LabelBuilder().label(parent.text);
                NameItem nameItem = new NameItem();
                String id = Ids.build(parent.id, "add");
                ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(nameItem, 0).fromRequestProperties().panelForOptionalAttributes().build();
                AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(title), form, (name1, model) -> {
                    unflattenModel(model);
                    crud.add(title, nameItem.getValue(), fqAddress(parent, nameItem.getValue()), model, (n, a) -> refresh(parent));
                });
                dialog.show();
            }
        });
    }
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) IsElement(org.jboss.gwt.elemento.core.IsElement) Provider(javax.inject.Provider) Elements.a(org.jboss.gwt.elemento.core.Elements.a) Environment(org.jboss.hal.config.Environment) CHOOSE(org.jboss.hal.core.modelbrowser.SingletonState.CHOOSE) VALUE_TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE_TYPE) LoggerFactory(org.slf4j.LoggerFactory) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) Node(org.jboss.hal.ballroom.tree.Node) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CSS.modelBrowserButtons(org.jboss.hal.resources.CSS.modelBrowserButtons) HTMLElement(elemental2.dom.HTMLElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Message(org.jboss.hal.spi.Message) FinishReset(org.jboss.hal.ballroom.form.Form.FinishReset) SERVER_GROUP(org.jboss.hal.dmr.ModelDescriptionConstants.SERVER_GROUP) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) CrudOperations(org.jboss.hal.core.CrudOperations) Collections.emptyList(java.util.Collections.emptyList) LayoutBuilder.row(org.jboss.hal.ballroom.LayoutBuilder.row) MARGIN_BIG(org.jboss.hal.ballroom.Skeleton.MARGIN_BIG) CSS(org.jboss.hal.resources.CSS) Skeleton.applicationOffset(org.jboss.hal.ballroom.Skeleton.applicationOffset) EventType.click(org.jboss.gwt.elemento.core.EventType.click) STRING(org.jboss.hal.dmr.ModelDescriptionConstants.STRING) CSS.btnGroup(org.jboss.hal.resources.CSS.btnGroup) Sets(com.google.common.collect.Sets) Tree(org.jboss.hal.ballroom.tree.Tree) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) MetadataProcessor(org.jboss.hal.meta.processing.MetadataProcessor) CSS.tmTagRemove(org.jboss.hal.resources.CSS.tmTagRemove) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) CSS.tagManagerContainer(org.jboss.hal.resources.CSS.tagManagerContainer) ModelNodeHelper(org.jboss.hal.dmr.ModelNodeHelper) PROFILE(org.jboss.hal.dmr.ModelDescriptionConstants.PROFILE) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) MARGIN_SMALL(org.jboss.hal.ballroom.Skeleton.MARGIN_SMALL) ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) Elements.div(org.jboss.gwt.elemento.core.Elements.div) TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.TYPE) SELECTED_GROUP(org.jboss.hal.meta.StatementContext.Expression.SELECTED_GROUP) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) ADD(org.jboss.hal.dmr.ModelDescriptionConstants.ADD) CSS.btnDefault(org.jboss.hal.resources.CSS.btnDefault) LayoutBuilder.column(org.jboss.hal.ballroom.LayoutBuilder.column) CSS.tmTag(org.jboss.hal.resources.CSS.tmTag) CSS.clickable(org.jboss.hal.resources.CSS.clickable) Stack(java.util.Stack) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Property(org.jboss.hal.dmr.Property) OPERATIONS(org.jboss.hal.dmr.ModelDescriptionConstants.OPERATIONS) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) REQUEST_PROPERTIES(org.jboss.hal.dmr.ModelDescriptionConstants.REQUEST_PROPERTIES) CSS.modelBrowserContent(org.jboss.hal.resources.CSS.modelBrowserContent) Elements.button(org.jboss.gwt.elemento.core.Elements.button) CSS.tagManagerTag(org.jboss.hal.resources.CSS.tagManagerTag) Logger(org.slf4j.Logger) Operation(org.jboss.hal.dmr.Operation) CREATE(org.jboss.hal.core.modelbrowser.SingletonState.CREATE) Ids(org.jboss.hal.resources.Ids) OBJECT(org.jboss.hal.dmr.ModelDescriptionConstants.OBJECT) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) MODEL_BROWSER_ROOT(org.jboss.hal.resources.Ids.MODEL_BROWSER_ROOT) CSS.btn(org.jboss.hal.resources.CSS.btn) SelectionContext(org.jboss.hal.ballroom.tree.SelectionContext) CSS.vh(org.jboss.hal.resources.CSS.vh) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) SELECTED_PROFILE(org.jboss.hal.meta.StatementContext.Expression.SELECTED_PROFILE) HTMLButtonElement(elemental2.dom.HTMLButtonElement) Collections(java.util.Collections) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Elements(org.jboss.gwt.elemento.core.Elements) Form(org.jboss.hal.ballroom.form.Form) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Wizard(org.jboss.hal.ballroom.wizard.Wizard) HashSet(java.util.HashSet)

Example 5 with Wizard

use of org.jboss.hal.ballroom.wizard.Wizard 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();
}
Also used : Dialog(org.jboss.hal.ballroom.dialog.Dialog) LoadContent(org.jboss.hal.client.deployment.DeploymentTasks.LoadContent) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) Constraint(org.jboss.hal.meta.security.Constraint) ItemActionFactory(org.jboss.hal.core.finder.ItemActionFactory) StatementContext(org.jboss.hal.meta.StatementContext) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ManagementModel(org.jboss.hal.meta.ManagementModel) CheckDeployment(org.jboss.hal.client.deployment.DeploymentTasks.CheckDeployment) CreateEmptyDialog(org.jboss.hal.client.deployment.dialog.CreateEmptyDialog) AuthorisationDecision(org.jboss.hal.meta.security.AuthorisationDecision) UploadOrReplace(org.jboss.hal.client.deployment.DeploymentTasks.UploadOrReplace) DeployContentDialog1(org.jboss.hal.client.deployment.dialog.DeployContentDialog1) Column(org.jboss.hal.spi.Column) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) Metadata(org.jboss.hal.meta.Metadata) Places(org.jboss.hal.core.mvp.Places) Names(org.jboss.hal.resources.Names) Collectors.toSet(java.util.stream.Collectors.toSet) UploadContentStep(org.jboss.hal.client.deployment.wizard.UploadContentStep) DeploymentState(org.jboss.hal.client.deployment.wizard.DeploymentState) DeploymentContext(org.jboss.hal.client.deployment.wizard.DeploymentContext) AddUnmanagedDialog(org.jboss.hal.client.deployment.dialog.AddUnmanagedDialog) Set(java.util.Set) Collectors.joining(java.util.stream.Collectors.joining) NAMES(org.jboss.hal.client.deployment.wizard.DeploymentState.NAMES) List(java.util.List) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) ROOT_ADDRESS(org.jboss.hal.client.deployment.ContentColumn.ROOT_ADDRESS) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) SecurityContextRegistry(org.jboss.hal.meta.security.SecurityContextRegistry) CLEAR_SELECTION(org.jboss.hal.core.finder.FinderColumn.RefreshMode.CLEAR_SELECTION) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) ServerGroupDeployment(org.jboss.hal.core.deployment.ServerGroupDeployment) ModelNode(org.jboss.hal.dmr.ModelNode) MessageEvent.fire(org.jboss.hal.spi.MessageEvent.fire) MessageEvent(org.jboss.hal.spi.MessageEvent) Constraints(org.jboss.hal.meta.security.Constraints) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) JsHelper(org.jboss.hal.js.JsHelper) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) CONTENT_ADDRESS(org.jboss.hal.client.deployment.ContentColumn.CONTENT_ADDRESS) AddUnmanagedDeployment(org.jboss.hal.client.deployment.DeploymentTasks.AddUnmanagedDeployment) UPLOAD(org.jboss.hal.client.deployment.wizard.DeploymentState.UPLOAD) SERVER_GROUP_DEPLOYMENT_ADDRESS(org.jboss.hal.client.deployment.ContentColumn.SERVER_GROUP_DEPLOYMENT_ADDRESS) RESTORE_SELECTION(org.jboss.hal.core.finder.FinderColumn.RefreshMode.RESTORE_SELECTION) FinderColumn(org.jboss.hal.core.finder.FinderColumn) ColumnActionFactory(org.jboss.hal.core.finder.ColumnActionFactory) Requires(org.jboss.hal.spi.Requires) CompositeResult(org.jboss.hal.dmr.CompositeResult) Operation(org.jboss.hal.dmr.Operation) NamesStep(org.jboss.hal.client.deployment.wizard.NamesStep) Ids(org.jboss.hal.resources.Ids) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) ItemMonitor(org.jboss.hal.core.finder.ItemMonitor) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Content(org.jboss.hal.core.deployment.Content) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) Strings(org.jboss.hal.resources.Strings) UploadElement(org.jboss.hal.client.shared.uploadwizard.UploadElement) Elements.span(org.jboss.gwt.elemento.core.Elements.span) DeploymentState(org.jboss.hal.client.deployment.wizard.DeploymentState) CheckDeployment(org.jboss.hal.client.deployment.DeploymentTasks.CheckDeployment) Metadata(org.jboss.hal.meta.Metadata) FlowContext(org.jboss.hal.flow.FlowContext) UploadContentStep(org.jboss.hal.client.deployment.wizard.UploadContentStep) DeploymentContext(org.jboss.hal.client.deployment.wizard.DeploymentContext) UploadOrReplace(org.jboss.hal.client.deployment.DeploymentTasks.UploadOrReplace) Outcome(org.jboss.hal.flow.Outcome) NamesStep(org.jboss.hal.client.deployment.wizard.NamesStep) Wizard(org.jboss.hal.ballroom.wizard.Wizard)

Aggregations

Wizard (org.jboss.hal.ballroom.wizard.Wizard)8 Operation (org.jboss.hal.dmr.Operation)8 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)8 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)8 Resources (org.jboss.hal.resources.Resources)8 Provider (javax.inject.Provider)7 Environment (org.jboss.hal.config.Environment)7 Flow.series (org.jboss.hal.flow.Flow.series)7 FlowContext (org.jboss.hal.flow.FlowContext)7 Progress (org.jboss.hal.flow.Progress)7 Metadata (org.jboss.hal.meta.Metadata)7 StatementContext (org.jboss.hal.meta.StatementContext)7 EventBus (com.google.web.bindery.event.shared.EventBus)6 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)6 Outcome (org.jboss.hal.flow.Outcome)6 Names (org.jboss.hal.resources.Names)6 Message (org.jboss.hal.spi.Message)6 MessageEvent (org.jboss.hal.spi.MessageEvent)6 List (java.util.List)5 HTMLElement (elemental2.dom.HTMLElement)4