Search in sources :

Example 6 with Dialog

use of org.jboss.hal.ballroom.dialog.Dialog in project console by hal.

the class StoresPresenter method verifyRenewCertificate.

void verifyRenewCertificate(Metadata metadata, String name, String alias) {
    metadata = metadata.forOperation(SHOULD_RENEW_CERTIFICATE);
    String id = Ids.build(KEY_STORE, SHOULD_RENEW_CERTIFICATE, FORM);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).build();
    form.setSaveCallback((form1, changedValues) -> {
        ResourceAddress address = KEY_STORE_TEMPLATE.resolve(statementContext, name);
        Operation operation = new Operation.Builder(address, SHOULD_RENEW_CERTIFICATE).payload(form.getModel()).build();
        dispatcher.execute(operation, result -> {
            int days = result.get("days-to-expiry").asInt();
            Date dueDate = new Date();
            CalendarUtil.addDaysToDate(dueDate, days);
            HTMLElement content;
            if (days < 1) {
                Alert warning = new Alert(Icons.WARNING, resources.messages().certificateExpired(alias));
                content = div().add(warning).element();
            } else {
                SafeHtml description = resources.messages().certificateShouldRenew(days, alias, Format.mediumDateTime(dueDate));
                content = p().innerHtml(description).element();
            }
            new Dialog.Builder(resources.constants().verifyRenewCertificate()).primary(resources.constants().ok(), null).size(Dialog.Size.MEDIUM).add(content).build().show();
        }, (operation1, failure) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().verifyRenewError(alias, name, failure))), (operation1, ex) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().verifyRenewError(alias, name, ex.getMessage()))));
    });
    Dialog dialog = new Dialog.Builder(resources.constants().verifyRenewCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().verifyRenew(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
    dialog.registerAttachable(form);
    dialog.show();
    ModelNode model = new ModelNode();
    model.get(ALIAS).set(alias);
    form.getFormItem(ALIAS).setEnabled(false);
    form.edit(model);
}
Also used : HTMLElement(elemental2.dom.HTMLElement) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Date(java.util.Date) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) Alert(org.jboss.hal.ballroom.Alert) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 7 with Dialog

use of org.jboss.hal.ballroom.dialog.Dialog in project console by hal.

the class StoresPresenter method importCertificate.

void importCertificate(Metadata metadata, String name) {
    AddressTemplate template = metadata.getTemplate();
    String resource = Names.KEY_STORE + SPACE + name;
    metadata = metadata.forOperation(IMPORT_CERTIFICATE);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), IMPORT_CERTIFICATE), metadata).build();
    form.setSaveCallback((form1, changedValues) -> {
        ModelNode payload = form.getModel();
        String path = payload.get(PATH).asString();
        if (!payload.hasDefined(VALIDATE)) {
            payload.get(VALIDATE).set(false);
        }
        ResourceAddress address = template.resolve(statementContext, name);
        String alias = payload.get(ALIAS).asString();
        List<Task<FlowContext>> tasks = new ArrayList<>();
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(address, IMPORT_CERTIFICATE).payload(payload).build();
            return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().importCertificateError(alias, path, resource, ex.getMessage())))).toCompletable();
        });
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
            return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().storeError(resource, ex.getMessage())))).toCompletable();
        });
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
            return dispatcher.execute(operation).doOnError(ex -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasesError(resource, ex.getMessage())))).toCompletable();
        });
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                MessageEvent.fire(getEventBus(), Message.success(resources.messages().importCertificateSuccess(alias, path, resource)));
            }

            @Override
            public void onError(FlowContext context, Throwable ex) {
                MessageEvent.fire(getEventBus(), Message.error(resources.messages().removeAliasError(alias, resource, ex.getMessage())));
            }
        });
    });
    Dialog dialog = new Dialog.Builder(resources.constants().importCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().importt(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
    dialog.registerAttachable(form);
    dialog.show();
    form.edit(new ModelNode());
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) Date(java.util.Date) StatementContext(org.jboss.hal.meta.StatementContext) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Icons(org.jboss.hal.resources.Icons) Elements.p(org.jboss.gwt.elemento.core.Elements.p) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) FinderPath(org.jboss.hal.core.finder.FinderPath) FORM(org.jboss.hal.resources.Ids.FORM) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) AddressTemplates(org.jboss.hal.client.runtime.subsystem.elytron.AddressTemplates) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) CalendarUtil(com.google.gwt.user.datepicker.client.CalendarUtil) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) Elements.div(org.jboss.gwt.elemento.core.Elements.div) Alert(org.jboss.hal.ballroom.Alert) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) Requires(org.jboss.hal.spi.Requires) CompositeResult(org.jboss.hal.dmr.CompositeResult) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Consumer(java.util.function.Consumer) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) Format(org.jboss.hal.ballroom.Format) SuggestCapabilitiesAutoComplete(org.jboss.hal.ballroom.autocomplete.SuggestCapabilitiesAutoComplete) NamedNode(org.jboss.hal.dmr.NamedNode) Collections(java.util.Collections) Form(org.jboss.hal.ballroom.form.Form) Task(org.jboss.hal.flow.Task) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) FlowContext(org.jboss.hal.flow.FlowContext) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 8 with Dialog

use of org.jboss.hal.ballroom.dialog.Dialog in project console by hal.

the class StoresPresenter method generateKeyPair.

void generateKeyPair(Metadata metadata, String name) {
    AddressTemplate template = metadata.getTemplate();
    String resource = Names.KEY_STORE + SPACE + name;
    metadata = metadata.forOperation(GENERATE_KEY_PAIR);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), GENERATE_KEY_PAIR), metadata).build();
    form.setSaveCallback((form1, changedValues) -> {
        ResourceAddress address = template.resolve(statementContext, name);
        String alias = form.getModel().get(ALIAS).asString();
        List<Task<FlowContext>> tasks = new ArrayList<>();
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(address, GENERATE_KEY_PAIR).payload(form.getModel()).build();
            return dispatcher.execute(operation).toCompletable();
        });
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
            return dispatcher.execute(operation).toCompletable();
        });
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
            return dispatcher.execute(operation).toCompletable();
        });
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                MessageEvent.fire(getEventBus(), Message.success(resources.messages().generateKeyPairSuccess(alias, resource)));
            }

            @Override
            public void onError(FlowContext context, Throwable ex) {
                MessageEvent.fire(getEventBus(), Message.error(resources.messages().generateKeyPairError(alias, resource, ex.getMessage())));
            }
        });
    });
    Dialog dialog = new Dialog.Builder(resources.constants().generateKeyPair()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().generate(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
    dialog.registerAttachable(form);
    dialog.show();
    form.edit(new ModelNode());
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) Task(org.jboss.hal.flow.Task) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) FlowContext(org.jboss.hal.flow.FlowContext) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 9 with Dialog

use of org.jboss.hal.ballroom.dialog.Dialog in project console by hal.

the class StoresPresenter method changeAlias.

void changeAlias(Metadata metadata, String name, String alias, Consumer<List<ModelNode>> callback) {
    AddressTemplate template = metadata.getTemplate();
    String resource = Names.KEY_STORE + SPACE + name;
    metadata = metadata.forOperation(CHANGE_ALIAS);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), CHANGE_ALIAS), metadata).build();
    form.setSaveCallback((form1, changedValues) -> {
        String newAlias = form.getModel().get("new-alias").asString();
        ResourceAddress address = template.resolve(statementContext, name);
        List<Task<FlowContext>> tasks = new ArrayList<>();
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(address, CHANGE_ALIAS).payload(form.getModel()).build();
            return dispatcher.execute(operation).toCompletable();
        });
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(KEY_STORE_TEMPLATE.resolve(statementContext, name), STORE).build();
            return dispatcher.execute(operation).toCompletable();
        });
        tasks.add(flowContext -> {
            Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
            return dispatcher.execute(operation).doOnSuccess(flowContext::push).toCompletable();
        });
        series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {

            @Override
            public void onSuccess(FlowContext flowContext) {
                MessageEvent.fire(getEventBus(), Message.success(resources.messages().changeAliasSuccess(alias, newAlias, resource)));
                ModelNode aliases = flowContext.pop();
                if (aliases.isDefined()) {
                    callback.accept(aliases.asList());
                } else {
                    callback.accept(Collections.emptyList());
                }
            }

            @Override
            public void onError(FlowContext context, Throwable ex) {
                MessageEvent.fire(getEventBus(), Message.error(resources.messages().changeAliasError(alias, newAlias, resource, ex.getMessage())));
            }
        });
    });
    ModelNode model = new ModelNode();
    model.get(ALIAS).set(alias);
    form.getFormItem(ALIAS).setEnabled(false);
    Dialog dialog = new Dialog.Builder(resources.constants().changeAlias()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().change(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
    dialog.registerAttachable(form);
    dialog.show();
    form.edit(model);
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) Task(org.jboss.hal.flow.Task) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ArrayList(java.util.ArrayList) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) FlowContext(org.jboss.hal.flow.FlowContext) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 10 with Dialog

use of org.jboss.hal.ballroom.dialog.Dialog in project console by hal.

the class StoresPresenter method exportCertificate.

void exportCertificate(Metadata metadata, String name, String alias) {
    AddressTemplate template = metadata.getTemplate();
    String resource = Names.KEY_STORE + SPACE + name;
    metadata = metadata.forOperation(EXPORT_CERTIFICATE);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(template.lastName(), EXPORT_CERTIFICATE), metadata).build();
    form.setSaveCallback((form1, changedValues) -> {
        ResourceAddress address = template.resolve(statementContext, name);
        Operation operation = new Operation.Builder(address, EXPORT_CERTIFICATE).payload(form.getModel()).build();
        String path = form.getModel().get(PATH).asString();
        dispatcher.execute(operation, result -> MessageEvent.fire(getEventBus(), Message.success(resources.messages().exportCertificateSuccess(alias, path, resource))), (op, failure) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().exportCertificateError(alias, path, resource, failure))), (op, ex) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().exportCertificateError(alias, path, resource, ex.getMessage()))));
    });
    ModelNode model = new ModelNode();
    model.get(ALIAS).set(alias);
    form.getFormItem(ALIAS).setEnabled(false);
    Dialog dialog = new Dialog.Builder(resources.constants().exportCertificate()).add(p().textContent(metadata.getDescription().getDescription()).element()).add(form.element()).primary(resources.constants().export(), form::save).size(Dialog.Size.MEDIUM).closeOnEsc(true).cancel().build();
    dialog.registerAttachable(form);
    dialog.show();
    form.edit(model);
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Operation(org.jboss.hal.dmr.Operation) ModelNode(org.jboss.hal.dmr.ModelNode) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm)

Aggregations

Dialog (org.jboss.hal.ballroom.dialog.Dialog)30 ModelNode (org.jboss.hal.dmr.ModelNode)26 Operation (org.jboss.hal.dmr.Operation)23 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)22 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)21 LabelBuilder (org.jboss.hal.ballroom.LabelBuilder)18 Metadata (org.jboss.hal.meta.Metadata)17 AddResourceDialog (org.jboss.hal.core.mbui.dialog.AddResourceDialog)15 AddressTemplate (org.jboss.hal.meta.AddressTemplate)12 FlowContext (org.jboss.hal.flow.FlowContext)11 Form (org.jboss.hal.ballroom.form.Form)9 Ids (org.jboss.hal.resources.Ids)9 Resources (org.jboss.hal.resources.Resources)9 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)8 EventBus (com.google.web.bindery.event.shared.EventBus)8 Inject (javax.inject.Inject)8 Provider (javax.inject.Provider)8 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)8 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)8 Progress (org.jboss.hal.flow.Progress)8