super(ActionReportResult.class, MediaType.TEXT_HTML_TYPE);
}
@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()) {