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
.dao
.test
.tree
;
19 import org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
22 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
23 import org
.argeo
.slc
.test
.TestResultListener
;
24 import org
.argeo
.slc
.test
.TestResultPart
;
27 * Listener persisting tree-based results.
32 public class TreeTestResultPersister
implements
33 TestResultListener
<TreeTestResult
> {
34 private static Log log
= LogFactory
.getLog(TreeTestResultPersister
.class);
36 private TreeTestResultDao testResultDao
;
38 public void resultPartAdded(TreeTestResult testResult
,
39 TestResultPart testResultPart
) {
41 TreeTestResult persistedResult
= testResultDao
42 .getTestResult(testResult
.getUuid());
44 if (persistedResult
== null) {
45 testResultDao
.create(testResult
);
47 testResultDao
.update(testResult
);
49 } catch (Exception e
) {
50 log
.error("Could not persist result part " + testResultPart
51 + " for result " + testResult
.getUuid());
55 public void close(TreeTestResult testResult
) {
56 TreeTestResult persistedResult
= (TreeTestResult
) testResultDao
57 .getTestResult(testResult
.getUuid());
59 if (persistedResult
!= null) {
60 persistedResult
.setCloseDate(testResult
.getCloseDate());
61 testResultDao
.update(persistedResult
);
63 if (log
.isDebugEnabled())
64 log
.debug("Closed result persister for result "
65 + testResult
.getUuid());
68 /** Sets the DAO to use in order to persist the results. */
69 public void setTestResultDao(TreeTestResultDao testResultDao
) {
70 this.testResultDao
= testResultDao
;