use of org.jboss.hal.dmr.ResourceCheck in project console by hal.
the class SecurityDomainPresenter method addModule.
void addModule(Module module) {
// first check for (and add if necessary) the intermediate singleton
// then add the final resource
AddressTemplate singletonTemplate = SELECTED_SECURITY_DOMAIN_TEMPLATE.append(module.singleton);
series(new FlowContext(progress.get()), new ResourceCheck(dispatcher, singletonTemplate.resolve(statementContext)), context -> {
int status = context.pop();
if (status == 200) {
return Completable.complete();
} else {
Operation operation = new Operation.Builder(singletonTemplate.resolve(statementContext), ADD).build();
return dispatcher.execute(operation).toCompletable();
}
}).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext context) {
AddressTemplate metadataTemplate = SECURITY_DOMAIN_TEMPLATE.append(module.singleton).append(module.resource + EQ_WILDCARD);
AddressTemplate selectionTemplate = SELECTED_SECURITY_DOMAIN_TEMPLATE.append(module.singleton).append(module.resource + EQ_WILDCARD);
Metadata metadata = metadataRegistry.lookup(metadataTemplate);
AddResourceDialog dialog = new AddResourceDialog(module.id, resources.messages().addResourceTitle(module.type), metadata, (name, modelNode) -> {
ResourceAddress address = selectionTemplate.resolve(statementContext, name);
crud.add(module.type, name, address, modelNode, (n, a) -> reload());
});
dialog.show();
}
});
}
use of org.jboss.hal.dmr.ResourceCheck in project console by hal.
the class CacheColumn method addCache.
private void addCache(CacheType cacheType) {
Metadata metadata = metadataRegistry.lookup(cacheType.template);
AddResourceDialog dialog = new AddResourceDialog(Ids.build(cacheType.baseId, Ids.ADD), resources.messages().addResourceTitle(cacheType.type), metadata, (name, model) -> {
String cacheContainer = findCacheContainer(getFinder().getContext().getPath());
ResourceAddress address = cacheType.template.resolve(statementContext, cacheContainer, name);
if (cacheType.equals(CacheType.LOCAL)) {
crud.add(cacheType.type, name, address, model, (n, a) -> refresh(Ids.build(cacheType.baseId, name)));
} else {
ResourceAddress jgroupsAddress = AddressTemplates.TRANSPORT_JGROUPS_TEMPLATE.resolve(statementContext, cacheContainer);
ResourceCheck check = new ResourceCheck(dispatcher, jgroupsAddress);
Task<FlowContext> add = context -> {
Operation addJgroups = new Operation.Builder(jgroupsAddress, ADD).build();
int status = context.pop();
if (status == 200) {
context.set(JGROUPS_ADDITION_STATUS, false);
return Completable.complete();
} else {
context.set(JGROUPS_ADDITION_STATUS, true);
return dispatcher.execute(addJgroups).toCompletable();
}
};
series(new FlowContext(progress.get()), check, add).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
if (context.get(JGROUPS_ADDITION_STATUS).equals(true)) {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.TRANSPORT, Names.JGROUPS)));
}
crud.add(cacheType.type, name, address, model, (n, a) -> refresh(Ids.build(cacheType.baseId, name)));
}
});
}
});
dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
dialog.show();
}
use of org.jboss.hal.dmr.ResourceCheck in project console by hal.
the class DestinationPresenter method addSecuritySettingRole.
void addSecuritySettingRole() {
Metadata metadata = metadataRegistry.lookup(ROLE_TEMPLATE);
TextBoxItem patternItem = new TextBoxItem(PATTERN, resources.constants().pattern());
patternItem.setRequired(true);
TextBoxItem roleItem = new TextBoxItem(ROLE, resources.constants().role());
roleItem.setRequired(true);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.MESSAGING_SECURITY_SETTING_ROLE_ADD, metadata).unboundFormItem(patternItem, 0).unboundFormItem(roleItem, 1).fromRequestProperties().requiredOnly().build();
new AddResourceDialog(Names.SECURITY_SETTING, form, (name, model) -> {
String pattern = patternItem.getValue();
ResourceAddress securitySettingAddress = SELECTED_SERVER_TEMPLATE.append(SECURITY_SETTING + EQUALS + pattern).resolve(statementContext);
ResourceAddress roleAddress = SELECTED_SERVER_TEMPLATE.append(SECURITY_SETTING + EQUALS + pattern).append(ROLE + EQUALS + roleItem.getValue()).resolve(statementContext);
ResourceCheck check = new ResourceCheck(dispatcher, securitySettingAddress);
Task<FlowContext> add = context -> {
Operation addSecuritySetting = new Operation.Builder(securitySettingAddress, ADD).build();
Operation addRole = new Operation.Builder(roleAddress, ADD).payload(model).build();
int status = context.pop();
if (status == 404) {
return dispatcher.execute(new Composite(addSecuritySetting, addRole)).toCompletable();
} else {
return dispatcher.execute(addRole).toCompletable();
}
};
series(new FlowContext(progress.get()), check, add).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().addResourceSuccess(Names.SECURITY_SETTING, pattern + "/" + name)));
reload();
}
});
}).show();
}
Aggregations