2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.jcr
.dao
;
19 import java
.util
.ArrayList
;
20 import java
.util
.Calendar
;
21 import java
.util
.Date
;
22 import java
.util
.GregorianCalendar
;
23 import java
.util
.List
;
25 import javax
.jcr
.Node
;
26 import javax
.jcr
.NodeIterator
;
27 import javax
.jcr
.RepositoryException
;
28 import javax
.jcr
.query
.Query
;
29 import javax
.jcr
.query
.QueryResult
;
31 import org
.apache
.commons
.logging
.Log
;
32 import org
.apache
.commons
.logging
.LogFactory
;
33 import org
.argeo
.jcr
.JcrUtils
;
34 import org
.argeo
.slc
.SlcException
;
35 import org
.argeo
.slc
.dao
.process
.SlcExecutionDao
;
36 import org
.argeo
.slc
.process
.SlcExecution
;
37 import org
.argeo
.slc
.process
.SlcExecutionStep
;
39 public class SlcExecutionDaoJcr
extends AbstractSlcJcrDao
implements
41 private final static Log log
= LogFactory
.getLog(SlcExecutionDaoJcr
.class);
43 public void addSteps(String slcExecutionId
,
44 List
<SlcExecutionStep
> additionalSteps
) {
45 // TODO: optimize, do one single query
46 SlcExecution slcExecution
= getSlcExecution(slcExecutionId
);
47 slcExecution
.getSteps().addAll(additionalSteps
);
52 public void create(SlcExecution slcExecution
) {
54 nodeMapper
.save(getSession(), basePath(slcExecution
), slcExecution
);
56 } catch (RepositoryException e
) {
57 throw new SlcException("Cannot create slcExecution" + slcExecution
,
62 protected String
basePath(SlcExecution slcExecution
) {
63 Calendar cal
= new GregorianCalendar();
64 cal
.setTime(new Date());
65 // cal.setTime(slcExecution.getStartDate());
66 String host
= slcExecution
.getHost();
69 return "/slc/processes/" + JcrUtils
.hostAsPath(host
) + '/'
70 + JcrUtils
.dateAsPath(cal
) + "process";
73 public SlcExecution
getSlcExecution(String uuid
) {
74 // TODO: optimize query
75 String queryString
= "//process[@uuid='" + uuid
+ "']";
76 Query query
= createQuery(queryString
, Query
.XPATH
);
77 Node node
= JcrUtils
.querySingleNode(query
);
80 return (SlcExecution
) nodeMapper
.load(node
);
83 public List
<SlcExecution
> listSlcExecutions() {
84 List
<SlcExecution
> res
= new ArrayList
<SlcExecution
>();
85 // TODO: optimize query
86 String queryString
= "//process";
88 Query query
= createQuery(queryString
, Query
.XPATH
);
89 QueryResult qr
= query
.execute();
90 NodeIterator iterator
= qr
.getNodes();
91 while (iterator
.hasNext()) {
92 Node node
= iterator
.nextNode();
93 SlcExecution slcExecution
= (SlcExecution
) nodeMapper
95 res
.add(slcExecution
);
98 } catch (RepositoryException e
) {
99 throw new SlcException("Cannot list SLC executions", e
);
103 public void merge(SlcExecution slcExecution
) {
104 throw new UnsupportedOperationException();
107 public void update(SlcExecution slcExecution
) {
108 // TODO: optimize query
109 String queryString
= "//process[@uuid='" + slcExecution
.getUuid()
112 Query query
= createQuery(queryString
, Query
.XPATH
);
113 Node node
= JcrUtils
.querySingleNode(query
);
114 nodeMapper
.update(node
, slcExecution
);
116 } catch (RepositoryException e
) {
117 throw new SlcException("Cannot update " + slcExecution
, e
);
121 public List
<SlcExecutionStep
> tailSteps(String slcExecutionId
,
122 Integer nbrOfSteps
) {
123 log
.error("Method not implemented, returning an empty list.");
124 return new ArrayList
<SlcExecutionStep
>();
127 public List
<SlcExecutionStep
> tailSteps(String slcExecutionId
,
128 String slcExecutionStepId
) {
129 log
.error("Method not implemented, returning an empty list.");
130 return new ArrayList
<SlcExecutionStep
>();