View Javadoc
1   /*
2    * Copyright 2010-2024 Medical Information Systems Research Group (https://medical.zcu.cz),
3    * Department of Computer Science and Engineering, University of West Bohemia.
4    * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5    *
6    * Author Petr Vcelak (vcelak@kiv.zcu.cz).
7    *
8    * This file is part of AnonMed project.
9    *
10   * AnonMed is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU General Public License as published by
12   * the Free Software Foundation, either version 3 of the License.
13   *
14   * AnonMed is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with AnonMed. If not, see <http://www.gnu.org/licenses/>.
21   */
22  package cz.zcu.mre.anonmed.rule;
23  
24  /**
25   * A single anonymizer rule description.
26   *
27   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
28   * @since 2011-03-08
29   */
30  public class Rule {
31  
32      /**
33       * Each rule has seven (7) columns that describes the rule.
34       */
35      public static final int RULE_COLUMNS = 7;
36  
37      /**
38       * File type group.
39       */
40      private String fileType;
41  
42      /**
43       * Order number of the rule.
44       */
45      private Integer order;
46  
47      /**
48       * Optional rule name.
49       */
50      private String name;
51  
52      /**
53       * Rule is an element path (XPath), tag name, or other proper identification
54       * used in anonymizer.
55       */
56      private String rule;
57  
58      /**
59       * Optional, condition -- it limits the selected tag.
60       */
61      private String condition;
62  
63      /**
64       * What to do with the selected tag.
65       */
66      private Operation operation;
67  
68      /**
69       * New newValue, or other the operation specific meaning.
70       *
71       * It is used for an external application path, to use with an
72       * EXTERNAL_APPLICATION operation, for example.
73       */
74      private String newValue;
75  
76      /**
77       * Get condition.
78       *
79       * @return condition.
80       */
81      public final String getCondition() {
82          return condition;
83      }
84  
85      /**
86       * Set condition.
87       *
88       * @param cond condition to set.
89       */
90      public final void setCondition(
91              final String cond) {
92  
93          this.condition = cond;
94      }
95  
96      /**
97       * Get file type.
98       *
99       * @return file type.
100      */
101     public final String getFileType() {
102 
103         return fileType;
104     }
105 
106     /**
107      * Set file type.
108      *
109      * @param type file type.
110      */
111     public final void setFileType(
112             final String type) {
113 
114         if (type != null) {
115             this.fileType = type;
116         }
117     }
118 
119     /**
120      * Get rule name.
121      *
122      * @return name.
123      */
124     public final String getName() {
125 
126         return name;
127     }
128 
129     /**
130      * Set rule name.
131      *
132      * @param value rule name.
133      */
134     public final void setName(
135             final String value) {
136 
137         this.name = value;
138     }
139 
140     /**
141      * Get rule operation.
142      *
143      * @return operation.
144      */
145     public final Operation getOperation() {
146         return operation;
147     }
148 
149     /**
150      * Set operation.
151      *
152      * @param value Operation.
153      */
154     public final void setOperation(
155             final Operation value) {
156 
157         this.operation = value;
158     }
159 
160     /**
161      * Set operation as string.
162      *
163      * @param value String operation code.
164      */
165     public final void setOperation(
166             final String value) {
167 
168         if (value != null) {
169             setOperation(Operation.valueOf(value));
170         }
171     }
172 
173     /**
174      * Get rule order.
175      *
176      * @return order.
177      */
178     public final Integer getOrder() {
179         return order;
180     }
181 
182     /**
183      * Set rule order newValue.
184      *
185      * @param value rule order.
186      */
187     public final void setOrder(
188             final Integer value) {
189 
190         this.order = value;
191     }
192 
193     /**
194      * Set order as string newValue.
195      *
196      * @param value integer newValue as a string.
197      */
198     public final void setOrder(
199             final String value) {
200 
201         if (value != null) {
202             setOrder(Integer.valueOf(value));
203         }
204     }
205 
206     /**
207      * Get rule.
208      *
209      * @return rule
210      */
211     public final String getRule() {
212 
213         return rule;
214     }
215 
216     /**
217      * Set rule string.
218      *
219      * @param r rule string.
220      */
221     public final void setRule(
222             final String r) {
223 
224         this.rule = r;
225     }
226 
227     /**
228      * Get rule newValue.
229      *
230      * @return rule newValue.
231      */
232     public final String getNewValue() {
233 
234         return newValue;
235     }
236 
237     /**
238      * Set rule newValue.
239      *
240      * @param value rule newValue.
241      */
242     public final void setNewValue(
243             final String value) {
244 
245         this.newValue = value;
246     }
247 
248     /**
249      * Set all rule fields.
250      *
251      * @param row string array.
252      */
253     public final void setAll(
254             final String[] row) {
255 
256         int i = 0;
257         setFileType(row[i++]);
258         setOrder(row[i++]);
259         setRule(row[i++]);
260         setOperation(row[i++]);
261         setNewValue(row[i++]);
262         setName(row[i++]);
263         setCondition(row[i++]);
264     }
265 
266     /**
267      * Get Rule as a String.
268      *
269      * @return String representation of the Rule.
270      */
271     @Override
272     public final String toString() {
273         return "Rule{" + "fileType=" + fileType + ", order=" + order
274                 + ", name=" + name + ", rule=" + rule
275                 + ", condition=" + condition + ", operation=" + operation
276                 + ", value=" + newValue + '}';
277     }
278 
279 }