summaryrefslogtreecommitdiff
path: root/src/plugins/preflighting.core/src/com/motorolamobility/preflighting/core/validation/ValidationResultData.java
blob: 1a91fd9678300a84d1180988b9d58a362a81af38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/*
 * Copyright (C) 2012 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.motorolamobility.preflighting.core.validation;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.motorolamobility.preflighting.core.checker.condition.Condition;
import com.motorolamobility.preflighting.core.i18n.PreflightingCoreNLS;

/**
 * Corresponds to one validation issue found by a checker/condition.
 */
public class ValidationResultData
{
    /**
     * Severity level of the result.
     */
    public enum SEVERITY
    {
        /**
         * The FATAL level is used for severe error events. In case of FATAL, the
         * application could be aborted.
         */
        FATAL
        {
            @Override
            public String toString()
            {
                return PreflightingCoreNLS.ValidationResultData_FatalSeverityMessage;
            }
        },
        /**
         * The ERROR level is used by errors events. Less severe than FATAL, used
         * for situations of error that will not crash the application.
         */
        ERROR
        {
            @Override
            public String toString()
            {
                return PreflightingCoreNLS.ValidationResultData_ErrorSeverityMessage;
            }
        },
        /**
         * The WARNING level is used for potentially harmful situations. Used for
         * situations that can generate an error.
         */
        WARNING
        {
            @Override
            public String toString()
            {
                return PreflightingCoreNLS.ValidationResultData_WarningSeverityMessage;
            }
        },
        /**
         * The OK level is used if no problem was identified by this checker / condition.
         */
        OK
        {
            @Override
            public String toString()
            {
                return PreflightingCoreNLS.ValidationResultData_OkSeverityMessage;
            }
        };

    }

    private Map<File, List<Integer>> fileToIssueLines;

    // initialize to avoid invalid value (null)
    private SEVERITY severity = SEVERITY.OK;

    private String issueDescription;

    private String quickFixSuggestion;

    /**
     * The condition associated with this result data.
     */
    private String conditionID;

    /**
     * The preview associated with this data (like the line with problems)
     */
    private String preview = null;

    /**
     * Link with more information about validation/checker
     */
    private String infoURL = null;

    private String markerType;

    private final List<Object> extra;

    /**
     * Default constructor.
     */
    public ValidationResultData()
    {
        fileToIssueLines = new HashMap<File, List<Integer>>();
        extra = new ArrayList<Object>();
    }

    /**
     * Constructor that fills the most used items when an issue is raised.
     * @param fileToIssueLines List of files and the lines where the problem occurred
     * @param severity {@link SEVERITY} of the issue.
     * @param issueDescription Description of the issue.
     * @param quickFixSuggestion Quick fix suggested.
     * @param conditionID {@link Condition#getId()} that identified the issue.
     */
    public ValidationResultData(Map<File, List<Integer>> fileToIssueLines, SEVERITY severity,
            String issueDescription, String quickFixSuggestion, String conditionID)
    {
        this.fileToIssueLines =
                fileToIssueLines != null ? fileToIssueLines : new HashMap<File, List<Integer>>();
        this.severity = severity;
        this.issueDescription = issueDescription;
        this.quickFixSuggestion = quickFixSuggestion;
        this.conditionID = conditionID;
        this.extra = new ArrayList<Object>();
    }

    /**
     * Constructor that fills the most used items when an issue is raised.
     * @param fileToIssueLines List of files and the lines where the problem occurred
     * @param severity {@link SEVERITY} of the issue.
     * @param issueDescription Description of the issue.
     * @param quickFixSuggestion Quick fix suggested.
     * @param conditionID {@link Condition#getId()} that identified the issue.
     * @param markerType the type of the problem that will be reported by App Validator.
     */
    public ValidationResultData(Map<File, List<Integer>> fileToIssueLines, SEVERITY severity,
            String issueDescription, String quickFixSuggestion, String conditionID,
            String markerType)
    {
        this.fileToIssueLines =
                fileToIssueLines != null ? fileToIssueLines : new HashMap<File, List<Integer>>();
        this.severity = severity;
        this.issueDescription = issueDescription;
        this.quickFixSuggestion = quickFixSuggestion;
        this.conditionID = conditionID;
        this.markerType = markerType;
        this.extra = new ArrayList<Object>();
    }

    /**
     * Returns a {@link Map} containing the {@link File} and the corresponding lines with issues of this
     * {@link ValidationResultData}.
     * @return a {@link Map} with the {@link File} and its issue lines.
     */
    public Map<File, List<Integer>> getFileToIssueLines()
    {
        return fileToIssueLines;
    }

    /**
     * Adds to a File, usually the problematic one, to the issue lines of the {@link ValidationResultData}.
     * @param file the file descriptor.
     * @param lines the lines in which the issue appears.    */

    public void addFileToIssueLines(File file, List<Integer> lines)
    {
        if (fileToIssueLines == null)
        {
            fileToIssueLines = new HashMap<File, List<Integer>>();
        }
        fileToIssueLines.put(file, lines);
    }

    /**
     * Returns the issue {@link SEVERITY}. 
     * @return the issue {@link SEVERITY}. 
     */
    public SEVERITY getSeverity()
    {
        return severity;
    }

    /**
     * Sets the {@link ValidationResultData} issue severity.
     * @param severity a {@link SEVERITY}. 
     */
    public void setSeverity(SEVERITY severity)
    {
        // protect from invalid value (null)
        if (severity != null)
        {
            this.severity = severity;
        }
        else
        {
            this.severity = SEVERITY.OK;
        }
    }

    /**
     * Returns the issue description for this {@link ValidationResultData}.
     * @return the issue description.
     */
    public String getIssueDescription()
    {
        return issueDescription;
    }

    /**
     * Sets the issue description for this {@link ValidationResultData}.
     * @param issueDescription the issue description.
     */
    public void setIssueDescription(String issueDescription)
    {
        this.issueDescription = issueDescription;
    }

    /**
     * Return the quick fix suggestion for this issue, or <code>null</code>
     * if there's no suggestion.
     * 
     * @return The quick fix suggestion.
     */
    public String getQuickFixSuggestion()
    {
        return quickFixSuggestion;
    }

    /**
     * Set the quick fix suggestion for this issue. If an empty string, or <code>null</code>
     * is passed, the quick fix suggestion is set to <code>null</code>, indicating
     * there is no suggestion for the issue.
     * 
     * @param quickFixSuggestion The quick fix suggestion for the issue.
     */
    public void setQuickFixSuggestion(String quickFixSuggestion)
    {
        if ((quickFixSuggestion == null) || (quickFixSuggestion.length() == 0))
        {
            this.quickFixSuggestion = null;
        }
        else
        {
            this.quickFixSuggestion = quickFixSuggestion;
        }
    }

    /**
     * Returns the condition ID from this {@link ValidationResultData}.
     * @return The condition ID.
     */
    public String getConditionID()
    {
        return conditionID;
    }

    /**
     * Sets the Condition Id of this {@link ValidationResultData}.
     * @param conditionID The condition ID to set.
     */
    public void setConditionID(String conditionID)
    {
        this.conditionID = conditionID;
    }

    /**
     * Get line preview of validation result.
     * @return The preview text or null if no preview is available.
     */
    public String getPreview()
    {
        return preview;
    }

    /**
     * Set the validation preview that will be seen by user.
     * @param preview A preview text.
     */
    public void setPreview(String preview)
    {
        this.preview = preview;
    }

    /**
     * Get infoURL with more information about error.
     * @return The infoURL.
     */
    public String getInfoURL()
    {
        return infoURL;
    }

    /**
     * Set infoURL with more information.
     * @param infoURL the url with the info
     */
    public void setInfoURL(String url)
    {
        this.infoURL = url;
    }

    /**
     * @return the markerType
     */
    public String getMarkerType()
    {
        return markerType;
    }

    /**
     * @param markerType the markerType to set
     */
    public void setMarkerType(String markerType)
    {
        this.markerType = markerType;
    }

    /**
     * @return the list of extra values.
     */
    public List<Object> getExtra()
    {
        return this.extra;
    }

    /**
     * Appends {@code value} to the list of extras. 
     */
    public void appendExtra(Object value)
    {
        extra.add(value);
    }
}