Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
PersonNameValidator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.datamodel.persons;
20 
21 import java.util.Collection;
22 import java.util.Set;
23 import java.util.stream.Collectors;
24 import java.util.stream.Stream;
25 import org.apache.commons.lang3.StringUtils;
26 import org.openide.util.NbBundle;
27 import org.sleuthkit.datamodel.Person;
28 
32 public class PersonNameValidator {
33 
45  @NbBundle.Messages({
46  "PersonNameValidator_getValidationMessage_onEmpty=Please provide some text for the person name.",
47  "PersonNameValidator_getValidationMessage_sameAsOriginal=Please provide a new name for this person.",
48  "PersonNameValidator_getValidationMessage_onDuplicate=Another person already has the same name. Please choose a different name.",})
49  public static String getValidationMessage(String curName, String initialName, Set<String> currentPersonsTrimmedUpper) {
50 
51  if (StringUtils.isBlank(curName)) {
52  return Bundle.PersonNameValidator_getValidationMessage_onEmpty();
53  }
54 
55  if (StringUtils.equalsIgnoreCase(initialName, curName)) {
56  return Bundle.PersonNameValidator_getValidationMessage_sameAsOriginal();
57  }
58 
59  if (currentPersonsTrimmedUpper.contains(curName.trim().toUpperCase())) {
60  return Bundle.PersonNameValidator_getValidationMessage_onDuplicate();
61  }
62 
63  return null;
64  }
65 
73  public static Set<String> getSanitizedPersonNames(Collection<Person> persons) {
74  Stream<Person> personsStream = persons != null ? persons.stream() : Stream.empty();
75  return personsStream
76  .map(h -> h == null ? null : h.getName())
77  .filter(hName -> StringUtils.isNotBlank(hName))
78  .map(hName -> hName.trim().toUpperCase())
79  .collect(Collectors.toSet());
80  }
81 }
static String getValidationMessage(String curName, String initialName, Set< String > currentPersonsTrimmedUpper)
static Set< String > getSanitizedPersonNames(Collection< Person > persons)

Copyright © 2012-2022 Basis Technology. Generated on: Wed Dec 7 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.