Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ValidationResult |
|
| 2.125;2.125 | ||||
ValidationResult$ErrorLevel |
|
| 2.125;2.125 |
1 | /* | |
2 | * Copyright 2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the | |
5 | * "License"); you may not use this file except in compliance with the | |
6 | * License. You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.osedu.org/licenses/ECL-2.0 | |
9 | * | |
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 | |
13 | * implied. See the License for the specific language governing | |
14 | * permissions and limitations under the License. | |
15 | */ | |
16 | package org.kuali.student.r2.common.infc; | |
17 | ||
18 | public interface ValidationResult { | |
19 | ||
20 | 0 | public enum ErrorLevel { |
21 | ||
22 | 0 | OK(0), WARN(1), ERROR(2); |
23 | int level; | |
24 | ||
25 | 0 | private ErrorLevel(int level) { |
26 | 0 | this.level = level; |
27 | 0 | } |
28 | ||
29 | public int getLevel() { | |
30 | 0 | return level; |
31 | } | |
32 | ||
33 | public static ErrorLevel fromInt(int level) { | |
34 | 0 | switch (level) { |
35 | case 0: | |
36 | 0 | return OK; |
37 | case 1: | |
38 | 0 | return WARN; |
39 | case 2: | |
40 | 0 | return ERROR; |
41 | default: | |
42 | 0 | throw new IllegalArgumentException(level + ""); |
43 | } | |
44 | } | |
45 | ||
46 | public static ErrorLevel min(ErrorLevel e1, ErrorLevel e2) { | |
47 | 0 | return e1.ordinal() < e2.ordinal() ? e1 : e2; |
48 | } | |
49 | ||
50 | public static ErrorLevel max(ErrorLevel e1, ErrorLevel e2) { | |
51 | 0 | return e1.ordinal() > e2.ordinal() ? e1 : e2; |
52 | } | |
53 | } | |
54 | ||
55 | /** | |
56 | * Message explaining this validation result | |
57 | * | |
58 | * If an error it is an an error message. | |
59 | * | |
60 | * TODO: decide if this is a key that then gets resolved into a | |
61 | * real localized message using the message service or the final | |
62 | * localized message itself | |
63 | * | |
64 | * @name Message | |
65 | * @readOnly | |
66 | */ | |
67 | public String getMessage(); | |
68 | ||
69 | /** | |
70 | * Identifies the element (field) that is the focus of the | |
71 | * validation. Uses xpath (dot) notation to navigate to the | |
72 | * field, for example: officialIdentifier.code | |
73 | * | |
74 | * TODO: find out how repeating substructures are handled in this | |
75 | * notation, with [n] occurrence brackets? | |
76 | * | |
77 | * @name Element | |
78 | * @readOnly | |
79 | * @required | |
80 | */ | |
81 | public String getElement(); | |
82 | ||
83 | /** | |
84 | * Indicates the severity of the validation result. | |
85 | * | |
86 | * 0=OK | |
87 | * 1=WARN | |
88 | * 2=ERROR | |
89 | * | |
90 | * @name Level | |
91 | * @readOnly | |
92 | * @required | |
93 | */ | |
94 | public ErrorLevel getLevel(); | |
95 | ||
96 | ||
97 | ||
98 | ||
99 | } |