use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class CompositeResource method launchDetachedCommand.
protected URI launchDetachedCommand(String command, ParameterMap parameters) {
CommandRunner cr = Globals.getDefaultHabitat().getService(CommandRunner.class);
final RestActionReporter ar = new RestActionReporter();
final CommandRunner.CommandInvocation commandInvocation = cr.getCommandInvocation(command, ar, getSubject()).parameters(parameters);
final String jobId = DetachedCommandHelper.invokeAsync(commandInvocation);
return getUri("jobs/id/" + jobId);
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class ActionReportResultHtmlProvider method processReport.
protected String processReport(ActionReporter ar) {
StringBuilder result = new StringBuilder();
String des = ar.getActionDescription();
// check for no description, make it blank
if (des == null) {
des = "";
}
final String message = ResourceUtil.encodeString((ar instanceof RestActionReporter) ? ((RestActionReporter) ar).getCombinedMessage() : ar.getMessage());
if (message != null) {
result.append("<h2>").append(des).append(" output:</h2><h3>").append("<pre>").append(message).append("</pre>").append("</h3>");
}
if (ar.getActionExitCode() != ExitCode.SUCCESS) {
result.append("<h3>Exit Code: ").append(ar.getActionExitCode().toString()).append("</h3>");
}
Properties properties = ar.getTopMessagePart().getProps();
if (!properties.isEmpty()) {
result.append(processProperties(properties));
}
Properties extraProperties = ar.getExtraProperties();
if ((extraProperties != null) && (!extraProperties.isEmpty())) {
if ((extraProperties.size() == 1) && (extraProperties.get("methods") != null)) {
// do not show only methods metadata in html, not really needed
} else {
result.append(getExtraProperties(extraProperties));
}
}
List<ActionReport.MessagePart> children = ar.getTopMessagePart().getChildren();
if (children.size() > 0) {
result.append(processChildren(children));
}
List<ActionReporter> subReports = ar.getSubActionsReport();
if (subReports.size() > 0) {
result.append(processSubReports(subReports));
}
return result.toString();
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class ActionReportResultHtmlProvider method getContent.
@Override
public String getContent(ActionReportResult proxy) {
RestActionReporter ar = (RestActionReporter) proxy.getActionReport();
StringBuilder result = new StringBuilder(ProviderUtil.getHtmlHeader(getBaseUri()));
final String message = ResourceUtil.encodeString(ar.getCombinedMessage());
if (!message.isEmpty()) {
result.append("<h3>").append(message).append("</h3>");
}
if (proxy.isError()) {
result.append("<h2>").append(ar.getActionDescription()).append(" Error:</h2>").append(proxy.getErrorMessage());
} else {
final Map<String, String> childResources = (Map<String, String>) ar.getExtraProperties().get("childResources");
final List<Map<String, String>> commands = (List<Map<String, String>>) ar.getExtraProperties().get("commands");
final MethodMetaData postMetaData = proxy.getMetaData().getMethodMetaData("POST");
final MethodMetaData deleteMetaData = proxy.getMetaData().getMethodMetaData("DELETE");
final MethodMetaData getMetaData = proxy.getMetaData().getMethodMetaData("GET");
final ConfigBean entity = proxy.getEntity();
if ((proxy.getCommandDisplayName() != null) && (getMetaData != null)) {
// for commands, we want the output of the command before the form
if (entity == null) {
// show extra properties only for non entity pages
result.append(processReport(ar));
}
}
if ((postMetaData != null) && (entity == null)) {
String postCommand = getHtmlRespresentationsForCommand(postMetaData, "POST", (proxy.getCommandDisplayName() == null) ? "Create" : proxy.getCommandDisplayName(), uriInfo.get());
result.append(getHtmlForComponent(postCommand, "Create " + ar.getActionDescription(), ""));
}
if ((deleteMetaData != null) && (entity == null)) {
String deleteCommand = getHtmlRespresentationsForCommand(deleteMetaData, "DELETE", (proxy.getCommandDisplayName() == null) ? "Delete" : proxy.getCommandDisplayName(), uriInfo.get());
result.append(getHtmlForComponent(deleteCommand, "Delete " + ar.getActionDescription(), ""));
}
if ((getMetaData != null) && (entity == null) && (proxy.getCommandDisplayName() != null)) {
String getCommand = getHtmlRespresentationsForCommand(getMetaData, "GET", (proxy.getCommandDisplayName() == null) ? "Get" : proxy.getCommandDisplayName(), uriInfo.get());
result.append(getHtmlForComponent(getCommand, "Get " + ar.getActionDescription(), ""));
}
if (entity != null) {
String attributes = ProviderUtil.getHtmlRepresentationForAttributes(proxy.getEntity(), uriInfo.get());
result.append(ProviderUtil.getHtmlForComponent(attributes, ar.getActionDescription() + " Attributes", ""));
String deleteCommand = ProviderUtil.getHtmlRespresentationsForCommand(proxy.getMetaData().getMethodMetaData("DELETE"), "DELETE", (proxy.getCommandDisplayName() == null) ? "Delete" : proxy.getCommandDisplayName(), uriInfo.get());
result.append(ProviderUtil.getHtmlForComponent(deleteCommand, "Delete " + entity.model.getTagName(), ""));
} else if (proxy.getLeafContent() != null) {
// it is a single leaf @Element
String content = "<form action=\"" + uriInfo.get().getAbsolutePath().toString() + "\" method=\"post\">" + "<dl><dt>" + "<label for=\"" + proxy.getLeafContent().name + "\">" + proxy.getLeafContent().name + ": </label>" + "</dt><dd>" + "<input name=\"" + proxy.getLeafContent().name + "\" value =\"" + proxy.getLeafContent().value + "\" type=\"text\" >" + "</dd><dt class=\"button\"></dt><dd class=\"button\"><input value=\"Update\" type=\"submit\"></dd></dl>" + "</form><br><hr class=\"separator\"/";
result.append(content);
} else {
// This is a monitoring result!!!
final Map vals = (Map) ar.getExtraProperties().get("entity");
if ((vals != null) && (!vals.isEmpty())) {
result.append("<ul>");
for (Map.Entry entry : (Set<Map.Entry>) vals.entrySet()) {
Object object = entry.getValue();
if (object == null) {
// do nothing
} else if (object instanceof Collection) {
if (!((Collection) object).isEmpty()) {
Collection c = ((Collection) object);
Iterator i = c.iterator();
result.append("<li>").append(entry.getKey());
result.append("<ul>");
while (i.hasNext()) {
result.append("<li>").append(getHtmlRepresentation(i.next())).append("</li>");
}
result.append("</ul>");
result.append("</li>");
}
} else if (object instanceof Map) {
if (!((Map) object).isEmpty()) {
Map m = (Map) object;
if (vals.size() != 1) {
// add a link if more than 1 child
result.append("<li>").append("<a href=\"" + uriInfo.get().getAbsolutePath().toString() + "/" + entry.getKey() + "\">" + entry.getKey() + "</a>");
} else {
result.append("<li>").append(entry.getKey());
}
result.append("<ul>");
for (Map.Entry anEntry : (Set<Map.Entry>) m.entrySet()) {
final String htmlRepresentation = getHtmlRepresentation(anEntry.getValue());
if (htmlRepresentation != null) {
result.append("<li>").append(anEntry.getKey()).append(" : ").append(htmlRepresentation).append("</li>");
}
}
result.append("</ul>");
result.append("</li>");
}
} else {
result.append("<li>").append(entry.getKey()).append(" : ").append(object.toString()).append("</li>");
}
}
result.append("</ul>");
} else {
// no values to show... give an hint
if ((childResources == null) || (childResources.isEmpty())) {
if ((uriInfo != null) && (uriInfo.get().getPath().equalsIgnoreCase("domain"))) {
result.append(getHint(uriInfo.get(), MediaType.TEXT_HTML));
}
}
}
}
if ((childResources != null) && (!childResources.isEmpty())) {
String childResourceLinks = getResourcesLinks(childResources);
result.append(ProviderUtil.getHtmlForComponent(childResourceLinks, "Child Resources", ""));
}
if ((commands != null) && (!commands.isEmpty())) {
String commandLinks = getCommandLinks(commands);
result.append(ProviderUtil.getHtmlForComponent(commandLinks, "Commands", ""));
}
}
return result.append("</div></body></html>").toString();
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter in project Payara by payara.
the class ActionReportResultJsonProvider method getContent.
@Override
public String getContent(ActionReportResult proxy) {
RestActionReporter ar = (RestActionReporter) proxy.getActionReport();
ActionReportJsonProvider provider = new ActionReportJsonProvider();
return provider.getContent(ar);
}
use of org.glassfish.admin.rest.utils.xml.RestActionReporter 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;
}
Aggregations