1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.job.history

File ExtensionJobHistoryRecord.java

 

Coverage histogram

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

Code metrics

4
16
7
1
127
57
9
0.56
2.29
7
1.29

Classes

Class Line # Actions
ExtensionJobHistoryRecord 37 16 0% 9 4
0.851851985.2%
 

Contributing tests

This file is covered by 20 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;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.Date;
25    import java.util.List;
26    import java.util.Map;
27   
28    import org.apache.commons.lang3.StringUtils;
29    import org.xwiki.extension.job.ExtensionRequest;
30   
31    /**
32    * A record in the {@link ExtensionJobHistory}.
33    *
34    * @version $Id: 25e38ec0798cdc1a5fd613b694a7fcf1d534a9e4 $
35    * @since 7.1RC1
36    */
 
37    public class ExtensionJobHistoryRecord
38    {
39    private final String jobType;
40   
41    private final ExtensionRequest request;
42   
43    private final Map<String, QuestionRecorder<Object>> answers;
44   
45    private final Date startDate;
46   
47    private final Date endDate;
48   
49    /**
50    * Creates a new unmodifiable history record.
51    *
52    * @param jobType the job type (normally the job component hint, e.g. "install")
53    * @param request the extension request
54    * @param answers the answers that were given by the user to the questions asked by the job specified by this
55    * history record (if the job was interactive); the key in the given map identifies the question type;
56    * the value represents the recorded answers for the corresponding question type
57    * @param startDate the date when the job execution started
58    * @param endDate the date when the job execution ended
59    */
 
60  111 toggle public ExtensionJobHistoryRecord(String jobType, ExtensionRequest request,
61    Map<String, QuestionRecorder<Object>> answers, Date startDate, Date endDate)
62    {
63  111 this.jobType = jobType;
64  111 this.request = request;
65  111 this.answers =
66  111 answers != null ? Collections.unmodifiableMap(answers) : Collections
67    .<String, QuestionRecorder<Object>>emptyMap();
68  111 this.startDate = startDate;
69  111 this.endDate = endDate;
70    }
71   
72    /**
73    * @return the job type (normally the job component hint, e.g. "install")
74    */
 
75  9 toggle public String getJobType()
76    {
77  9 return jobType;
78    }
79   
80    /**
81    * @return the extension request
82    */
 
83  26 toggle public ExtensionRequest getRequest()
84    {
85  26 return request;
86    }
87   
88    /**
89    * @return the answers that were given by the user to the questions asked by the job specified by this history
90    * record (if the job was interactive); the key in the returned map identifies the question type; the value
91    * represents the recorded answers for the corresponding question type
92    */
 
93  2 toggle public Map<String, QuestionRecorder<Object>> getAnswers()
94    {
95  2 return answers;
96    }
97   
98    /**
99    * @return the date when the job execution started
100    */
 
101  1 toggle public Date getStartDate()
102    {
103  1 return startDate;
104    }
105   
106    /**
107    * @return the date when the job execution ended
108    */
 
109  0 toggle public Date getEndDate()
110    {
111  0 return endDate;
112    }
113   
114    /**
115    * @return a string that can be used to identify this record
116    */
 
117  2 toggle public String getId()
118    {
119  2 List<Object> parts = new ArrayList<>();
120  2 parts.add(this.endDate.getTime());
121  2 parts.add(this.jobType);
122  2 if (this.request.hasNamespaces()) {
123  0 parts.addAll(this.request.getNamespaces());
124    }
125  2 return StringUtils.join(parts, '-');
126    }
127    }