@ -15,10 +15,7 @@ import java.nio.file.Files;
import java.sql.ResultSet ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
import java.sql.SQLException ;
import java.sql.Timestamp ;
import java.sql.Timestamp ;
import java.util.ArrayList ;
import java.util.* ;
import java.util.HashMap ;
import java.util.Map ;
import java.util.TreeMap ;
import static de.srsoftware.widerhall.Constants.* ;
import static de.srsoftware.widerhall.Constants.* ;
import static de.srsoftware.widerhall.Constants.VARCHAR ;
import static de.srsoftware.widerhall.Constants.VARCHAR ;
@ -26,12 +23,13 @@ import static de.srsoftware.widerhall.Constants.VARCHAR;
public class Post {
public class Post {
public static final Logger LOG = LoggerFactory . getLogger ( Post . class ) ;
public static final Logger LOG = LoggerFactory . getLogger ( Post . class ) ;
public static final String TABLE_NAME = "Posts" ;
public static final String TABLE_NAME = "Posts" ;
private static final String DATE = "date" ;
private static final String FILE = "file" ;
private static final String FROM_ADDR = "from_addr" ;
private static final String FROM_ADDR = "from_addr" ;
private static final String FROM_NAME = "from_name" ;
private static final String FROM_NAME = "from_name" ;
private static final String PARENT = "parent" ;
private static final String LONG = "LONG" ;
private static final String LONG = "LONG" ;
private static final String DATE = "date" ;
private static final String PARENT = "parent" ;
private static final String FILE = "file" ;
private static HashMap < String , Post > cache = new HashMap < > ( ) ;
private static HashMap < String , Post > cache = new HashMap < > ( ) ;
private String id , fromAddr , fromName , subject , filename ;
private String id , fromAddr , fromName , subject , filename ;
@ -98,12 +96,13 @@ public class Post {
return new File ( filename ) ;
return new File ( filename ) ;
}
}
public static ArrayList < Post > find ( MailingList list , String month ) throws SQLException {
public static ArrayList < Post > find ( MailingList list , String month , List < String > allowedSenders ) throws SQLException {
var rs = Database . open ( )
var query = Database . open ( )
. select ( TABLE_NAME , "*" , "strftime('%Y-%m',date/1000,'unixepoch') as month" )
. select ( TABLE_NAME , "*" , "strftime('%Y-%m',date/1000,'unixepoch') as month" )
. where ( LIST , list . email ( ) )
. where ( LIST , list . email ( ) )
. where ( MONTH , month )
. where ( MONTH , month ) ;
. sort ( DATE )
if ( allowedSenders ! = null ) query = query . where ( FROM_ADDR , allowedSenders ) ;
var rs = query . sort ( DATE )
. compile ( )
. compile ( )
. exec ( ) ;
. exec ( ) ;
try {
try {
@ -174,10 +173,13 @@ public class Post {
return this ;
return this ;
}
}
public static Map < String , Object > summarize ( MailingList list ) throws SQLException {
public static Map < String , Object > summarize ( MailingList list , List < String > limitedUsers ) throws SQLException {
var sql = new StringBuilder ( "SELECT count(*) as count,strftime('%Y-%m',date/1000,'unixepoch') as month FROM Posts WHERE list = ? GROUP BY month ORDER BY month;" ) ;
var sql = new StringBuilder ( "SELECT count(*) as count,strftime('%Y-%m',date/1000,'unixepoch') as month FROM Posts" ) ;
var query = Database . open ( ) . query ( sql ) . where ( LIST , list . email ( ) ) . groupBy ( MONTH ) . sort ( MONTH ) ;
if ( limitedUsers ! = null ) query . where ( FROM_ADDR , limitedUsers ) ;
var rs = query . compile ( ) . exec ( ) ;
var map = new TreeMap < String , Object > ( ) ;
var map = new TreeMap < String , Object > ( ) ;
var rs = Database . open ( ) . query ( sql ) . compile ( list . email ( ) ) . exec ( ) ;
while ( rs . next ( ) ) map . put ( rs . getString ( "month" ) , rs . getInt ( "count" ) ) ;
while ( rs . next ( ) ) map . put ( rs . getString ( "month" ) , rs . getInt ( "count" ) ) ;
rs . close ( ) ;
rs . close ( ) ;
return map ;
return map ;