View Javadoc
1   /*
2    * Copyright 2011-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;
23  
24  import cz.zcu.mre.anonmed.rule.ProfileBuilder;
25  import cz.zcu.mre.mrelib.cipher.CipherService;
26  import java.io.File;
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * Look for anonymous identification in an external source file.
32   *
33   * @author Petr Vcelak (vcelak@kiv.zcu.cz)
34   * @since 2011-03-09
35   */
36  public final class AnonMedConfiguration {
37  
38      /**
39       * AnonMed principal text.
40       */
41      public static final String ANONMED_X500_PRINCIPAL
42              = "CN=AnonMed, OU=medical.zcu.cz, O=ZCU, C=CS";
43  
44      /**
45       * Default AnonMed password.
46       */
47      private static final String DEFAULT_PASSWORD = "AnonMed";
48      /**
49       * Change file name.
50       */
51      private Boolean changeFilename = false;
52      /**
53       * Remove original file when de-identification is complete.
54       */
55      private Boolean deleteOriginal = false;
56      /**
57       * Overwrite original. Original file is modified.
58       */
59      private Boolean overwriteFile = false;
60      /**
61       * Strict mode feature.
62       */
63      private Boolean strictMode = false;
64      /**
65       * List of all files for processing.
66       */
67      private List<File> inputFiles = new ArrayList<>();
68      /**
69       * Output directory.
70       */
71      private File outputDirectory = null;
72      /**
73       * Profiles for medical data types.
74       */
75      private ProfileBuilder profileBuilder = null;
76      /**
77       * Output directory for files that are uncertain.
78       */
79      private File uncertainDirectory = null;
80  
81      /**
82       * Directory with key stores.
83       */
84      private File keystoresDirectory = null;
85  
86      private String password = DEFAULT_PASSWORD;
87      /**
88       * Cipher service.
89       */
90      private CipherService cipherService = null;
91  
92      private String context = null;
93  
94      /**
95       * Is changing file name allowed.
96       *
97       * @return True if it is allowed.
98       */
99      public Boolean isChangeFilename() {
100         return changeFilename;
101     }
102 
103     /**
104      * Set if change file name is allowed.
105      *
106      * @param value True if it is allowed to change the file name.
107      */
108     public void setChangeFilename(final Boolean value) {
109         this.changeFilename = value;
110     }
111 
112     /**
113      * Should original be deleted?
114      *
115      * @return True if it is allowed.
116      */
117     public Boolean isDeleteOriginal() {
118         return deleteOriginal;
119     }
120 
121     /**
122      * Set if original file deletion is allowed.
123      *
124      * @param delete set true if original file have to be deleted.
125      */
126     public void setDeleteOriginal(final Boolean delete) {
127         this.deleteOriginal = delete;
128     }
129 
130     /**
131      * Should the original file be overwritten?
132      *
133      * @return True if it is allowed.
134      */
135     public Boolean isOverwriteFile() {
136         return overwriteFile;
137     }
138 
139     /**
140      * Set if original file should be overwritten.
141      *
142      * @param overwrite True if it is allowed/requested.
143      */
144     public void setOverwriteFile(final Boolean overwrite) {
145         this.overwriteFile = overwrite;
146     }
147 
148     /**
149      * Is strict mode enabled?
150      *
151      * @return True if strict mode is enabled.
152      */
153     public Boolean isStrictMode() {
154         return strictMode;
155     }
156 
157     /**
158      * Set strict mode.
159      *
160      * @param strict True if this mode is requested.
161      */
162     public void setStrictMode(final Boolean strict) {
163         this.strictMode = strict;
164     }
165 
166     /**
167      * Get input files list.
168      *
169      * @return input files list.
170      */
171     public List<File> getInputFiles() {
172         return inputFiles;
173     }
174 
175     /**
176      * Set input files.
177      *
178      * @param files input files.
179      */
180     public void setInputFiles(final List<File> files) {
181         this.inputFiles = files;
182     }
183 
184     /**
185      * Get output directory.
186      *
187      * @return output directory.
188      */
189     public File getOutputDirectory() {
190         return outputDirectory;
191     }
192 
193     /**
194      * Set output directory.
195      *
196      * @param output output directory.
197      */
198     public void setOutputDirectory(final File output) {
199 
200         if (!output.exists()
201                 || !output.isDirectory()
202                 || !output.canWrite()) {
203             throw new AnonMedException("Output directory "
204                     + output.getAbsolutePath()
205                     + " does not exist, it is not a directory "
206                     + "or permission to write is missing.", -1);
207         }
208         this.outputDirectory = output;
209     }
210 
211     /**
212      * Get profile builder.
213      *
214      * @return profile builder.
215      */
216     public ProfileBuilder getProfileBuilder() {
217         return profileBuilder;
218     }
219 
220     /**
221      * Get profile or rules builder.
222      *
223      * @param builder profile/rules builder.
224      */
225     public void setProfileBuilder(final ProfileBuilder builder) {
226         this.profileBuilder = builder;
227     }
228 
229     /**
230      * Get uncertain directory.
231      *
232      * @return uncertain directory.
233      */
234     public File getUncertainDirectory() {
235         return uncertainDirectory;
236     }
237 
238     /**
239      * Set uncertain directory.
240      *
241      * @param dir uncertain directory.
242      */
243     public void setUncertainDirectory(final File dir) {
244 
245         if (!dir.exists() || !dir.isDirectory() || !dir.canWrite()) {
246             throw new AnonMedException("Uncertain output directory "
247                     + dir.getAbsolutePath()
248                     + " does not exist, it is not a directory "
249                     + "or permission to write is missing.", -1);
250         }
251 
252         this.uncertainDirectory = dir;
253     }
254 
255     /**
256      * Set directory for key stores.
257      *
258      * @param directory output directory.
259      */
260     public void setKeystoresDirectory(final File directory) {
261 
262         if (!directory.exists()
263                 || !directory.isDirectory()
264                 || !directory.canWrite()) {
265             throw new AnonMedException("KeyStore directory "
266                     + directory.getAbsolutePath()
267                     + " does not exist, it is not a directory "
268                     + "or permission to write is missing.", -1);
269         }
270         this.keystoresDirectory = directory;
271     }
272 
273     public File getKeystoresDirectory() {
274         return keystoresDirectory;
275     }
276 
277     public CipherService getCipherService() {
278         return cipherService;
279     }
280 
281     public void setCipherService(CipherService cipherService) {
282         this.cipherService = cipherService;
283     }
284 
285     public String getPassword() {
286         return password;
287     }
288 
289     public void setPassword(String password) {
290         this.password = password;
291     }
292 
293     public void setContext(String context) {
294         this.context = context;
295     }
296 
297     public String getContext() {
298         return context;
299     }
300 
301 }