Revision 37397
Added by Michele Artini almost 9 years ago
ManagerWorkerServiceImpl.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.worker; |
2 | 2 |
|
3 |
import java.awt.Image; |
|
3 |
import java.awt.image.BufferedImage; |
|
4 |
import java.io.ByteArrayOutputStream; |
|
4 | 5 |
import java.io.IOException; |
5 | 6 |
|
6 | 7 |
import javax.imageio.ImageIO; |
7 |
import javax.xml.ws.soap.MTOM; |
|
8 | 8 |
|
9 |
import org.apache.commons.codec.binary.Base64; |
|
10 |
import org.apache.commons.io.IOUtils; |
|
9 | 11 |
import org.apache.commons.logging.Log; |
10 | 12 |
import org.apache.commons.logging.LogFactory; |
11 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
15 | 17 |
|
16 | 18 |
import eu.dnetlib.common.services.AbstractBaseService; |
17 | 19 |
import eu.dnetlib.msro.worker.ui.ProcessToImageMapHelper; |
20 |
import eu.dnetlib.rmi.object.manager.ProcessImageDesc; |
|
18 | 21 |
import eu.dnetlib.rmi.soap.ManagerWorkerService; |
19 | 22 |
|
20 |
@MTOM |
|
21 | 23 |
public class ManagerWorkerServiceImpl extends AbstractBaseService implements ManagerWorkerService { |
22 | 24 |
|
23 | 25 |
@Autowired |
... | ... | |
25 | 27 |
private static final Log log = LogFactory.getLog(ManagerWorkerServiceImpl.class); |
26 | 28 |
|
27 | 29 |
@Override |
28 |
public Image getProcessImage(final String procId) {
|
|
30 |
public ProcessImageDesc getProcessImageDesc(final String procId) {
|
|
29 | 31 |
final GraphProcess proc = registry.findProcess(procId); |
32 |
byte[] imgBytes; |
|
33 |
String mapContent = ""; |
|
30 | 34 |
try { |
31 | 35 |
if (proc != null) { |
36 |
final ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
32 | 37 |
try { |
33 | 38 |
final ProcessImageMapCreator imageMapCreator = new ProcessImageMapCreator(proc, new ProcessToImageMapHelper(procId)); |
34 |
return imageMapCreator.getImage(); |
|
39 |
final BufferedImage image = imageMapCreator.getImage(); |
|
40 |
ImageIO.write(image, "png", bos); |
|
41 |
imgBytes = bos.toByteArray(); |
|
42 |
mapContent = imageMapCreator.getMapContents(); |
|
35 | 43 |
} catch (Throwable e) { |
36 |
return ImageIO.read(getClass().getResourceAsStream("/eu/dnetlib/msro/worker/ui/wf_problem.png")); |
|
44 |
imgBytes = IOUtils.toByteArray(getClass().getResourceAsStream("/eu/dnetlib/msro/worker/ui/wf_problem.png")); |
|
45 |
} finally { |
|
46 |
bos.close(); |
|
37 | 47 |
} |
38 | 48 |
} else { |
39 |
return ImageIO.read(getClass().getResourceAsStream("/eu/dnetlib/msro/worker/ui/wf_not_found.png"));
|
|
49 |
imgBytes = IOUtils.toByteArray(getClass().getResourceAsStream("/eu/dnetlib/msro/worker/ui/wf_not_found.png"));
|
|
40 | 50 |
} |
41 | 51 |
} catch (IOException e) { |
42 | 52 |
log.error("Error generating wf image for process: " + procId, e); |
43 | 53 |
return null; |
44 | 54 |
} |
55 |
return new ProcessImageDesc("image/png", new String(Base64.encodeBase64(imgBytes)), mapContent); |
|
45 | 56 |
} |
46 | 57 |
|
47 |
@Override |
|
48 |
public String getProcessImageMap(final String procId) { |
|
49 |
final GraphProcess proc = registry.findProcess(procId); |
|
50 |
if (proc != null) { |
|
51 |
try { |
|
52 |
final ProcessImageMapCreator imageMapCreator = new ProcessImageMapCreator(proc, new ProcessToImageMapHelper(procId)); |
|
53 |
return imageMapCreator.getMapContents(); |
|
54 |
} catch (Throwable e) {} |
|
55 |
} |
|
56 |
return ""; |
|
57 |
} |
|
58 | 58 |
} |
Also available in: Unified diff
process graph image