]>
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
1 package org
.argeo
.slc
.jcr
.execution
;
3 import java
.util
.Calendar
;
4 import java
.util
.GregorianCalendar
;
8 import javax
.jcr
.RepositoryException
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.jcr
.JcrUtils
;
13 import org
.argeo
.slc
.SlcException
;
14 import org
.argeo
.slc
.execution
.ExecutionProcess
;
15 import org
.argeo
.slc
.execution
.ExecutionStep
;
16 import org
.argeo
.slc
.jcr
.SlcNames
;
17 import org
.argeo
.slc
.jcr
.SlcTypes
;
19 /** Execution process implementation based on a JCR node. */
20 public class JcrExecutionProcess
implements ExecutionProcess
, SlcNames
{
21 private Log log
= LogFactory
.getLog(JcrExecutionProcess
.class);
22 private final Node node
;
24 private Long nextLogLine
= 1l;
26 public JcrExecutionProcess(Node node
) {
30 public String
getUuid() {
32 return node
.getProperty(SLC_UUID
).getString();
33 } catch (RepositoryException e
) {
34 throw new SlcException("Cannot get uuid for " + node
, e
);
38 public String
getStatus() {
40 return node
.getProperty(SLC_STATUS
).getString();
41 } catch (RepositoryException e
) {
42 log
.error("Cannot get status: " + e
);
43 // we should re-throw exception because this information can
44 // probably used for monitoring in case there are already unexpected
50 public void setStatus(String status
) {
52 node
.setProperty(SLC_STATUS
, status
);
53 // last modified properties needs to be manually updated
54 // see https://issues.apache.org/jira/browse/JCR-2233
55 JcrUtils
.updateLastModified(node
);
56 node
.getSession().save();
57 } catch (RepositoryException e
) {
58 JcrUtils
.discardUnderlyingSessionQuietly(node
);
59 // we should re-throw exception because this information can
60 // probably used for monitoring in case there are already unexpected
62 log
.error("Cannot set status " + status
+ ": " + e
);
67 * Synchronized in order to make sure that there is no concurrent
68 * modification of {@link #nextLogLine}.
70 public synchronized void addSteps(List
<ExecutionStep
> steps
) {
72 steps
: for (ExecutionStep step
: steps
) {
74 if (step
.getType().equals(ExecutionStep
.TRACE
))
75 type
= SlcTypes
.SLC_LOG_TRACE
;
76 else if (step
.getType().equals(ExecutionStep
.DEBUG
))
77 type
= SlcTypes
.SLC_LOG_DEBUG
;
78 else if (step
.getType().equals(ExecutionStep
.INFO
))
79 type
= SlcTypes
.SLC_LOG_INFO
;
80 else if (step
.getType().equals(ExecutionStep
.WARNING
))
81 type
= SlcTypes
.SLC_LOG_WARNING
;
82 else if (step
.getType().equals(ExecutionStep
.ERROR
))
83 type
= SlcTypes
.SLC_LOG_ERROR
;
88 String relPath
= SLC_LOG
+ '/' + step
.getThread() + '/'
89 + step
.getLocation().replace('.', '/');
90 String path
= node
.getPath() + '/' + relPath
;
91 // clean special character
92 // TODO factorize in JcrUtils
93 path
= path
.replace('@', '_').replace('/', '_')
96 Node location
= JcrUtils
.mkdirs(node
.getSession(), path
);
97 Node logEntry
= location
.addNode(Long
.toString(nextLogLine
),
99 logEntry
.setProperty(SLC_MESSAGE
, step
.getLog());
100 Calendar calendar
= new GregorianCalendar();
101 calendar
.setTime(step
.getTimestamp());
102 logEntry
.setProperty(SLC_TIMESTAMP
, calendar
);
104 // System.out.println("Logged " + logEntry.getPath());
109 // last modified properties needs to be manually updated
110 // see https://issues.apache.org/jira/browse/JCR-2233
111 JcrUtils
.updateLastModified(node
);
113 node
.getSession().save();
114 } catch (Exception e
) {
115 JcrUtils
.discardUnderlyingSessionQuietly(node
);
120 public Node
getNode() {