1 package gov.nasa.pds.vtool.validate;
2
3 import gov.nasa.pds.tools.label.validate.Status;
4
5 /***
6 * Class that can be used to save the results of a
7 * validation run.
8 *
9 * @author mcayanan
10 *
11 */
12 public class ValidationRecord implements Status {
13 private int totalErrors;
14 private int totalWarnings;
15 private int filesPassed;
16 private int filesSkipped;
17 private int filesFailed;
18
19 /***
20 * Constructor
21 *
22 */
23 public ValidationRecord() {
24 totalErrors = 0;
25 totalWarnings = 0;
26 filesPassed = 0;
27 filesSkipped = 0;
28 filesFailed = 0;
29 }
30
31 /***
32 * Constructor
33 *
34 * @param status Indicates the success or failure of a validation.
35 * @param warns Number of warnings encountered during validation.
36 * @param errors Number of errors encountered during validation.
37 *
38 * @throws UnknownLabelStatusException
39 */
40 public ValidationRecord(String status, int warns, int errors)
41 throws UnknownLabelStatusException {
42 add(status, warns, errors);
43 }
44
45 /***
46 * Record the results of a label validation.
47 *
48 * @param record A validationRecord object.
49 */
50 public void add(ValidationRecord record) {
51 totalErrors += record.getTotalErrors();
52 totalWarnings += record.getTotalWarnings();
53 filesPassed += record.getFilesPassed();
54 filesSkipped += record.getFilesSkipped();
55 filesFailed += record.getFilesFailed();
56 }
57
58 /***
59 * Record the results of a label validation.
60 *
61 * @param status Indicates the success or failure of a validation. Argument
62 * must be 'PASS', 'FAIL', or 'SKIP'.
63 * @param warns The number of warnings encountered during validation.
64 * @param errors The number of errors encountered during validation.
65 *
66 * @throws UnknownLabelStatusException
67 */
68 public void add(String status, int warns, int errors)
69 throws UnknownLabelStatusException {
70 if(status.equals(PASS)) {
71 ++filesPassed;
72 } else if(status.equals(FAIL)) {
73 ++filesFailed;
74
75 } else if(status.equals("SKIP")) {
76 ++filesSkipped;
77 } else {
78 throw new UnknownLabelStatusException("Unknown label status");
79 }
80 totalWarnings += warns;
81 totalErrors += errors;
82 }
83
84 /***
85 * Determines if any warnings are present in the record.
86 * @return 'true' if there were warnings, 'false' otherwise.
87 */
88 public boolean hasWarnings() {
89 if(totalWarnings > 0)
90 return true;
91 else
92 return false;
93 }
94
95 /***
96 * @return The total number of warnings encountered.
97 */
98 public int getTotalWarnings() {
99 return totalWarnings;
100 }
101
102 /***
103 * Determines if any errors are present in the record.
104 * @return 'true' if there were errors, 'false' otherwise.
105 */
106 public boolean hasErrors() {
107 if(totalErrors > 0)
108 return true;
109 else
110 return false;
111 }
112
113 /***
114 * @return The total number of errors encountered.
115 */
116 public int getTotalErrors() {
117 return totalErrors;
118 }
119
120 /***
121 * @return The total number of files that passed the PDS validation step.
122 */
123 public int getFilesPassed() {
124 return filesPassed;
125 }
126
127 /***
128 * @return The total number of files that skipped the PDS validation step.
129 */
130 public int getFilesSkipped() {
131 return filesSkipped;
132 }
133
134 /***
135 * @return The total number of files that failed the PDS validation step.
136 */
137 public int getFilesFailed() {
138 return filesFailed;
139 }
140 }