com.strider.datadefender.specialcase.PhiDetector   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 40
ccs 0
cts 12
cp 0
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A isPhiTerm(ColumnMetaData,String) 0 14 4
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 java.io.BufferedReader;
20
import java.io.FileReader;
21
import java.io.IOException;
22
23
import java.util.ArrayList;
24
import java.util.List;
25
import java.util.Locale;
26
27
import com.strider.datadefender.discoverer.Probability;
28
import com.strider.datadefender.database.metadata.TableMetaData.ColumnMetaData;
29
import java.util.Objects;
30
31
import lombok.extern.log4j.Log4j2;
32
import org.apache.commons.lang3.StringUtils;
33
34
/**
35
 * @author Armenak Grigoryan
36
 */
37
@Log4j2
38
public class PhiDetector implements SpecialCase {
39
40
    private static final String PHI_FILE = "phi.txt";
41
    private static List         phiList  = new ArrayList();
42
43
    static {
44
        try {
45
            log.info("*** reading from " + PHI_FILE);
46
47
            try (BufferedReader br = new BufferedReader(new FileReader(PHI_FILE))) {
48
                for (String line; (line = br.readLine()) != null; ) {
49
                    phiList.add(line);
50
                }
51
            }
52
        } catch (IOException ioe) {
53
            log.error(ioe.toString());
54
        }
55
    }
56
57
    /**
58
     * Generates random 9-digit student number
59
     * @param data
60
     * @param text
61
     * @return String
62
     */
63
    public static ColumnMatch isPhiTerm(final ColumnMetaData data, final String text) {
64
        if (StringUtils.isNotBlank(text)
65
            && Objects.equals(String.class, data.getColumnType())
66
            && phiList.contains(text.trim().toLowerCase(Locale.ENGLISH))) {
67
            
68
            log.debug("PHI detected: " + text);
69
            return new ColumnMatch(
70
                data,
71
                100.0,
72
                "phi",
73
                List.of(new Probability(text, 1.00))
74
            );
75
        }
76
        return null;
77
    }
78
}