Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
UserInputErrorManager.java
Go to the documentation of this file.
1 /*
2  *
3  * Autopsy Forensic Browser
4  *
5  * Copyright 2018 Basis Technology Corp.
6  * Contact: carrier <at> sleuthkit <dot> org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 package org.sleuthkit.autopsy.commonpropertiessearch;
21 
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.stream.Collectors;
26 import org.openide.util.NbBundle;
27 
31 class UserInputErrorManager {
32 
33  static final int FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY = 1;
34  static final int NO_FILE_CATEGORIES_SELECTED_KEY = 2;
35 
36  private final Map<Integer, ErrorMessage> currentErrors;
37 
43  @NbBundle.Messages({
44  "UserInputErrorManager.frequency=Invalid Frequency Percentage: 0 < % < 100.",
45  "UserInputErrorManager.categories=No file categories are included in the search."})
46  UserInputErrorManager (){
47 
48  //when new errors are needed for the dialog, define a key and a value
49  // and add them to the map.
50 
51  this.currentErrors = new HashMap<>();
52  this.currentErrors.put(FREQUENCY_PERCENTAGE_OUT_OF_RANGE_KEY, new ErrorMessage(Bundle.UserInputErrorManager_frequency()));
53  this.currentErrors.put(NO_FILE_CATEGORIES_SELECTED_KEY, new ErrorMessage(Bundle.UserInputErrorManager_categories()));
54  }
55 
61  void setError(int errorId, boolean errorState){
62  if(this.currentErrors.containsKey(errorId)){
63  this.currentErrors.get(errorId).setStatus(errorState);
64  } else {
65  throw new IllegalArgumentException(String.format("The given errorId is not mapped to an ErrorMessage: %s.", errorId));
66  }
67  }
68 
73  boolean anyErrors(){
74  return this.currentErrors.values().stream().anyMatch(errorMessage -> errorMessage.isErrorSet() == true);
75  }
76 
80  List<String> getErrors(){
81  return this.currentErrors.values().stream()
82  .filter(errorMessage -> errorMessage.isErrorSet() == true)
83  .map(ErrorMessage::getMessage)
84  .collect(Collectors.toList());
85  }
86 
91  private class ErrorMessage {
92 
93  private final String message;
94  private boolean status;
95 
101  ErrorMessage(String message){
102  this.message = message;
103  this.status = false;
104  }
105 
110  void setStatus(boolean status){
111  this.status = status;
112  }
113 
118  String getMessage(){
119  return this.message;
120  }
121 
126  boolean isErrorSet(){
127  return this.status;
128  }
129  }
130 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.