use of org.jboss.hal.resources.Resources 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();
}
use of org.jboss.hal.resources.Resources in project console by hal.
the class DeploymentPresenter method reload.
@Override
protected void reload() {
ResourceAddress address = deploymentAddress();
// task 1: read sessions ids, servlets and websockets
Operation readResourceOp = new Operation.Builder(address, READ_RESOURCE_OPERATION).param(INCLUDE_RUNTIME, true).param(RECURSIVE, true).build();
Operation listSessionsOp = new Operation.Builder(address, LIST_SESSIONS).build();
Task<FlowContext> task1 = context -> dispatcher.execute(new Composite(readResourceOp, listSessionsOp)).doOnSuccess((CompositeResult result) -> {
ModelNode readResourceResult = result.step(0).get(RESULT);
List<NamedNode> servlets = asNamedNodes(failSafePropertyList(readResourceResult, SERVLET));
List<NamedNode> websockets = asNamedNodes(failSafePropertyList(readResourceResult, WEBSOCKET));
// sorted session ids (important for step 2!)
ModelNode listSessionsResult = result.step(1).get(RESULT);
List<String> sessionIds = listSessionsResult.isDefined() ? listSessionsResult.asList().stream().map(ModelNode::asString).sorted().collect(toList()) : Collections.emptyList();
context.set(SERVLETS, servlets);
context.set(WEBSOCKETS, websockets);
context.set(SESSION_IDS, sessionIds);
}).toCompletable();
// task 2: read session creation and last access times
Task<FlowContext> task2 = context -> {
List<String> sessionIds = context.get(SESSION_IDS);
if (sessionIds.isEmpty()) {
context.set(SESSIONS, Collections.emptyList());
return Completable.complete();
} else {
List<Operation> operations = new ArrayList<>();
for (String id : sessionIds) {
operations.add(new Operation.Builder(address, GET_SESSION_CREATION_TIME).param(SESSION_ID, id).build());
operations.add(new Operation.Builder(address, GET_SESSION_LAST_ACCESSED_TIME).param(SESSION_ID, id).build());
}
return dispatcher.execute(new Composite(operations)).doOnSuccess((CompositeResult result) -> {
int i = 0;
List<Session> sessions = new ArrayList<>();
for (String sessionId : sessionIds) {
ModelNode modelNode = new ModelNode();
if (result.step(i).isDefined() && result.step(i).get(RESULT).isDefined()) {
modelNode.get(CREATION_TIME).set(result.step(i).get(RESULT));
}
i++;
if (result.step(i).isDefined() && result.step(i).get(RESULT).isDefined()) {
modelNode.get(LAST_ACCESSED_TIME).set(result.step(i).get(RESULT));
}
i++;
sessions.add(new Session(sessionId, modelNode));
}
context.set(SESSIONS, sessions);
}).toCompletable();
}
};
series(new FlowContext(progress.get()), task1, task2).subscribe(new SuccessfulOutcome<FlowContext>(getEventBus(), resources) {
@Override
public void onSuccess(FlowContext context) {
List<Session> sessions = context.get(SESSIONS);
List<NamedNode> servlets = context.get(SERVLETS);
List<NamedNode> websockets = context.get(WEBSOCKETS);
getView().updateSessions(sessions);
getView().updateServlets(servlets);
getView().updateWebsockets(websockets);
}
});
}
use of org.jboss.hal.resources.Resources in project console by hal.
the class FooterPresenter method onMacroRecording.
void onMacroRecording() {
if (recording) {
recording = false;
getView().stopRecording();
getEventBus().fireEvent(Recording.stop());
} else {
new MacroOptionsDialog(macros, resources, options -> {
MessageEvent.fire(getEventBus(), Message.info(resources.messages().recordingStarted()));
getEventBus().fireEvent(Recording.start(options));
getView().startRecording();
getView().steps(0);
recording = true;
}).show();
}
}
use of org.jboss.hal.resources.Resources in project console by hal.
the class CrudOperations method readChildren.
/**
* Read multiple different child resources using a composite operation. The steps in the composite result map to the
* position of the resource in the {@code resources} collection.
*
* @param address the fq address for the {@code read-children-resource} operation
* @param resources the child resources (not human readable, but the actual child resource name!)
* @param depth the depth used for the {@code recursive-depth} parameter
* @param callback the callback which gets the composite result
*/
@JsIgnore
public void readChildren(ResourceAddress address, Iterable<String> resources, int depth, ReadCompositeCallback callback) {
List<Operation> operations = stream(resources.spliterator(), false).map(resource -> new Operation.Builder(address, READ_CHILDREN_RESOURCES_OPERATION).param(CHILD_TYPE, resource).param(RECURSIVE_DEPTH, depth).build()).collect(toList());
dispatcher.execute(new Composite(operations), callback::execute);
}
Aggregations