1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension.job.history.internal

File AnswerReplayer.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

6
9
3
1
76
39
8
0.89
3
3
2.67

Classes

Class Line # Actions
AnswerReplayer 42 9 0% 8 2
0.888888988.9%
 

Contributing tests

This file is covered by 127 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.job.history.internal;
21   
22    import javax.inject.Named;
23    import javax.inject.Singleton;
24   
25    import org.xwiki.component.annotation.Component;
26    import org.xwiki.extension.job.history.ExtensionJobHistoryRecord;
27    import org.xwiki.extension.job.history.QuestionRecorder;
28    import org.xwiki.extension.job.history.ReplayJobStatus;
29    import org.xwiki.job.event.status.QuestionAskedEvent;
30    import org.xwiki.observation.AbstractEventListener;
31    import org.xwiki.observation.event.Event;
32   
33    /**
34    * Listens to {@link QuestionAskedEvent}s and replays a recorded answer, if such an answer is available.
35    *
36    * @version $Id: d05b06b765c8e288644c29b733e73aceeffaece8 $
37    * @since 7.1RC1
38    */
39    @Component
40    @Named(AnswerReplayer.NAME)
41    @Singleton
 
42    public class AnswerReplayer extends AbstractEventListener
43    {
44    /**
45    * The name of this event listener (and its component hint at the same time).
46    */
47    public static final String NAME = "AnswerReplayer";
48   
49    /**
50    * Default constructor.
51    */
 
52  298 toggle public AnswerReplayer()
53    {
54  298 super(NAME, new QuestionAskedEvent());
55    }
56   
 
57  16 toggle @Override
58    public void onEvent(Event event, Object source, Object data)
59    {
60  16 if (source instanceof ReplayJobStatus) {
61  1 replayAnswer((QuestionAskedEvent) event, (ReplayJobStatus) source);
62    }
63    }
64   
 
65  1 toggle private void replayAnswer(QuestionAskedEvent event, ReplayJobStatus replayJobStatus)
66    {
67  1 Object question = replayJobStatus.getQuestion();
68  1 ExtensionJobHistoryRecord currentRecord = replayJobStatus.getCurrentRecord();
69  1 if (question != null && currentRecord != null) {
70  1 QuestionRecorder<Object> answers = currentRecord.getAnswers().get(question.getClass().getName());
71  1 if (answers != null && answers.replay(question)) {
72  1 event.answered();
73    }
74    }
75    }
76    }