pulse - the web application framework Get pulse at SourceForge.net. Fast, secure and Free Open Source software downloads Ohloh project report for pulse-java

org.torweg.pulse.component.statistics.view
Class AbstractStatisticsViewController<T extends AbstractStatisticsViewControllerConfiguration,U extends AbstractStatisticsViewControllerResultData,V extends AbstractStatisticsViewControllerResult<U>>

java.lang.Object
  extended by org.torweg.pulse.bundle.Controller
      extended by org.torweg.pulse.component.statistics.view.AbstractStatisticsController<T,V>
          extended by org.torweg.pulse.component.statistics.view.AbstractStatisticsViewController<T,U,V>
Type Parameters:
T - the actual implementation of: AbstractStatisticsViewControllerConfiguration
U - the actual implementation of: AbstractStatisticsViewControllerResultData
V - the actual implementation of: AbstractStatisticsViewControllerResult as used for the initialisation of the view
All Implemented Interfaces:
Configurable<AbstractStatisticsViewControllerConfiguration>
Direct Known Subclasses:
GroupAnalysisViewController, OverViewController, RefererAnalysisViewController, TechnicalInformationViewController, TimeAnalysisViewController

public abstract class AbstractStatisticsViewController<T extends AbstractStatisticsViewControllerConfiguration,U extends AbstractStatisticsViewControllerResultData,V extends AbstractStatisticsViewControllerResult<U>>
extends AbstractStatisticsController<T,V>

Abstract base-class to derive a "view" for statistical data from.

Version:
$Revision: 1832 $
Author:
Daniel Dietz

Nested Class Summary
 
Nested classes/interfaces inherited from class org.torweg.pulse.bundle.Controller
Controller.AlwaysRun
 
Field Summary
protected static int DEFAULT_CHART_HEIGHT
          The default chart height - 400 - being used if none is specified.
protected static int DEFAULT_CHART_WIDTH
          The default chart width - 600 - being used if none is specified.
protected static long NO_SERVERID
          The default server id - 0L - being used if none is specified.
 
Fields inherited from class org.torweg.pulse.component.statistics.view.AbstractStatisticsController
LOGGER
 
Constructor Summary
AbstractStatisticsViewController()
           
 
Method Summary
protected abstract  U buildViewResultData(Duration duration, Period dataResolution, StatisticsServer server, org.hibernate.Session s)
          Builds the result data for the given StatisticsServer and the given Duration using the given Period as "data resolution".
protected  int chartHeightFromCommand(Command command)
          Retrieves the "height" as integer from the given Command.
protected  int chartWidthFromCommand(Command command)
          Retrieves the "width" as integer from the given Command.
protected  java.lang.Class<? extends org.jfree.data.time.RegularTimePeriod> determineJFreeChartTimePeriod(Period dataResolution)
          Returns the corresponding RegularTimePeriod for the given Period.
protected  Duration durationFromCommand(Command command)
          Builds a Duration from the given Command if the given command.getParameter("duration") !
protected  U fetchResultDataFromSession(ServiceSession session, long statisticsServerId)
          Retrieves the AbstractStatisticsViewControllerResultData from the current ServiceSession for the given id of a StatisticsServer.
protected  java.lang.String fileNameForReport(StatisticsServer server, java.lang.String suffix)
          Creates a string to name the actual report with.
protected  V initView(ServiceRequest request, boolean keepDataInSession)
          Builds the &lt;V&lt;U&gt;&gt; initialising the view.
protected  java.lang.Integer integerFromCommand(Command command, java.lang.String parameterName)
          Retrieves an integer by parameterName from the given Command.
protected  java.util.List<? extends AbstractAggregation> loadAggregations(java.lang.Class<? extends AbstractAggregation> clazz, StatisticsServer statisticsServer, Duration duration, org.hibernate.Session s)
          Loads the AbstractAggregations of the given type clazz for the given StatisticsServer and the given Duration.
protected  StatisticsServer loadStatisticsServer(long serverId, org.hibernate.Session s)
          Loads and returns a StatisticsServer by given request- Parameter "serverId".
protected abstract  V newResult(T configuration, U data)
          Factory method to retrieve an actual new result.
protected  V outputReportPDF(V result, java.util.Map<java.lang.String,java.io.File> fileMap, ServiceRequest request)
          Performs the creation of the PDF-file and adds the required PDFOutputEvent to the EventManager.
protected  void putResultDataInSession(U resultData, ServiceSession session)
          Adds the given AbstractStatisticsViewControllerResultData to the current request-session and stores it under the following key: "fqn.of.the.current.
protected  void removeResultDataFromSession(ServiceSession session, long statisticsServerId)
          Retrieves the AbstractStatisticsViewControllerResultData from the current ServiceSession for the given id of a StatisticsServer.
protected  Period resolutionFromCommand(Command command)
          Builds a Duration from the given Command if the given command.getParameter("resolution") !
protected  long serverIdFromCommand(Command command)
          Retrieves the "serverId" as long from the given Command.
protected  V userIsNotAllowedEvent(ServiceRequest request)
          Adds a ForbiddenEvent to the EventManager of the current ServiceRequest with the following message "You do not have the required roles to view the data for the requested server.".
 
Methods inherited from class org.torweg.pulse.component.statistics.view.AbstractStatisticsController
getConfiguration, hasRoleForServer, initialize, initView
 
Methods inherited from class org.torweg.pulse.bundle.Controller
getAlwaysRun, isAlwaysRun, setAlwaysRun
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CHART_WIDTH

protected static final int DEFAULT_CHART_WIDTH
The default chart width - 600 - being used if none is specified.

See Also:
Constant Field Values

DEFAULT_CHART_HEIGHT

protected static final int DEFAULT_CHART_HEIGHT
The default chart height - 400 - being used if none is specified.

See Also:
Constant Field Values

NO_SERVERID

protected static final long NO_SERVERID
The default server id - 0L - being used if none is specified.

See Also:
Constant Field Values
Constructor Detail

AbstractStatisticsViewController

public AbstractStatisticsViewController()
Method Detail

buildViewResultData

protected abstract U buildViewResultData(Duration duration, Period dataResolution, StatisticsServer server,
                                         org.hibernate.Session s)
Builds the result data for the given StatisticsServer and the given Duration using the given Period as "data resolution".

Parameters:
duration - Duration
dataResolution - Period to be used as "data resolution"
server - StatisticsServer
s - Session
Returns:
&lt;U&gt;

newResult

protected abstract V newResult(T configuration, U data)
Factory method to retrieve an actual new result.

Parameters:
configuration - &lt;T&gt;
data - &lt;U&gt;
Returns:
&lt;V&gt;

initView

protected final V initView(ServiceRequest request,
                           boolean keepDataInSession)
Builds the &lt;V&lt;U&gt;&gt; initialising the view.

Parameters:
request - ServiceRequest
keepDataInSession - true to keep the data in the session, false otherwise
Returns:
&lt;V&gt;

userIsNotAllowedEvent

protected final V userIsNotAllowedEvent(ServiceRequest request)
Adds a ForbiddenEvent to the EventManager of the current ServiceRequest with the following message "You do not have the required roles to view the data for the requested server.".

Parameters:
request - the current ServiceRequest
Returns:
null

loadAggregations

protected final java.util.List<? extends AbstractAggregation> loadAggregations(java.lang.Class<? extends AbstractAggregation> clazz, StatisticsServer statisticsServer, Duration duration,
                                                                               org.hibernate.Session s)
Loads the AbstractAggregations of the given type clazz for the given StatisticsServer and the given Duration.

Parameters:
clazz - the Class&lt;? extends AbstractAggregation&gt; to be loaded
statisticsServer - the StatisticsServer
duration - the Duration
s - the HibernateTM-Session to be used for loading
Returns:
a List&lt;? extends AbstractAggregation&gt;

loadStatisticsServer

protected final StatisticsServer loadStatisticsServer(long serverId,
                                                      org.hibernate.Session s)
Loads and returns a StatisticsServer by given request- Parameter "serverId".

Parameters:
serverId - the request-Parameter
s - a HibernateTM-Session to be used for loading
Returns:
StatisticsServer if one could be loaded, null otherwise

durationFromCommand

protected final Duration durationFromCommand(Command command)
Builds a Duration from the given Command if the given command.getParameter("duration") != null.

If no duration can be build from request, the default Duration as in set in &lt;T&gt; based on the current time-stamp will be returned.

Parameters:
command - the Command to build the Duration from
Returns:
the Duration
Throws:
PulseException - if a request-parameter for the "duration" is given, but cannot be converted to a valid Duration

resolutionFromCommand

protected final Period resolutionFromCommand(Command command)
Builds a Duration from the given Command if the given command.getParameter("resolution") != null.

If no Period can be build from request, the default Period as in set in &lt;T&gt; will be returned.

NOTE: &lt;T&gt; does not necessarily have to have a default "data resolution" Period to be set.

Parameters:
command - the Command to build the Period from
Returns:
the Period, or null if none could be retrieved or build from given command
Throws:
PulseException - if a request-parameter for the "resolution" is given, but cannot be converted to a valid Period

chartHeightFromCommand

protected final int chartHeightFromCommand(Command command)
Retrieves the "height" as integer from the given Command.

Parameters:
command - the Command
Returns:
the positive integer "height", if a "height" could be retrieved and built from the given command, the default AbstractStatisticsViewController.DEFAULT_CHART_HEIGHT otherwise and on internal NumberFormatException

chartWidthFromCommand

protected final int chartWidthFromCommand(Command command)
Retrieves the "width" as integer from the given Command.

Parameters:
command - the Command
Returns:
the positive integer "width", if a "width" could be retrieved and built from the given command, the default AbstractStatisticsViewController.DEFAULT_CHART_WIDTH otherwise and on internal NumberFormatException

serverIdFromCommand

protected final long serverIdFromCommand(Command command)
Retrieves the "serverId" as long from the given Command.

Parameters:
command - the Command
Returns:
the positive long "serverId", if a "serverId" could be retrieved and built from the given command, the default AbstractStatisticsViewController.NO_SERVERID otherwise and on internal NumberFormatException

integerFromCommand

protected final java.lang.Integer integerFromCommand(Command command,
                                                     java.lang.String parameterName)
Retrieves an integer by parameterName from the given Command.

Parameters:
command - the Command
parameterName - the name of the Parameter to look for
Returns:
the "height" as a positive integer if a "height" could be retrieved and built from the given command, the default AbstractStatisticsViewController.DEFAULT_CHART_HEIGHT otherwise and on internal NumberFormatException

putResultDataInSession

protected final void putResultDataInSession(U resultData, ServiceSession session)
Adds the given AbstractStatisticsViewControllerResultData to the current request-session and stores it under the following key:

"fqn.of.the.current.AbstractStatisticsViewController#resultData.StatisticsServer.id"

.

Parameters:
resultData - the AbstractStatisticsViewControllerResultData
session - the current ServiceSession

fetchResultDataFromSession

protected final U fetchResultDataFromSession(ServiceSession session,
                                             long statisticsServerId)
Retrieves the AbstractStatisticsViewControllerResultData from the current ServiceSession for the given id of a StatisticsServer.

Parameters:
session - the current ServiceSession
statisticsServerId - the id of the StatisticsServer
Returns:
the AbstractStatisticsViewControllerResultData, or null if no AbstractStatisticsViewControllerResultData

removeResultDataFromSession

protected final void removeResultDataFromSession(ServiceSession session,
                                                 long statisticsServerId)
Retrieves the AbstractStatisticsViewControllerResultData from the current ServiceSession for the given id of a StatisticsServer.

Parameters:
session - the current ServiceSession
statisticsServerId - the id of the StatisticsServer

determineJFreeChartTimePeriod

protected final java.lang.Class<? extends org.jfree.data.time.RegularTimePeriod> determineJFreeChartTimePeriod(Period dataResolution)
Returns the corresponding RegularTimePeriod for the given Period.

Parameters:
dataResolution - the Period
Returns:
a RegularTimePeriod, null if no RegularTimePeriod could be mapped to the given Period

outputReportPDF

protected final V outputReportPDF(V result,
                                  java.util.Map<java.lang.String,java.io.File> fileMap, ServiceRequest request)
Performs the creation of the PDF-file and adds the required PDFOutputEvent to the EventManager.

Parameters:
result - the actual implementation of: AbstractStatisticsViewControllerResult
fileMap - a map of files for the creation of the report PDF
request - the current ServiceRequest
Returns:
the (modified) AbstractStatisticsViewControllerResult as used for the creation of the PDF

fileNameForReport

protected final java.lang.String fileNameForReport(StatisticsServer server,
                                                   java.lang.String suffix)
Creates a string to name the actual report with.

Parameters:
server - the StatisticsServer
suffix - the file name suffix
Returns:
a string to be used for naming the report file