|
1
|
|
|
/** |
|
2
|
|
|
* Copyright 2014-2020, Armenak Grigoryan, and individual contributors as indicated |
|
3
|
|
|
* by the @authors tag. See the copyright.txt in the distribution for a |
|
4
|
|
|
* full listing of individual contributors. |
|
5
|
|
|
* |
|
6
|
|
|
* This is free software; you can redistribute it and/or modify it |
|
7
|
|
|
* under the terms of the GNU Lesser General Public License as |
|
8
|
|
|
* published by the Free Software Foundation; either version 2.1 of |
|
9
|
|
|
* the License, or (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This software is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14
|
|
|
* Lesser General Public License for more details. |
|
15
|
|
|
*/ |
|
16
|
|
|
package com.strider.datadefender.specialcase; |
|
17
|
|
|
|
|
18
|
|
|
import com.strider.datadefender.discoverer.Discoverer.ColumnMatch; |
|
19
|
|
|
import org.apache.commons.validator.routines.EmailValidator; |
|
20
|
|
|
|
|
21
|
|
|
import com.strider.datadefender.database.metadata.TableMetaData; |
|
22
|
|
|
import com.strider.datadefender.database.metadata.TableMetaData.ColumnMetaData; |
|
23
|
|
|
|
|
24
|
|
|
import lombok.extern.log4j.Log4j2; |
|
25
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @author Armenak Grigoryan |
|
29
|
|
|
*/ |
|
30
|
|
|
@Log4j2 |
|
31
|
|
|
public class EmailDetector implements SpecialCase { |
|
32
|
|
|
|
|
33
|
|
|
public static ColumnMatch detectEmail(final ColumnMetaData metaData, final String text) { |
|
34
|
|
|
if (StringUtils.isNotBlank(text) && isValidEmail(text)) { |
|
35
|
|
|
log.debug("Email detected: " + text); |
|
36
|
|
|
return new ColumnMatch(metaData, 1.0, "email", null); |
|
37
|
|
|
} else { |
|
38
|
|
|
log.debug("Email " + text + " is not a valid email"); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param email Email address |
|
46
|
|
|
* @return true if email is valid, otherwise false |
|
47
|
|
|
*/ |
|
48
|
|
|
private static boolean isValidEmail(final String email) { |
|
49
|
|
|
|
|
50
|
|
|
EmailValidator eValidator = EmailValidator.getInstance(); |
|
51
|
|
|
if (eValidator.isValid(email)) { |
|
52
|
|
|
log.debug("*************** Email " + email + " is valid"); |
|
53
|
|
|
return true; |
|
54
|
|
|
} else { |
|
55
|
|
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|