} catch (GcResourceNotFoundException e) {
// The workflow was not found in the engine.
logger.caught(e);
template = null;
} catch (RuntimeException e) {
throw new WorkflowEngineException(ErrorMessages.GPEL_ERROR, e);
}
}
}
String title = workflow.getName();
if (template == null) {
// This case is either it is a new deploy or the tempate does not
// exist in the GPEL Engine.
template = this.client.createTemplate(title);
links = new ArrayList<GcWebResource>();
template.setLinks(links);
} else {
// Redeploy
template.setTitle(title);
links = template.getLinks();
// Look for each resource.
for (GcWebResource link : links) {
String rel = link.getRel();
logger.finest("rel: " + rel);
if (GpelConstants.REL_PROCESS.equals(rel)) {
processResource = (GcProcessResource) link;
} else if (GPELLinksFilter.REL_XWF.equals(rel)) {
graphResource = (GcXmlWebResource) link;
} else if (GPELLinksFilter.REL_IMAGE.equals(rel)) {
imageResource = (GcBinaryWebResource) link;
} else if (GpelConstants.REL_WSDL.equals(rel)) {
GcWsdlResource wsdlResouece = (GcWsdlResource) link;
String wsdlTitle = wsdlResouece.getTitle();
logger.finest("wsdlTitle: " + wsdlTitle);
// XXX Can we rely on the title to do the matching?
wsdlResourceMap.put(wsdlTitle, wsdlResouece);
}
}
}
// BPEL process
GpelProcess process = workflow.getGpelProcess();
if (processResource == null) {
processResource = new GcProcessResource(PROCESS_GPEL_TITLE, process);
links.add(processResource);
} else {
processResource.setXmlContent(process.xml());
}
// WSDL for the process
workflowWSDLresource = wsdlResourceMap.remove(PROCESS_WSDL_TYTLE);
WsdlDefinitions workflowWSDL = workflow.getWorkflowWSDL();
logger.finest(workflowWSDL.xmlString());
if (workflowWSDLresource == null) {
workflowWSDLresource = new GcWsdlResource(PROCESS_WSDL_TYTLE,
workflowWSDL);
links.add(workflowWSDLresource);
} else {
workflowWSDLresource.setXmlContent(workflowWSDL.xml());
}
Map<String, WsdlDefinitions> wsdlMap = workflow.getWSDLs();
for (String id : wsdlMap.keySet()) {
WsdlDefinitions wsdl = wsdlMap.get(id);
GcWsdlResource wsdlResource = wsdlResourceMap.remove(id);
if (wsdlResource == null) {
wsdlResource = new GcWsdlResource(id, wsdl);
links.add(wsdlResource);
} else {
wsdlResource.setXmlContent(wsdl.xml());
}
}
// Remove the rest of unused WSDL from the links.
for (GcWsdlResource resource : wsdlResourceMap.values()) {
links.remove(resource);
}
// Graph
Graph graph = workflow.getGraph();
if (graphResource == null) {
logger.finest("Creating a new graphResource");
graphResource = new GcXmlWebResource("process.xgr", graph.toXML(),
GRAPH_MIME_TYPE);
graphResource.setRel(GPELLinksFilter.REL_XWF);
links.add(graphResource);
} else {
logger.finest("Updating the graphResource");
graphResource.setXmlContent(graph.toXML());
}
// Image
try {
BufferedImage image = workflow.getImage();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
ImageIO.write(image, XBayaConstants.PNG_FORMAT_NAME, outStream);
byte[] bytes = outStream.toByteArray();
if (imageResource == null) {
imageResource = new GcBinaryWebResource("image.png", bytes,
PNG_MIME_TYPE);
imageResource.setRel(GPELLinksFilter.REL_IMAGE);
links.add(imageResource);
} else {
imageResource.setBinaryContent(bytes);
}
} catch (IOException e) {
// It's OK to not save the image for now.
logger.caught(e);
} catch (IllegalArgumentException e) {
// This happens only from junit tests.
logger.caught(e);
}
try {
this.client.deployTemplate(template);
// this needs to be kept and reused
URI templateID = template.getTemplateId();
workflow.setGPELTemplateID(templateID);
logger.exiting();
return templateID;
} catch (RuntimeException e) {
throw new WorkflowEngineException(ErrorMessages.GPEL_ERROR, e);
}
}