if (request instanceof ResourceRequest) {
ResourceRequest rr = (ResourceRequest) request;
ResourceResponse resp = (ResourceResponse) response;
if (rr.getParameter("instanceId") != null) { //special handling
logger.info("Image request");
ProcessToolBpmSession session = ctx.getProcessToolSessionFactory()
.createSession(new UserData("admin", "admin@aperteworkflow.org", "Admin admin"),
new ArrayList<String>());
byte[] bytes = session.getProcessMapImage(
session.getProcessData(rr.getParameter("instanceId"), ctx));
if (bytes != null) {
resp.setContentType("image/png");
resp.getPortletOutputStream().write(bytes);
}
return;
} else if (rr.getParameter("svg") != null) { //to use svg inside of a window
logger.info("SVG request");
ProcessToolBpmSession session = ctx.getProcessToolSessionFactory()
.createSession(new UserData("admin", "admin@aperteworkflow.org", "Admin admin"),
new ArrayList<String>());
ProcessInstance pi = session.getProcessData(rr.getParameter("svg"), ctx);
List<GraphElement> processHistory = session.getProcessHistory(pi);
// final StringBuffer svg = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
final StringBuffer svg = new StringBuffer("<html><body style=\"margin:0; padding:0\">\n\n");
final byte[] png = session.getProcessMapImage(pi);
if (png != null) {
BufferedImage read;
try {
read = ImageIO.read(new ByteArrayInputStream(png));
ResourceURL resourceURL = resp.createResourceURL();