]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/execution/JcrExecutionProcess.java
Primitive arguments working
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.jcr / src / main / java / org / argeo / slc / jcr / execution / JcrExecutionProcess.java
1 package org.argeo.slc.jcr.execution;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.argeo.jcr.JcrUtils;
9 import org.argeo.slc.SlcException;
10 import org.argeo.slc.execution.ExecutionProcess;
11 import org.argeo.slc.jcr.SlcNames;
12
13 /** Execution process implementation based on a JCR node. */
14 public class JcrExecutionProcess implements ExecutionProcess {
15 private Log log = LogFactory.getLog(JcrExecutionProcess.class);
16 private final Node node;
17
18 public JcrExecutionProcess(Node node) {
19 this.node = node;
20 }
21
22 public String getUuid() {
23 try {
24 return node.getProperty(SlcNames.SLC_UUID).getString();
25 } catch (RepositoryException e) {
26 throw new SlcException("Cannot get uuid for " + node, e);
27 }
28 }
29
30 public String getStatus() {
31 try {
32 return node.getProperty(SlcNames.SLC_STATUS).getString();
33 } catch (RepositoryException e) {
34 log.error("Cannot get status: " + e);
35 // we should re-throw exception because this information can
36 // probably used for monitoring in case there are already unexpected
37 // exceptions
38 return UNKOWN;
39 }
40 }
41
42 public void setStatus(String status) {
43 try {
44 node.setProperty(SlcNames.SLC_STATUS, status);
45 // last modified properties needs to be manually updated
46 // see https://issues.apache.org/jira/browse/JCR-2233
47 JcrUtils.updateLastModified(node);
48 node.getSession().save();
49 } catch (RepositoryException e) {
50 try {
51 JcrUtils.discardQuietly(node.getSession());
52 } catch (RepositoryException e1) {
53 // silent
54 }
55 // we should re-throw exception because this information can
56 // probably used for monitoring in case there are already unexpected
57 // exceptions
58 log.error("Cannot set status " + status + ": " + e);
59 }
60 }
61
62 public Node getNode() {
63 return node;
64 }
65
66 }