2 * Copyright (C) 2007-2012 Mathieu Baudier
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.
16 package org
.argeo
.slc
.jcr
.dao
;
18 import java
.util
.ArrayList
;
19 import java
.util
.Calendar
;
20 import java
.util
.Date
;
21 import java
.util
.GregorianCalendar
;
22 import java
.util
.List
;
24 import javax
.jcr
.Node
;
25 import javax
.jcr
.NodeIterator
;
26 import javax
.jcr
.RepositoryException
;
27 import javax
.jcr
.query
.Query
;
28 import javax
.jcr
.query
.QueryResult
;
30 import org
.apache
.commons
.logging
.Log
;
31 import org
.apache
.commons
.logging
.LogFactory
;
32 import org
.argeo
.jcr
.JcrUtils
;
33 import org
.argeo
.slc
.SlcException
;
34 import org
.argeo
.slc
.dao
.process
.SlcExecutionDao
;
35 import org
.argeo
.slc
.process
.SlcExecution
;
36 import org
.argeo
.slc
.process
.SlcExecutionStep
;
38 public class SlcExecutionDaoJcr
extends AbstractSlcJcrDao
implements
40 private final static Log log
= LogFactory
.getLog(SlcExecutionDaoJcr
.class);
42 public void addSteps(String slcExecutionId
,
43 List
<SlcExecutionStep
> additionalSteps
) {
44 // TODO: optimize, do one single query
45 SlcExecution slcExecution
= getSlcExecution(slcExecutionId
);
46 slcExecution
.getSteps().addAll(additionalSteps
);
51 public void create(SlcExecution slcExecution
) {
53 nodeMapper
.save(getSession(), basePath(slcExecution
), slcExecution
);
55 } catch (RepositoryException e
) {
56 throw new SlcException("Cannot create slcExecution" + slcExecution
,
61 protected String
basePath(SlcExecution slcExecution
) {
62 Calendar cal
= new GregorianCalendar();
63 cal
.setTime(new Date());
64 // cal.setTime(slcExecution.getStartDate());
65 String host
= slcExecution
.getHost();
68 return "/slc/processes/" + JcrUtils
.hostAsPath(host
) + '/'
69 + JcrUtils
.dateAsPath(cal
) + "process";
72 public SlcExecution
getSlcExecution(String uuid
) {
73 // TODO: optimize query
74 String queryString
= "//process[@uuid='" + uuid
+ "']";
75 Query query
= createQuery(queryString
, Query
.XPATH
);
76 Node node
= JcrUtils
.querySingleNode(query
);
79 return (SlcExecution
) nodeMapper
.load(node
);
82 public List
<SlcExecution
> listSlcExecutions() {
83 List
<SlcExecution
> res
= new ArrayList
<SlcExecution
>();
84 // TODO: optimize query
85 String queryString
= "//process";
87 Query query
= createQuery(queryString
, Query
.XPATH
);
88 QueryResult qr
= query
.execute();
89 NodeIterator iterator
= qr
.getNodes();
90 while (iterator
.hasNext()) {
91 Node node
= iterator
.nextNode();
92 SlcExecution slcExecution
= (SlcExecution
) nodeMapper
94 res
.add(slcExecution
);
97 } catch (RepositoryException e
) {
98 throw new SlcException("Cannot list SLC executions", e
);
102 public void merge(SlcExecution slcExecution
) {
103 throw new UnsupportedOperationException();
106 public void update(SlcExecution slcExecution
) {
107 // TODO: optimize query
108 String queryString
= "//process[@uuid='" + slcExecution
.getUuid()
111 Query query
= createQuery(queryString
, Query
.XPATH
);
112 Node node
= JcrUtils
.querySingleNode(query
);
113 nodeMapper
.update(node
, slcExecution
);
115 } catch (RepositoryException e
) {
116 throw new SlcException("Cannot update " + slcExecution
, e
);
120 public List
<SlcExecutionStep
> tailSteps(String slcExecutionId
,
121 Integer nbrOfSteps
) {
122 log
.error("Method not implemented, returning an empty list.");
123 return new ArrayList
<SlcExecutionStep
>();
126 public List
<SlcExecutionStep
> tailSteps(String slcExecutionId
,
127 String slcExecutionStepId
) {
128 log
.error("Method not implemented, returning an empty list.");
129 return new ArrayList
<SlcExecutionStep
>();