stella.log
Class TargetReport

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by util.Mailer
                  extended by stella.log.TargetReport
All Implemented Interfaces:
Cloneable, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class TargetReport
extends Mailer
implements Initializable, ExitCleaning

A target report is an e-mail notification scheme that automatically sends an e-amil at given period to stella users. The SQL-query is like select * from obs,done,target where obs.objid=done.object and obs.objname=target.objname and obs.objid='20090501-0063';


Nested Class Summary
 
Nested classes/interfaces inherited from class util.Mailer
Mailer.Google
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static boolean DEFDEBUG
          The default debuggin mode.
private static String DEFDEPARAMETER
          Default name of the time parameter.
private static boolean DEFEXPLANATION
          Default include field explanation.
private static String DEFFROM
          The default from address.
private static double DEFGENERALCYCLE
          Default report cycle.
private static String DEFGENERALTO
          The default from address.
private static String DEFRAPARAMETER
          Default name of the time parameter.
private static double DEFREPORTCYCLE
          Default report cycle.
private static boolean DEFREPORTFAILURE
          Default report only successes.
private static String DEFREPORTFIELD
          Default reported per user fields.
private static String DEFREPORTGENERAL
          Default reported fields for the general report.
private static String DEFTELESCOPE
          Default telescope name.
private static String DEFTIMEPARAMETER
          Default name of the time parameter.
private static Map<String,String> EXPLAIN
          All possible fields with explanations.
private  javax.mail.Address from
          The from-address.
private  Date general
          The date of the last general report.
static String KEY_BCC
          Address list of the recipients, bcc-type.
static String KEY_CC
          Address list of the recipients, cc-type.
static String KEY_DEBUG
          If true, mail-delivery is blocked for debugging mode.
static String KEY_DEPARAMETER
          The parameter that holds the object's right ascension.
static String KEY_EXPLANATION
          If true, the field explanation is added.
static String KEY_FROM
          Address of the sender, with or without domain.
static String KEY_GENERALCYCLE
          The report cycle of the general report in days, zero = no report.
static String KEY_GENERALTO
          Address list of the recipients of the general report.
static String KEY_PARAMETERS
          The properties of the parameter cluster we use.
static String KEY_RAPARAMETER
          The parameter that holds the object's right ascension.
static String KEY_REPORTCYCLE
          The report cycle in days, zero = no report.
static String KEY_REPORTFAILURE
          If true, only successful observations are reported.
static String KEY_REPORTFIELD
          The fields to be included in the report, plus order.
static String KEY_REPORTGENERAL
          The fields to be included in the general report, plus order.
static String KEY_TELESCOPE
          The issuing telescope.
static String KEY_TIMEPARAMETER
          The parameter that holds the settable time.
static String KEY_USERCONF
          The list of per-user configurations different from default.
private static DateFormat MDF
          The medium date format.
private  Map<String,Date> report
          Link of user names to their last report dates.
private static DateFormat SDF
          The short date format.
static String SEPARATOR
          Separator in report blocks.
static String SERIALIZE
          The file where the last report times are serialized.
private  ParameterClustering set
          The parameter set we use.
static String TABSEP
          Separator of table columns.
private  Map<String,Map<String,String>> users
          Override default parameters per user.
 
Fields inherited from class util.Mailer
KEY_PASSWORD, KEY_SMTPHOST, KEY_SMTPPORT, KEY_USERNAME, KEY_USESSL, STELLAMAINTENANCE, STELLAROBOTIC
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
TargetReport(Map<String,String> prop)
          Constructs a new target report.
 
Method Summary
 void exit()
          On exit, we save the time table.
private  String explanation(Map<String,String> nondef)
          Get an explanation of the fields in the report.
private  Map<String,Date> fileLoad(File resource)
          Loads a hash map from a file.
 javax.mail.Address getFrom()
          Returns the from address.
private  List<List<String>> getGeneralReport(String user, Date from, Date to)
          Gets a formatted report for a user, spanning the time of last report until now.
 long getRefreshInterval()
          The refresh intervall is one day, but not necessarily a mail is sent each day.
private  List<String> getReportHead(Map<String,String> nondef)
          Gets the head of the report table, basically the queried fields.
private  List<String> getReportHead(String fields)
          Gets the head of the report table, basically the queried fields.
private  List<String> getReportLine(String uniq, String fields)
          This prepares one line of the report, for the specified unique object id.
private  String getUserReport(String user, Date from, Date to)
          Gets a formatted report for a user, spanning the time of last report until now.
 void init()
          Initializes the report.
 boolean isFixedRate()
          We want the report to be filed each morning at the same time.
private  boolean mailReports()
          Sends all reports.
static void main(String[] arg)
          This runs as a cron job.
 void refresh()
          On refresh, we check for each user, if a report should be sent.
private  void setFrom(javax.mail.Address mailfrom)
          Sets the from address.
private  String tableFormat(List<List<String>> format)
          Formats a table into a single string.
 
Methods inherited from class util.Mailer
close, createStellaRoboticMailer, getAddresses, getStellaMaintenance, getStellaRobotic, prepareMail, sendMail, sendMail, threadMail
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 

Field Detail

SEPARATOR

public static final String SEPARATOR
Separator in report blocks.

See Also:
Constant Field Values

TABSEP

public static final String TABSEP
Separator of table columns.

See Also:
Constant Field Values

SERIALIZE

public static final String SERIALIZE
The file where the last report times are serialized.

See Also:
Constant Field Values

KEY_USERCONF

public static final String KEY_USERCONF
The list of per-user configurations different from default.

See Also:
Constant Field Values

KEY_PARAMETERS

public static final String KEY_PARAMETERS
The properties of the parameter cluster we use.

See Also:
Constant Field Values

KEY_TIMEPARAMETER

public static final String KEY_TIMEPARAMETER
The parameter that holds the settable time.

See Also:
Constant Field Values

KEY_RAPARAMETER

public static final String KEY_RAPARAMETER
The parameter that holds the object's right ascension.

See Also:
Constant Field Values

KEY_DEPARAMETER

public static final String KEY_DEPARAMETER
The parameter that holds the object's right ascension.

See Also:
Constant Field Values

KEY_REPORTCYCLE

public static final String KEY_REPORTCYCLE
The report cycle in days, zero = no report.

See Also:
Constant Field Values

KEY_GENERALCYCLE

public static final String KEY_GENERALCYCLE
The report cycle of the general report in days, zero = no report.

See Also:
Constant Field Values

KEY_REPORTFIELD

public static final String KEY_REPORTFIELD
The fields to be included in the report, plus order.

See Also:
Constant Field Values

KEY_REPORTGENERAL

public static final String KEY_REPORTGENERAL
The fields to be included in the general report, plus order.

See Also:
Constant Field Values

KEY_REPORTFAILURE

public static final String KEY_REPORTFAILURE
If true, only successful observations are reported.

See Also:
Constant Field Values

KEY_EXPLANATION

public static final String KEY_EXPLANATION
If true, the field explanation is added.

See Also:
Constant Field Values

KEY_TELESCOPE

public static final String KEY_TELESCOPE
The issuing telescope.

See Also:
Constant Field Values

KEY_FROM

public static final String KEY_FROM
Address of the sender, with or without domain. Follow RFC822 syntax.

See Also:
Constant Field Values

KEY_GENERALTO

public static final String KEY_GENERALTO
Address list of the recipients of the general report.

See Also:
Constant Field Values

KEY_CC

public static final String KEY_CC
Address list of the recipients, cc-type. With or without domain.

See Also:
Constant Field Values

KEY_BCC

public static final String KEY_BCC
Address list of the recipients, bcc-type. With or without domain.

See Also:
Constant Field Values

KEY_DEBUG

public static final String KEY_DEBUG
If true, mail-delivery is blocked for debugging mode.

See Also:
Constant Field Values

DEFTELESCOPE

private static final String DEFTELESCOPE
Default telescope name.

See Also:
Constant Field Values

DEFTIMEPARAMETER

private static final String DEFTIMEPARAMETER
Default name of the time parameter.

See Also:
Constant Field Values

DEFRAPARAMETER

private static final String DEFRAPARAMETER
Default name of the time parameter.

See Also:
Constant Field Values

DEFDEPARAMETER

private static final String DEFDEPARAMETER
Default name of the time parameter.

See Also:
Constant Field Values

DEFDEBUG

private static final boolean DEFDEBUG
The default debuggin mode.

See Also:
Constant Field Values

DEFFROM

private static final String DEFFROM
The default from address. Used without domain.

See Also:
Constant Field Values

DEFGENERALTO

private static final String DEFGENERALTO
The default from address. Used without domain.

See Also:
Constant Field Values

DEFREPORTCYCLE

private static final double DEFREPORTCYCLE
Default report cycle.

See Also:
Constant Field Values

DEFGENERALCYCLE

private static final double DEFGENERALCYCLE
Default report cycle.

See Also:
Constant Field Values

DEFREPORTFIELD

private static final String DEFREPORTFIELD
Default reported per user fields.

See Also:
Constant Field Values

DEFREPORTGENERAL

private static final String DEFREPORTGENERAL
Default reported fields for the general report.

See Also:
Constant Field Values

DEFREPORTFAILURE

private static final boolean DEFREPORTFAILURE
Default report only successes.

See Also:
Constant Field Values

DEFEXPLANATION

private static final boolean DEFEXPLANATION
Default include field explanation.

See Also:
Constant Field Values

EXPLAIN

private static final Map<String,String> EXPLAIN
All possible fields with explanations.


SDF

private static final DateFormat SDF
The short date format.


MDF

private static final DateFormat MDF
The medium date format.


set

private ParameterClustering set
The parameter set we use.


users

private Map<String,Map<String,String>> users
Override default parameters per user.


general

private Date general
The date of the last general report.


report

private Map<String,Date> report
Link of user names to their last report dates.


from

private javax.mail.Address from
The from-address.

Constructor Detail

TargetReport

public TargetReport(Map<String,String> prop)
Constructs a new target report. First report sent immediately, then around noon.

Method Detail

init

public void init()
Initializes the report.

Specified by:
init in interface Initializable
Overrides:
init in class Mailer

exit

public void exit()
On exit, we save the time table.

Specified by:
exit in interface ExitCleaning

fileLoad

private Map<String,Date> fileLoad(File resource)
Loads a hash map from a file.


setFrom

private void setFrom(javax.mail.Address mailfrom)
Sets the from address.


getFrom

public javax.mail.Address getFrom()
Returns the from address.


isFixedRate

public boolean isFixedRate()
We want the report to be filed each morning at the same time.


getRefreshInterval

public long getRefreshInterval()
The refresh intervall is one day, but not necessarily a mail is sent each day. This depends on the rate set by the user.


refresh

public void refresh()
On refresh, we check for each user, if a report should be sent. This is determined first by looking in the report table. If no entry for the user exists, or if the entry is outdated, a report is generated and the new date stored in report. If the report is not empty, it is readilly sent to the user. If no last report date for a user exists, we go back the specified number of days.


mailReports

private boolean mailReports()
Sends all reports.


getGeneralReport

private List<List<String>> getGeneralReport(String user,
                                            Date from,
                                            Date to)
Gets a formatted report for a user, spanning the time of last report until now. Each entry produces a line. Query like select obs.objid,success from obs,task,proposal,done where dateobs<'2009-05-14 12:32:00' and dateobs > '2009-05-13 12:32:00' and pi='Strassmeier' and obs.object=task.object and task.propid=proposal.propid and done.object=obs.objid; to retrieve the list of unique id's, which are then used in getReportLine(java.lang.String, java.lang.String)


getUserReport

private String getUserReport(String user,
                             Date from,
                             Date to)
Gets a formatted report for a user, spanning the time of last report until now. Each entry produces a line. Query like select obs.objid,success from obs,task,proposal,done where dateobs<'2009-05-14 12:32:00' and dateobs > '2009-05-13 12:32:00' and pi='Strassmeier' and obs.object=task.object and task.propid=proposal.propid and done.object=obs.objid; to retrieve the list of unique id's, which are then used in getReportLine(java.lang.String, java.lang.String)


tableFormat

private String tableFormat(List<List<String>> format)
Formats a table into a single string. The table is given as a rectangular grid of strings, collected in a list of list of strings.


explanation

private String explanation(Map<String,String> nondef)
Get an explanation of the fields in the report.


getReportHead

private List<String> getReportHead(Map<String,String> nondef)
Gets the head of the report table, basically the queried fields.


getReportHead

private List<String> getReportHead(String fields)
Gets the head of the report table, basically the queried fields.


getReportLine

private List<String> getReportLine(String uniq,
                                   String fields)
This prepares one line of the report, for the specified unique object id. Issuses like select * from obs,done,target where obs.objid=done.object and obs.objname=target.objname and obs.objid='20090501-0063';


main

public static void main(String[] arg)
This runs as a cron job.