Skip to content

Commit

Permalink
Issue #91: Adjusted pages to changed API.
Browse files Browse the repository at this point in the history
  • Loading branch information
haumacher committed Nov 30, 2024
1 parent c734341 commit 37fd471
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import de.haumacher.phoneblock.analysis.NumberAnalyzer;
import de.haumacher.phoneblock.db.AggregationInfo;
import de.haumacher.phoneblock.db.DB;
import de.haumacher.phoneblock.db.DBNumbersEntry;
import de.haumacher.phoneblock.db.DBNumberInfo;
import de.haumacher.phoneblock.db.DBService;
import de.haumacher.phoneblock.db.Ratings;
import de.haumacher.phoneblock.db.SpamReports;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import de.haumacher.phoneblock.analysis.NumberBlock;
import de.haumacher.phoneblock.analysis.NumberTree;
import de.haumacher.phoneblock.db.BlockList;
import de.haumacher.phoneblock.db.DBNumbersEntry;
import de.haumacher.phoneblock.db.DBNumberInfo;
import de.haumacher.phoneblock.db.DBService;
import de.haumacher.phoneblock.db.SpamReports;
import de.haumacher.phoneblock.db.Users;
Expand Down Expand Up @@ -176,10 +176,10 @@ private List<NumberBlock> getCommonNumbers(SpamReports reports, ListType listTyp

private List<NumberBlock> loadNumbers(SpamReports reports, List<String> personalizations, Set<String> exclusions,
ListType listType) {
List<DBNumbersEntry> result = reports.getReports();
List<DBNumberInfo> result = reports.getReports();
long now = System.currentTimeMillis();
NumberTree numberTree = new NumberTree();
for (DBNumbersEntry report : result) {
for (DBNumberInfo report : result) {
String phone = report.getPhone();

int votes = report.getVotes();
Expand Down
14 changes: 7 additions & 7 deletions phoneblock/src/main/java/de/haumacher/phoneblock/db/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private Rating rating(SpamReports reports, String phone) {
}

public NumberInfo getPhoneInfo(SpamReports reports, String phone) {
DBNumbersEntry result = reports.getPhoneInfo(phone);
DBNumberInfo result = reports.getPhoneInfo(phone);
return result != null ? result : NumberInfo.create().setPhone(phone);
}

Expand Down Expand Up @@ -519,7 +519,7 @@ public SqlSession openSession() {
/**
* Looks up all spam reports that were done after the given time in milliseconds since epoch.
*/
public List<DBNumbersEntry> getLatestSpamReports(long notBefore) {
public List<? extends NumberInfo> getLatestSpamReports(long notBefore) {
try (SqlSession session = openSession()) {
SpamReports reports = session.getMapper(SpamReports.class);
return reports.getLatestReports(notBefore);
Expand All @@ -543,7 +543,7 @@ List<? extends SearchInfo> getTopSearches(int cnt) {
long revisionDate = orMidnightYesterday(reports.getRevisionDate(afterRev));

List<SearchInfo> topSearches = new ArrayList<>();
for (DBNumbersEntry entry : reports.getUpdatedPhoneInfos(revisionDate)) {
for (DBNumberInfo entry : reports.getUpdatedPhoneInfos(revisionDate)) {
String phone = entry.getPhone();
int searches = entry.getSearches();
SearchInfo info = SearchInfo.create()
Expand Down Expand Up @@ -591,7 +591,7 @@ private long orMidnightYesterday(Long revisionDate) {
/**
* Looks all spam reports.
*/
public List<DBNumbersEntry> getAll(int limit) {
public List<DBNumberInfo> getAll(int limit) {
try (SqlSession session = openSession()) {
SpamReports reports = session.getMapper(SpamReports.class);
return reports.getAll(limit);
Expand All @@ -601,7 +601,7 @@ public List<DBNumbersEntry> getAll(int limit) {
/**
* Looks up spam reports with the most votes in the last month.
*/
public List<DBNumbersEntry> getTopSpamReports(int cnt) {
public List<DBNumberInfo> getTopSpamReports(int cnt) {
Calendar cal = GregorianCalendar.getInstance();
cal.add(Calendar.MONTH, -1);
cal.set(Calendar.HOUR_OF_DAY, 0);
Expand All @@ -617,7 +617,7 @@ public List<DBNumbersEntry> getTopSpamReports(int cnt) {
/**
* Looks up the newest entries in the blocklist.
*/
public List<DBNumbersEntry> getLatestBlocklistEntries(String login) {
public List<DBNumberInfo> getLatestBlocklistEntries(String login) {
try (SqlSession session = openSession()) {
SpamReports reports = session.getMapper(SpamReports.class);

Expand All @@ -642,7 +642,7 @@ public Blocklist getBlockListAPI(int minVotes) {
}
}

private static BlockListEntry toBlocklistEntry(DBNumbersEntry n) {
private static BlockListEntry toBlocklistEntry(DBNumberInfo n) {
return BlockListEntry.create()
.setPhone(n.getPhone())
.setVotes(n.getVotes())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
/**
* Data class for DB access.
*/
public class DBNumbersEntry extends NumberInfo {
public class DBNumberInfo extends NumberInfo {

/**
* Creates a {@link DBBlockListEntry}.
*/
public DBNumbersEntry(String phone, long added, long updated, boolean active, int calls, int votes, int legitimate, int ping, int poll, int advertising, int gamble, int fraud, int searches) {
public DBNumberInfo(String phone, long added, long updated, boolean active, int calls, int votes, int legitimate, int ping, int poll, int advertising, int gamble, int fraud, int searches) {
setPhone(phone)
.setAdded(added)
.setUpdated(updated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,27 @@ SELECT COUNT(1) FROM NUMBERS s
where UPDATED >= #{after} and ACTIVE
order by UPDATED desc
""")
List<DBNumbersEntry> getLatestReports(long after);
List<DBNumberInfo> getLatestReports(long after);

@Select("""
select s.PHONE, s.ADDED, s.UPDATED, s.ACTIVE, s.CALLS, s.VOTES, s.LEGITIMATE, s.PING, s.POLL, s.ADVERTISING, s.GAMBLE, s.FRAUD, s.SEARCHES from NUMBERS s
where ACTIVE
order by UPDATED desc
limit #{limit}
""")
List<DBNumbersEntry> getAll(int limit);
List<DBNumberInfo> getAll(int limit);

@Select("""
select s.PHONE, s.ADDED, s.UPDATED, s.ACTIVE, s.CALLS, s.VOTES, s.LEGITIMATE, s.PING, s.POLL, s.ADVERTISING, s.GAMBLE, s.FRAUD, s.SEARCHES from NUMBERS s
where s.PHONE = #{phone}
""")
DBNumbersEntry getPhoneInfo(String phone);
DBNumberInfo getPhoneInfo(String phone);

@Select("""
select s.PHONE, s.ADDED, s.UPDATED, s.ACTIVE, s.CALLS, s.VOTES, s.LEGITIMATE, s.PING, s.POLL, s.ADVERTISING, s.GAMBLE, s.FRAUD, s.SEARCHES from NUMBERS s
where s.UPDATED > #{updatedAfter}
""")
List<DBNumbersEntry> getUpdatedPhoneInfos(long updatedAfter);
List<DBNumberInfo> getUpdatedPhoneInfos(long updatedAfter);

@Select("""
select s.PHONE from NUMBERS s
Expand All @@ -149,20 +149,20 @@ SELECT COUNT(1) FROM NUMBERS s
WHERE ACTIVE and s.UPDATED >= #{notBefore}
ORDER BY s.VOTES DESC LIMIT #{cnt}
""")
List<DBNumbersEntry> getTopSpammers(int cnt, long notBefore);
List<DBNumberInfo> getTopSpammers(int cnt, long notBefore);

@Select("""
select s.PHONE, s.ADDED, s.UPDATED, s.ACTIVE, s.CALLS, s.VOTES, s.LEGITIMATE, s.PING, s.POLL, s.ADVERTISING, s.GAMBLE, s.FRAUD, s.SEARCHES from NUMBERS s
WHERE ACTIVE and VOTES >= #{minVotes} AND DATEADDED > 0 ORDER BY DATEADDED DESC LIMIT 10
""")
List<DBNumbersEntry> getLatestBlocklistEntries(int minVotes);
List<DBNumberInfo> getLatestBlocklistEntries(int minVotes);

@Select("""
select s.PHONE, s.ADDED, s.UPDATED, s.ACTIVE, s.CALLS, s.VOTES, s.LEGITIMATE, s.PING, s.POLL, s.ADVERTISING, s.GAMBLE, s.FRAUD, s.SEARCHES from NUMBERS s
where s.ACTIVE and s.VOTES >= #{minVotes}
order by s.PHONE
""")
List<DBNumbersEntry> getBlocklist(int minVotes);
List<DBNumberInfo> getBlocklist(int minVotes);

@Select("""
SELECT x.PHONE FROM NUMBERS x
Expand All @@ -188,7 +188,7 @@ WHERE h.PHONE IN (
ORDER BY s.SEARCHES - i.SEARCHES DESC
LIMIT 10;
""")
List<DBNumbersEntry> getTopSearches(long revTime);
List<DBNumberInfo> getTopSearches(long revTime);

/**
* Retrieves all historic versions for the given number not older than the given revision.
Expand Down Expand Up @@ -228,13 +228,13 @@ WHERE h.PHONE IN (
</foreach>
</script>
""")
List<DBNumbersEntry> getNumbers(Collection<String> numbers);
List<DBNumberInfo> getNumbers(Collection<String> numbers);

@Select("""
select s.PHONE, s.ADDED, s.UPDATED, s.ACTIVE, s.CALLS, s.VOTES, s.LEGITIMATE, s.PING, s.POLL, s.ADVERTISING, s.GAMBLE, s.FRAUD, s.SEARCHES from NUMBERS s
where ACTIVE
""")
List<DBNumbersEntry> getReports();
List<DBNumberInfo> getReports();

@Select("""
select PHONE from WHITELIST
Expand Down
9 changes: 5 additions & 4 deletions phoneblock/src/main/webapp/phone-info.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!DOCTYPE html>
<%@page import="de.haumacher.phoneblock.db.model.PhoneInfo"%>
<%@page import="de.haumacher.phoneblock.app.UIProperties"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@page import="de.haumacher.phoneblock.app.api.CommentVoteServlet"%>
Expand Down Expand Up @@ -28,11 +29,11 @@
<html>
<%
PhoneNumer analysis = (PhoneNumer) request.getAttribute("number");
SpamReport info = (SpamReport) request.getAttribute("info");
PhoneInfo info = (PhoneInfo) request.getAttribute("info");
Rating rating = (Rating) request.getAttribute("rating");
List<String> relatedNumbers = (List<String>) request.getAttribute("relatedNumbers");
Map<Rating, Integer> ratings = (Map<Rating, Integer>) request.getAttribute("ratings");
List<? extends SearchInfo> searches = (List<? extends SearchInfo>) request.getAttribute("searches");
List<Integer> searches = (List<Integer>) request.getAttribute("searches");
boolean thanks = request.getAttribute("thanks") != null;
Expand Down Expand Up @@ -398,7 +399,7 @@
boolean first = true;
for (SearchInfo r : searches) {
for (Integer r : searches) {
if (first) {
first = false;
} else {
Expand All @@ -407,7 +408,7 @@
}
labels.append(fmt.format(date.getTime()));
date.add(Calendar.DAY_OF_MONTH, 1);
data.append(r.getCount());
data.append(r.intValue());
}
%>
<div id="searches-data" searches-labels="<%=labels.toString()%>" searches-dataset="<%=data.toString()%>">
Expand Down
22 changes: 12 additions & 10 deletions phoneblock/src/main/webapp/status.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<!DOCTYPE html>
<%@page import="de.haumacher.phoneblock.db.model.NumberInfo"%>
<%@page import="de.haumacher.phoneblock.db.DBNumberInfo"%>
<%@page import="de.haumacher.phoneblock.db.model.SearchInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%>
<%@page import="de.haumacher.phoneblock.app.LoginFilter"%>
Expand Down Expand Up @@ -134,7 +136,7 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc
%>

<%
List<? extends SpamReport> reports = DBService.getInstance().getLatestSpamReports(System.currentTimeMillis() - 60 * 60 * 1000);
List<? extends NumberInfo> reports = DBService.getInstance().getLatestSpamReports(System.currentTimeMillis() - 60 * 60 * 1000);
if (!reports.isEmpty()) {
%>
<h2>Spam-Reports der letzten Stunde</h2>
Expand All @@ -150,7 +152,7 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc
</thead>
<tbody>
<%
for (SpamReport report : reports) {
for (NumberInfo report : reports) {
%>
<tr>
<td>
Expand All @@ -162,11 +164,11 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc
</td>

<td>
<%= (now - report.getLastUpdate()) / 1000 / 60 %> minutes ago
<%= (now - report.getUpdated()) / 1000 / 60 %> minutes ago
</td>

<td>
<%= report.getDateAdded() > 0 ? format.format(new Date(report.getDateAdded())) : "-" %>
<%= report.getAdded() > 0 ? format.format(new Date(report.getAdded())) : "-" %>
</td>
</tr>
<%
Expand Down Expand Up @@ -195,7 +197,7 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc
</thead>
<tbody>
<%
for (SpamReport report : reports) {
for (NumberInfo report : reports) {
%>
<tr>
<td>
Expand All @@ -207,11 +209,11 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc
</td>

<td>
<%= format.format(new Date(report.getLastUpdate()))%>
<%= format.format(new Date(report.getUpdated()))%>
</td>

<td>
<%= report.getDateAdded() > 0 ? format.format(new Date(report.getDateAdded())) : "-" %>
<%= report.getAdded() > 0 ? format.format(new Date(report.getAdded())) : "-" %>
</td>
</tr>
<%
Expand Down Expand Up @@ -240,7 +242,7 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc
</thead>
<tbody>
<%
for (SpamReport report : reports) {
for (NumberInfo report : reports) {
%>
<tr>
<td>
Expand All @@ -252,11 +254,11 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc
</td>

<td>
<%= format.format(new Date(report.getLastUpdate()))%>
<%= format.format(new Date(report.getUpdated()))%>
</td>

<td>
<%= report.getDateAdded() > 0 ? format.format(new Date(report.getDateAdded())) : "-" %>
<%= report.getAdded() > 0 ? format.format(new Date(report.getAdded())) : "-" %>
</td>
</tr>
<%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void testSpamReports() {

assertEquals(1006, _db.getLastSpamReport().longValue());

List<DBNumbersEntry> reports = _db.getLatestSpamReports(1001);
List<? extends NumberInfo> reports = _db.getLatestSpamReports(1001);
assertEquals(3, reports.size());
assertEquals("456", reports.get(2).getPhone());
assertEquals("999", reports.get(1).getPhone());
Expand Down

0 comments on commit 37fd471

Please sign in to comment.