use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ActionReportJsonProprietaryReader method fillSubMessages.
/**
* Fills all messages below top_message of an action report
* @param mp
* @param json
* @throws JsonException
*/
private static void fillSubMessages(final ActionReport.MessagePart mp, final JsonArray json) throws JsonException {
if (json == null) {
return;
}
for (int i = 0; i < json.size(); i++) {
JsonObject subJson = json.getJsonObject(i);
MessagePart child = mp.addChild();
child.setMessage(subJson.getString("message", null));
Properties props = (Properties) extractMap(subJson.getJsonObject("properties"), new Properties());
for (Map.Entry entry : props.entrySet()) {
Object entryValue = entry.getValue();
if (entryValue instanceof JsonString) {
child.addProperty(String.valueOf(entry.getKey()), ((JsonString) entry.getValue()).getString());
} else {
child.addProperty(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
child.addProperty(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
}
fillSubMessages(child, subJson.getJsonArray("children"));
}
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class InstanceRestCommandExecutor method copyMessagePart.
private void copyMessagePart(MessagePart source, MessagePart dest) {
if (source == null || dest == null) {
return;
}
dest.setMessage(source.getMessage());
dest.setChildrenType(source.getChildrenType());
Properties props = source.getProps();
if (props != null) {
for (Map.Entry<Object, Object> entry : props.entrySet()) {
dest.addProperty((String) entry.getKey(), (String) entry.getValue());
}
}
for (MessagePart chmp : source.getChildren()) {
copyMessagePart(chmp, dest.addChild());
}
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ActionReportXmlProvider method processReport.
protected XmlObject processReport(ActionReporter ar) {
XmlMap result = new XmlMap("map");
result.put("message", (ar instanceof RestActionReporter) ? ((RestActionReporter) ar).getCombinedMessage() : ar.getMessage());
result.put("command", ar.getActionDescription());
result.put("exit_code", ar.getActionExitCode().toString());
Properties properties = ar.getTopMessagePart().getProps();
if ((properties != null) && (!properties.isEmpty())) {
result.put("properties", new XmlMap("properties", properties));
}
Properties extraProperties = ar.getExtraProperties();
if ((extraProperties != null) && (!extraProperties.isEmpty())) {
result.put("extraProperties", getExtraProperties(result, extraProperties));
}
List<MessagePart> children = ar.getTopMessagePart().getChildren();
if ((children != null) && (!children.isEmpty())) {
result.put("children", processChildren(children));
}
List<ActionReporter> subReports = ar.getSubActionsReport();
if ((subReports != null) && (!subReports.isEmpty())) {
result.put("subReports", processSubReports(subReports));
}
return result;
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ListJdbcResourcesTest method testExecuteSuccessListOriginal.
/**
* Test of execute method, of class ListJdbcResources.
* list-jdbc-resources
*/
@Test
public void testExecuteSuccessListOriginal() {
// List the original set of JDBC Resources
// Get an instance of the ListJdbcResources command
ListJdbcResources listCommand = habitat.getService(ListJdbcResources.class);
AdminCommandContext context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
assertEquals(origNum, list.size());
// Check the exit code is SUCCESS
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
use of org.glassfish.api.ActionReport.MessagePart in project Payara by payara.
the class ListJdbcResourcesTest method testExecuteSuccessValidTargetOperand.
/**
* Test of execute method, of class ListJdbcResource.
* list-jdbc-resources server
*/
@Test
public void testExecuteSuccessValidTargetOperand() {
// List the original set of JDBC Resources
// Get an instance of the ListJdbcResources command
listCommand = habitat.getService(ListJdbcResources.class);
parameters.add("DEFAULT", "server");
context = new AdminCommandContextImpl(LogDomains.getLogger(ListJdbcResourcesTest.class, LogDomains.ADMIN_LOGGER), new PropsFileActionReporter());
// Call CommandRunnerImpl.doCommand(..) to execute the command
cr.getCommandInvocation("list-jdbc-resources", context.getActionReport(), adminSubject()).parameters(parameters).execute(listCommand);
List<MessagePart> list = context.getActionReport().getTopMessagePart().getChildren();
assertEquals(origNum, list.size());
// Check the exit code is Success
assertEquals(ActionReport.ExitCode.SUCCESS, context.getActionReport().getActionExitCode());
}
Aggregations