From 37fd471b8b7629b4b64095cb1bde1f2fc2c0e259 Mon Sep 17 00:00:00 2001 From: Bernhard Haumacher Date: Sat, 23 Nov 2024 13:35:42 +0100 Subject: [PATCH] Issue #91: Adjusted pages to changed API. --- .../phoneblock/app/SearchServlet.java | 2 +- .../carddav/resource/AddressBookCache.java | 6 ++--- .../java/de/haumacher/phoneblock/db/DB.java | 14 ++++++------ ...{DBNumbersEntry.java => DBNumberInfo.java} | 4 ++-- .../haumacher/phoneblock/db/SpamReports.java | 20 ++++++++--------- phoneblock/src/main/webapp/phone-info.jsp | 9 ++++---- phoneblock/src/main/webapp/status.jsp | 22 ++++++++++--------- .../de/haumacher/phoneblock/db/TestDB.java | 2 +- 8 files changed, 41 insertions(+), 38 deletions(-) rename phoneblock/src/main/java/de/haumacher/phoneblock/db/{DBNumbersEntry.java => DBNumberInfo.java} (70%) diff --git a/phoneblock/src/main/java/de/haumacher/phoneblock/app/SearchServlet.java b/phoneblock/src/main/java/de/haumacher/phoneblock/app/SearchServlet.java index fe2d3f1..1e9ff05 100644 --- a/phoneblock/src/main/java/de/haumacher/phoneblock/app/SearchServlet.java +++ b/phoneblock/src/main/java/de/haumacher/phoneblock/app/SearchServlet.java @@ -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; diff --git a/phoneblock/src/main/java/de/haumacher/phoneblock/carddav/resource/AddressBookCache.java b/phoneblock/src/main/java/de/haumacher/phoneblock/carddav/resource/AddressBookCache.java index e13f2bc..a2c14f4 100644 --- a/phoneblock/src/main/java/de/haumacher/phoneblock/carddav/resource/AddressBookCache.java +++ b/phoneblock/src/main/java/de/haumacher/phoneblock/carddav/resource/AddressBookCache.java @@ -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; @@ -176,10 +176,10 @@ private List getCommonNumbers(SpamReports reports, ListType listTyp private List loadNumbers(SpamReports reports, List personalizations, Set exclusions, ListType listType) { - List result = reports.getReports(); + List 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(); diff --git a/phoneblock/src/main/java/de/haumacher/phoneblock/db/DB.java b/phoneblock/src/main/java/de/haumacher/phoneblock/db/DB.java index c568872..698f541 100644 --- a/phoneblock/src/main/java/de/haumacher/phoneblock/db/DB.java +++ b/phoneblock/src/main/java/de/haumacher/phoneblock/db/DB.java @@ -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); } @@ -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 getLatestSpamReports(long notBefore) { + public List getLatestSpamReports(long notBefore) { try (SqlSession session = openSession()) { SpamReports reports = session.getMapper(SpamReports.class); return reports.getLatestReports(notBefore); @@ -543,7 +543,7 @@ List getTopSearches(int cnt) { long revisionDate = orMidnightYesterday(reports.getRevisionDate(afterRev)); List 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() @@ -591,7 +591,7 @@ private long orMidnightYesterday(Long revisionDate) { /** * Looks all spam reports. */ - public List getAll(int limit) { + public List getAll(int limit) { try (SqlSession session = openSession()) { SpamReports reports = session.getMapper(SpamReports.class); return reports.getAll(limit); @@ -601,7 +601,7 @@ public List getAll(int limit) { /** * Looks up spam reports with the most votes in the last month. */ - public List getTopSpamReports(int cnt) { + public List getTopSpamReports(int cnt) { Calendar cal = GregorianCalendar.getInstance(); cal.add(Calendar.MONTH, -1); cal.set(Calendar.HOUR_OF_DAY, 0); @@ -617,7 +617,7 @@ public List getTopSpamReports(int cnt) { /** * Looks up the newest entries in the blocklist. */ - public List getLatestBlocklistEntries(String login) { + public List getLatestBlocklistEntries(String login) { try (SqlSession session = openSession()) { SpamReports reports = session.getMapper(SpamReports.class); @@ -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()) diff --git a/phoneblock/src/main/java/de/haumacher/phoneblock/db/DBNumbersEntry.java b/phoneblock/src/main/java/de/haumacher/phoneblock/db/DBNumberInfo.java similarity index 70% rename from phoneblock/src/main/java/de/haumacher/phoneblock/db/DBNumbersEntry.java rename to phoneblock/src/main/java/de/haumacher/phoneblock/db/DBNumberInfo.java index 6692ec1..3751fdc 100644 --- a/phoneblock/src/main/java/de/haumacher/phoneblock/db/DBNumbersEntry.java +++ b/phoneblock/src/main/java/de/haumacher/phoneblock/db/DBNumberInfo.java @@ -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) diff --git a/phoneblock/src/main/java/de/haumacher/phoneblock/db/SpamReports.java b/phoneblock/src/main/java/de/haumacher/phoneblock/db/SpamReports.java index fede014..268366b 100644 --- a/phoneblock/src/main/java/de/haumacher/phoneblock/db/SpamReports.java +++ b/phoneblock/src/main/java/de/haumacher/phoneblock/db/SpamReports.java @@ -106,7 +106,7 @@ SELECT COUNT(1) FROM NUMBERS s where UPDATED >= #{after} and ACTIVE order by UPDATED desc """) - List getLatestReports(long after); + List 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 @@ -114,19 +114,19 @@ SELECT COUNT(1) FROM NUMBERS s order by UPDATED desc limit #{limit} """) - List getAll(int limit); + List 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 getUpdatedPhoneInfos(long updatedAfter); + List getUpdatedPhoneInfos(long updatedAfter); @Select(""" select s.PHONE from NUMBERS s @@ -149,20 +149,20 @@ SELECT COUNT(1) FROM NUMBERS s WHERE ACTIVE and s.UPDATED >= #{notBefore} ORDER BY s.VOTES DESC LIMIT #{cnt} """) - List getTopSpammers(int cnt, long notBefore); + List 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 getLatestBlocklistEntries(int minVotes); + List 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 getBlocklist(int minVotes); + List getBlocklist(int minVotes); @Select(""" SELECT x.PHONE FROM NUMBERS x @@ -188,7 +188,7 @@ WHERE h.PHONE IN ( ORDER BY s.SEARCHES - i.SEARCHES DESC LIMIT 10; """) - List getTopSearches(long revTime); + List getTopSearches(long revTime); /** * Retrieves all historic versions for the given number not older than the given revision. @@ -228,13 +228,13 @@ WHERE h.PHONE IN ( """) - List getNumbers(Collection numbers); + List getNumbers(Collection 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 getReports(); + List getReports(); @Select(""" select PHONE from WHITELIST diff --git a/phoneblock/src/main/webapp/phone-info.jsp b/phoneblock/src/main/webapp/phone-info.jsp index 2fa47a0..c678540 100644 --- a/phoneblock/src/main/webapp/phone-info.jsp +++ b/phoneblock/src/main/webapp/phone-info.jsp @@ -1,4 +1,5 @@ +<%@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"%> @@ -28,11 +29,11 @@ <% 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 relatedNumbers = (List) request.getAttribute("relatedNumbers"); Map ratings = (Map) request.getAttribute("ratings"); - List searches = (List) request.getAttribute("searches"); + List searches = (List) request.getAttribute("searches"); boolean thanks = request.getAttribute("thanks") != null; @@ -398,7 +399,7 @@ boolean first = true; - for (SearchInfo r : searches) { + for (Integer r : searches) { if (first) { first = false; } else { @@ -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()); } %>
diff --git a/phoneblock/src/main/webapp/status.jsp b/phoneblock/src/main/webapp/status.jsp index d4b9cca..4409c1a 100644 --- a/phoneblock/src/main/webapp/status.jsp +++ b/phoneblock/src/main/webapp/status.jsp @@ -1,4 +1,6 @@ +<%@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"%> @@ -134,7 +136,7 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc %> <% - List reports = DBService.getInstance().getLatestSpamReports(System.currentTimeMillis() - 60 * 60 * 1000); + List reports = DBService.getInstance().getLatestSpamReports(System.currentTimeMillis() - 60 * 60 * 1000); if (!reports.isEmpty()) { %>

Spam-Reports der letzten Stunde

@@ -150,7 +152,7 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc <% - for (SpamReport report : reports) { + for (NumberInfo report : reports) { %> @@ -162,11 +164,11 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc - <%= (now - report.getLastUpdate()) / 1000 / 60 %> minutes ago + <%= (now - report.getUpdated()) / 1000 / 60 %> minutes ago - <%= report.getDateAdded() > 0 ? format.format(new Date(report.getDateAdded())) : "-" %> + <%= report.getAdded() > 0 ? format.format(new Date(report.getAdded())) : "-" %> <% @@ -195,7 +197,7 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc <% - for (SpamReport report : reports) { + for (NumberInfo report : reports) { %> @@ -207,11 +209,11 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc - <%= format.format(new Date(report.getLastUpdate()))%> + <%= format.format(new Date(report.getUpdated()))%> - <%= report.getDateAdded() > 0 ? format.format(new Date(report.getDateAdded())) : "-" %> + <%= report.getAdded() > 0 ? format.format(new Date(report.getAdded())) : "-" %> <% @@ -240,7 +242,7 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc <% - for (SpamReport report : reports) { + for (NumberInfo report : reports) { %> @@ -252,11 +254,11 @@ request.setAttribute("title", "Telefonnummern aktueller Werbeanrufer - PhoneBloc - <%= format.format(new Date(report.getLastUpdate()))%> + <%= format.format(new Date(report.getUpdated()))%> - <%= report.getDateAdded() > 0 ? format.format(new Date(report.getDateAdded())) : "-" %> + <%= report.getAdded() > 0 ? format.format(new Date(report.getAdded())) : "-" %> <% diff --git a/phoneblock/src/test/java/de/haumacher/phoneblock/db/TestDB.java b/phoneblock/src/test/java/de/haumacher/phoneblock/db/TestDB.java index a8ea617..249229a 100644 --- a/phoneblock/src/test/java/de/haumacher/phoneblock/db/TestDB.java +++ b/phoneblock/src/test/java/de/haumacher/phoneblock/db/TestDB.java @@ -139,7 +139,7 @@ void testSpamReports() { assertEquals(1006, _db.getLastSpamReport().longValue()); - List reports = _db.getLatestSpamReports(1001); + List reports = _db.getLatestSpamReports(1001); assertEquals(3, reports.size()); assertEquals("456", reports.get(2).getPhone()); assertEquals("999", reports.get(1).getPhone());