Search in sources :

Example 6 with MessagePart

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"));
    }
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) JsonObject(javax.json.JsonObject) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with MessagePart

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());
    }
}
Also used : MessagePart(org.glassfish.api.ActionReport.MessagePart) Properties(java.util.Properties) Map(java.util.Map)

Example 8 with MessagePart

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;
}
Also used : RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MessagePart(org.glassfish.api.ActionReport.MessagePart) XmlMap(org.glassfish.admin.rest.utils.xml.XmlMap) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ActionReporter(com.sun.enterprise.v3.common.ActionReporter)

Example 9 with MessagePart

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());
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) MessagePart(org.glassfish.api.ActionReport.MessagePart) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) AdminCommandContext(org.glassfish.api.admin.AdminCommandContext) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Example 10 with MessagePart

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());
}
Also used : AdminCommandContextImpl(org.glassfish.api.admin.AdminCommandContextImpl) MessagePart(org.glassfish.api.ActionReport.MessagePart) PropsFileActionReporter(com.sun.enterprise.v3.common.PropsFileActionReporter) Test(org.junit.Test) ConfigApiTest(org.glassfish.tests.utils.ConfigApiTest)

Aggregations

MessagePart (org.glassfish.api.ActionReport.MessagePart)25 ParameterMap (org.glassfish.api.admin.ParameterMap)11 Test (org.junit.Test)11 ConfigApiTest (org.glassfish.tests.utils.ConfigApiTest)9 PropsFileActionReporter (com.sun.enterprise.v3.common.PropsFileActionReporter)7 AdminCommandContextImpl (org.glassfish.api.admin.AdminCommandContextImpl)7 ArrayList (java.util.ArrayList)5 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)5 Properties (java.util.Properties)4 ActionReport (org.glassfish.api.ActionReport)4 HashMap (java.util.HashMap)3 ActionReporter (com.sun.enterprise.v3.common.ActionReporter)2 Map (java.util.Map)2 JsonObject (javax.json.JsonObject)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 XmlMap (org.glassfish.admin.rest.utils.xml.XmlMap)2 CommandInvocation (org.glassfish.api.admin.CommandRunner.CommandInvocation)2 RemoteCLICommand (com.sun.enterprise.admin.cli.remote.RemoteCLICommand)1 Resource (com.sun.enterprise.config.serverbeans.Resource)1 IOException (java.io.IOException)1