Revize 855c1138
Přidáno uživatelem stepanekp před asi 3 roky(ů)
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/detectors/UnknownPosterDetectorImpl.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors; |
|
2 |
|
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.DatabaseConnection; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResultItem; |
|
7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.ResultDetail; |
|
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.Percentage; |
|
9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils; |
|
10 |
import org.slf4j.Logger; |
|
11 |
import org.slf4j.LoggerFactory; |
|
12 |
|
|
13 |
import java.sql.ResultSet; |
|
14 |
import java.sql.SQLException; |
|
15 |
import java.util.*; |
|
16 |
|
|
17 |
public class UnknownPosterDetectorImpl implements AntiPatternDetector { |
|
18 |
|
|
19 |
private final Logger LOGGER = LoggerFactory.getLogger(UnknownPosterDetectorImpl.class); |
|
20 |
|
|
21 |
public final String configJsonFileName = "UnknownPoster.json"; |
|
22 |
|
|
23 |
private AntiPattern antiPattern; |
|
24 |
|
|
25 |
private final List<String> SQL_FILE_NAMES = Arrays.asList( |
|
26 |
"set_project_id.sql", |
|
27 |
"select_all_persons_without_full_name.sql", |
|
28 |
"select_identities_without_valid_information.sql" |
|
29 |
); |
|
30 |
|
|
31 |
// sql queries loaded from sql file |
|
32 |
private List<String> sqlQueries; |
|
33 |
|
|
34 |
private List<String> getSearchSubstringsInvalidNames(Map<String, String> thresholds) { |
|
35 |
return Arrays.asList(thresholds.get("searchSubstringsInvalidNames").split("\\|\\|")); |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public String getJsonFileName(){ |
|
40 |
return this.configJsonFileName; |
|
41 |
} |
|
42 |
|
|
43 |
@Override |
|
44 |
public void setAntiPattern(AntiPattern antiPattern) { |
|
45 |
this.antiPattern = antiPattern; |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public AntiPattern getAntiPatternModel() { |
|
50 |
return this.antiPattern; |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public List<String> getSqlFileNames() { |
|
55 |
return this.SQL_FILE_NAMES; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public void setSqlQueries(List<String> queries) { |
|
60 |
this.sqlQueries = queries; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* |
|
65 |
*/ |
|
66 |
@Override |
|
67 |
public QueryResultItem analyze(Project project, DatabaseConnection databaseConnection, Map<String, String> thresholds) { |
|
68 |
List<String> queriesFirstPart = this.sqlQueries.subList(0, 2); |
|
69 |
List<String> queriesSecondPart = this.sqlQueries.subList(2, 3); |
|
70 |
|
|
71 |
List<List<Map<String, Object>>> resultSets = databaseConnection.executeQueriesWithMultipleResults(project, queriesFirstPart); |
|
72 |
|
|
73 |
int resultNumber = 0; |
|
74 |
for(Map<String, Object> result : resultSets.get(0)) { |
|
75 |
List<String> invalidIds = new ArrayList<>(); |
|
76 |
invalidIds.add(result.get("id").toString()); |
|
77 |
|
|
78 |
List<String> substringsInvalidNames = getSearchSubstringsInvalidNames(thresholds); |
|
79 |
for(String substring : substringsInvalidNames) |
|
80 |
invalidIds.add(substring); |
|
81 |
|
|
82 |
List<List<Map<String, Object>>> resultsForInvalidIds = databaseConnection.executeQueriesWithMultipleResults(project, Utils.fillQueryWithSearchSubstrings(queriesSecondPart, invalidIds)); |
|
83 |
|
|
84 |
if(Integer.parseInt(resultsForInvalidIds.get(0).get(0).get("count(i.id)").toString()) == 0) |
|
85 |
resultNumber++; |
|
86 |
} |
|
87 |
|
|
88 |
List<ResultDetail> resultDetails = new ArrayList<>(); |
|
89 |
resultDetails.add(new ResultDetail("Number of unknown contributors", String.valueOf(resultNumber))); |
|
90 |
|
|
91 |
if(resultNumber > 0) |
|
92 |
return new QueryResultItem(this.antiPattern, true, resultDetails); |
|
93 |
|
|
94 |
return new QueryResultItem(this.antiPattern, false, resultDetails); |
|
95 |
} |
|
96 |
} |
Také k dispozici: Unified diff
Unknown Poster antipattern detection added