]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/dao/test/tree/TreeTestResultPersister.java
Introduce JCR agent. Client agent not needed anymore.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / dao / test / tree / TreeTestResultPersister.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package org.argeo.slc.dao.test.tree;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import org.argeo.slc.core.test.tree.TreeTestResult;
23 import org.argeo.slc.test.TestResultListener;
24 import org.argeo.slc.test.TestResultPart;
25
26 /**
27 * Listener persisting tree-based results.
28 *
29 * @see TreeTestResult
30 */
31 public class TreeTestResultPersister implements
32 TestResultListener<TreeTestResult> {
33 private static Log log = LogFactory.getLog(TreeTestResultPersister.class);
34
35 private TreeTestResultDao testResultDao;
36
37 public void resultPartAdded(TreeTestResult testResult,
38 TestResultPart testResultPart) {
39 try {
40 TreeTestResult persistedResult = testResultDao
41 .getTestResult(testResult.getUuid());
42
43 if (persistedResult == null) {
44 testResultDao.create(testResult);
45 } else {
46 testResultDao.update(testResult);
47 }
48 } catch (Exception e) {
49 log.error("Could not persist result part " + testResultPart
50 + " for result " + testResult.getUuid());
51 }
52 }
53
54 public void close(TreeTestResult testResult) {
55 TreeTestResult persistedResult = (TreeTestResult) testResultDao
56 .getTestResult(testResult.getUuid());
57
58 if (persistedResult != null) {
59 persistedResult.setCloseDate(testResult.getCloseDate());
60 testResultDao.update(persistedResult);
61 }
62 if (log.isDebugEnabled())
63 log.debug("Closed result persister for result "
64 + testResult.getUuid());
65 }
66
67 /** Sets the DAO to use in order to persist the results. */
68 public void setTestResultDao(TreeTestResultDao testResultDao) {
69 this.testResultDao = testResultDao;
70 }
71 }