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
.dao
.test
.tree
;
18 import org
.apache
.commons
.logging
.Log
;
19 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
22 import org
.argeo
.slc
.test
.TestResultListener
;
23 import org
.argeo
.slc
.test
.TestResultPart
;
26 * Listener persisting tree-based results.
31 public class TreeTestResultPersister
implements
32 TestResultListener
<TreeTestResult
> {
33 private static Log log
= LogFactory
.getLog(TreeTestResultPersister
.class);
35 private TreeTestResultDao testResultDao
;
37 public void resultPartAdded(TreeTestResult testResult
,
38 TestResultPart testResultPart
) {
40 TreeTestResult persistedResult
= testResultDao
41 .getTestResult(testResult
.getUuid());
43 if (persistedResult
== null) {
44 testResultDao
.create(testResult
);
46 testResultDao
.update(testResult
);
48 } catch (Exception e
) {
49 log
.error("Could not persist result part " + testResultPart
50 + " for result " + testResult
.getUuid());
54 public void close(TreeTestResult testResult
) {
55 TreeTestResult persistedResult
= (TreeTestResult
) testResultDao
56 .getTestResult(testResult
.getUuid());
58 if (persistedResult
!= null) {
59 persistedResult
.setCloseDate(testResult
.getCloseDate());
60 testResultDao
.update(persistedResult
);
62 if (log
.isDebugEnabled())
63 log
.debug("Closed result persister for result "
64 + testResult
.getUuid());
67 /** Sets the DAO to use in order to persist the results. */
68 public void setTestResultDao(TreeTestResultDao testResultDao
) {
69 this.testResultDao
= testResultDao
;