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);
}
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());
}
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());
}
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);
}
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);
}
Aggregations