Changeset 485


Ignore:
Timestamp:
01/23/11 23:27:01 (2 years ago)
Author:
philsmart
Message:
 
Location:
raptor-web/trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • raptor-web/trunk/pom.xml

    r476 r485  
    512512            </exclusions> 
    513513        </dependency> 
     514         
     515        <!-- Quartz  --> 
     516         
     517        <dependency> 
     518                        <groupId>org.quartz-scheduler</groupId> 
     519                        <artifactId>quartz</artifactId> 
     520                        <version>1.8.0</version> 
     521                        <exclusions> 
     522                                <exclusion> 
     523                                        <artifactId>slf4j-api</artifactId> 
     524                                        <groupId>org.slf4j</groupId> 
     525                                </exclusion> 
     526                        </exclusions> 
     527                </dependency> 
    514528 
    515529                <!-- spring security --> 
  • raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/model/StartModel.java

    r484 r485  
    88import java.text.DecimalFormatSymbols; 
    99 
     10import org.joda.time.DateTime; 
    1011import org.slf4j.Logger; 
    1112import org.slf4j.LoggerFactory; 
     
    2223 
    2324        static Logger log = LoggerFactory.getLogger(StartModel.class); 
    24  
    25         private double numberOfAuthenticationsPer; 
    26         private double numberOfUniqueAuthenticationsPer; 
    27         private RaptorTableChartModel topFiveResouces; 
    28         private RaptorTableChartModel bottomFiveResouces; 
    29         private RaptorGraphModel headlineGraph; 
     25         
    3026        private Capabilities attachedMUACapabilities; 
     27         
     28        private StartStatistics startStatistics; 
     29         
    3130        private TimeRange statsRangeSelector; 
    3231 
    33         /* only updated on the UI, hence sensible default*/ 
    3432        public enum TimeRange{TODAY,LASTWEEK,LASTMONTH,LASTYEAR} 
    3533 
     
    3836        } 
    3937 
    40         public void setNumberOfAuthenticationsPer(double numberOfAuthenticationsPer) { 
    41             this.numberOfAuthenticationsPer = numberOfAuthenticationsPer; 
    42         } 
    43  
    44         public double getNumberOfAuthenticationsPer() { 
    45             return numberOfAuthenticationsPer; 
    46         } 
    47  
    48         public String getNumberOfAuthenticationsPerFormatted(){ 
    49             return formatDoubleWithCommas(numberOfAuthenticationsPer); 
    50         } 
    51  
    52         private String formatDoubleWithCommas(double number){ 
    53             DecimalFormat df = new DecimalFormat(); 
    54             DecimalFormatSymbols dfs = new DecimalFormatSymbols(); 
    55             dfs.setGroupingSeparator(','); 
    56             df.setDecimalFormatSymbols(dfs); 
    57             String formattedNumber = df.format((int)number); 
    58             return formattedNumber; 
    59         } 
    60  
    61         public void setNumberOfUniqueAuthenticationsPer(double numberOfUniqueAuthenticationsPer) { 
    62             this.numberOfUniqueAuthenticationsPer = numberOfUniqueAuthenticationsPer; 
    63         } 
    64  
    65         public double getNumberOfUniqueAuthenticationsPer() { 
    66             return numberOfUniqueAuthenticationsPer; 
    67         } 
    68  
    69         public String getNumberOfUniqueAuthenticationsPerFormatted() { 
    70             return formatDoubleWithCommas(numberOfUniqueAuthenticationsPer); 
    71         } 
    72  
    73         public void setTopFiveResouces(RaptorTableChartModel topFiveResouces) { 
    74             this.topFiveResouces = topFiveResouces; 
    75         } 
    76  
    77         public RaptorTableChartModel getTopFiveResouces() { 
    78             return topFiveResouces; 
    79         } 
    80  
    81         public void setBottomFiveResouces(RaptorTableChartModel bottomFiveResouces) { 
    82             this.bottomFiveResouces = bottomFiveResouces; 
    83         } 
    84  
    85         public RaptorTableChartModel getBottomFiveResouces() { 
    86             return bottomFiveResouces; 
    87         } 
    88  
    89         public void setHeadlineGraph(RaptorGraphModel headlineGraph) { 
    90             this.headlineGraph = headlineGraph; 
    91         } 
    92  
    93         public RaptorGraphModel getHeadlineGraph() { 
    94             log.debug("getting headline graph"); 
    95             return headlineGraph; 
    96         } 
    9738 
    9839        public void setAttachedMUACapabilities(Capabilities attachedMUACapabilities) { 
     
    11354        } 
    11455 
     56        public void setStartStatistics(StartStatistics startStatistics) { 
     57            this.startStatistics = startStatistics; 
     58        } 
     59 
     60        public StartStatistics getStartStatistics() { 
     61            return startStatistics; 
     62        } 
     63 
    11564 
    11665 
  • raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/service/impl/StartServiceImpl.java

    r484 r485  
    1717import uk.ac.cardiff.raptorweb.engine.ChartProcessor; 
    1818import uk.ac.cardiff.raptorweb.engine.RaptorWebEngine; 
     19import uk.ac.cardiff.raptorweb.model.CachedStartStatistics; 
    1920import uk.ac.cardiff.raptorweb.model.RaptorGraphModel; 
    2021import uk.ac.cardiff.raptorweb.model.RaptorTableChartModel; 
    2122import uk.ac.cardiff.raptorweb.model.StartModel; 
     23import uk.ac.cardiff.raptorweb.model.StartStatistics; 
    2224import uk.ac.cardiff.raptorweb.model.WebSession; 
    2325import uk.ac.cardiff.raptorweb.model.StartModel.TimeRange; 
     
    3335 
    3436    private RaptorWebEngine webEngine; 
    35  
    36     /** 
    37      * Adds the following statistical information from the attached MUA: 1. Number of authentications per <RANGE> 
    38      */ 
     37     
     38    /* holds the statistics for the front page gathered from the background worker thread */ 
     39    private CachedStartStatistics cachedStartModelToday; 
     40    private CachedStartStatistics cachedStartModelLastWeek; 
     41    private CachedStartStatistics cachedStartModelLastMonth; 
     42    private CachedStartStatistics cachedStartModelLastYear; 
     43     
     44    public void generateStatisticsBackground(){ 
     45        log.info("Generating background statistics for the start page, using {}",this); 
     46        CurrentTimeRange currentTimeRange = getTimeRanges(); 
     47        if (cachedStartModelToday==null)     
     48            cachedStartModelToday= new CachedStartStatistics(); 
     49        if (cachedStartModelLastWeek==null) 
     50            cachedStartModelLastWeek= new CachedStartStatistics(); 
     51        if (cachedStartModelLastMonth==null) 
     52            cachedStartModelLastMonth= new CachedStartStatistics(); 
     53        if (cachedStartModelLastYear==null) 
     54            cachedStartModelLastYear= new CachedStartStatistics(); 
     55         
     56        log.debug("Background start page worker getting today"); 
     57        generateStatistics(cachedStartModelToday.getCached(),currentTimeRange.currentTime,currentTimeRange.startToday); 
     58        log.debug("Background start page worker getting last week"); 
     59        generateStatistics(cachedStartModelLastWeek.getCached(),currentTimeRange.currentTime,currentTimeRange.startWeek); 
     60        log.debug("Background start page worker getting last month"); 
     61        generateStatistics(cachedStartModelLastMonth.getCached(),currentTimeRange.currentTime,currentTimeRange.startMonth); 
     62        log.debug("Background start page worker getting last year"); 
     63        generateStatistics(cachedStartModelLastYear.getCached(),currentTimeRange.currentTime,currentTimeRange.startYear); 
     64         
     65        log.info("Generating background statistics for the start page...done"); 
     66    } 
     67     
    3968    @Override 
    40     public void generateStatistics(WebSession websession) { 
    41         StartModel startmodel = websession.getStartmodel(); 
     69    public void generateStatistics(WebSession websession){ 
     70        log.debug("Getting start statistics for {} from {}",websession.getStartmodel().getStatsRangeSelector(),this); 
     71         
     72        if (websession.getStartmodel().getStatsRangeSelector()==StartModel.TimeRange.LASTMONTH) 
     73            websession.getStartmodel().setStartStatistics(cachedStartModelLastMonth.getCached()); 
     74        if (websession.getStartmodel().getStatsRangeSelector()==StartModel.TimeRange.LASTWEEK) 
     75            websession.getStartmodel().setStartStatistics(cachedStartModelLastWeek.getCached()); 
     76        if (websession.getStartmodel().getStatsRangeSelector()==StartModel.TimeRange.TODAY) 
     77            websession.getStartmodel().setStartStatistics(cachedStartModelToday.getCached()); 
     78        if (websession.getStartmodel().getStatsRangeSelector()==StartModel.TimeRange.LASTYEAR) 
     79            websession.getStartmodel().setStartStatistics(cachedStartModelLastYear.getCached()); 
     80         
     81        //so we could output the name of the attached MUA 
     82        Capabilities capabilities = getAttachedCapabilities(); 
     83        if (capabilities!=null){ 
     84            websession.getStartmodel().setAttachedMUACapabilities(capabilities); 
     85 
     86        } 
     87    } 
     88     
     89    private CurrentTimeRange getTimeRanges(){ 
    4290        long currentTimeInMS = System.currentTimeMillis(); 
    4391        //decide dates to use 
     
    54102        //log.debug("One Year Previous {}",oneYearPrevious); 
    55103        DateTime oneWeekPrevious = currentDateTime.minusWeeks(1); 
    56         DateTime chosenStartTime = null; 
    57         if (startmodel.getStatsRangeSelector()==StartModel.TimeRange.LASTMONTH) 
    58             chosenStartTime = oneMonthPrevious; 
    59         if (startmodel.getStatsRangeSelector()==StartModel.TimeRange.LASTWEEK) 
    60             chosenStartTime = oneWeekPrevious; 
    61         if (startmodel.getStatsRangeSelector()==StartModel.TimeRange.TODAY) 
    62             chosenStartTime = today; 
    63         if (startmodel.getStatsRangeSelector()==StartModel.TimeRange.LASTYEAR) 
    64             chosenStartTime = oneYearPrevious; 
    65  
    66         // get all the stats 
     104         
     105        CurrentTimeRange currentRange = new CurrentTimeRange(); 
     106        currentRange.startMonth=oneMonthPrevious; 
     107        currentRange.startToday=today; 
     108        currentRange.startWeek=oneWeekPrevious; 
     109        currentRange.startYear=oneYearPrevious; 
     110        currentRange.currentTime = currentDateTime; 
     111        return currentRange;     
     112         
     113    } 
     114     
     115 
     116    /** 
     117     * Adds the following statistical information from the attached MUA:  
     118     * 1. Number of authentications per <RANGE> 
     119     * 2.  
     120     */ 
     121    private void generateStatistics(StartStatistics startstats, DateTime currentDateTime, DateTime chosenStartTime) { 
     122         
    67123        List<StatisticalUnitInformation> statisticalUnits = getStatisticalUnits(); 
    68124        log.debug("Found {} statistics", statisticalUnits.size()); 
     
    102158                    if (table.getRows().size() == 1) { 
    103159                        if (table.getRows().get(0).getValue() instanceof Double) { 
    104                             startmodel.setNumberOfAuthenticationsPer(((Double) table.getRows().get(0).getValue())); 
     160                            startstats.setNumberOfAuthenticationsPer(((Double) table.getRows().get(0).getValue())); 
    105161                        } 
    106162                    } 
    107163            } 
    108164            else{ 
    109                 startmodel.setNumberOfAuthenticationsPer(0); 
     165                startstats.setNumberOfAuthenticationsPer(0); 
    110166            } 
    111167        } 
     
    121177                        log.debug("Number of rows: {}",table.getRows().size()); 
    122178                        if (table.getRows() != null) { 
    123                             startmodel.setNumberOfUniqueAuthenticationsPer(table.getRows().size()); 
     179                            startstats.setNumberOfUniqueAuthenticationsPer(table.getRows().size()); 
    124180                        } 
    125181                    } 
    126182            } 
    127183            else{ 
    128                 startmodel.setNumberOfUniqueAuthenticationsPer(0); 
     184                startstats.setNumberOfUniqueAuthenticationsPer(0); 
    129185            } 
    130186 
     
    137193            if (topFiveResourcesModel!=null){ 
    138194                RaptorTableChartModel table = ChartProcessor.constructRaptorTableChartModel(topFiveResourcesModel); 
    139                 startmodel.setTopFiveResouces(table); 
     195                startstats.setTopFiveResouces(table); 
    140196            } 
    141197            else 
    142                 startmodel.setTopFiveResouces(null); 
     198                startstats.setTopFiveResouces(null); 
    143199        } 
    144200 
     
    149205            if (bottomFiveResourcesModel!=null){ 
    150206                RaptorTableChartModel table = ChartProcessor.constructRaptorTableChartModel(bottomFiveResourcesModel); 
    151                 startmodel.setBottomFiveResouces(table); 
     207                startstats.setBottomFiveResouces(table); 
    152208            } 
    153209            else 
    154                 startmodel.setBottomFiveResouces(null); 
     210                startstats.setBottomFiveResouces(null); 
    155211 
    156212        } 
     
    167223                            graph.getGroupLabels().set(i,new String("")); 
    168224                    } 
    169                     startmodel.setHeadlineGraph(graph); 
     225                    startstats.setHeadlineGraph(graph); 
    170226            } 
    171227            else 
    172                 startmodel.setHeadlineGraph(null); 
    173         } 
    174  
    175         Capabilities capabilities = getAttachedCapabilities(); 
    176         if (capabilities!=null){ 
    177             startmodel.setAttachedMUACapabilities(capabilities); 
    178  
    179         } 
     228                startstats.setHeadlineGraph(null); 
     229        } 
     230 
     231 
    180232 
    181233    } 
     
    195247    public Capabilities getAttachedCapabilities() { 
    196248            return webEngine.getAttachedCapabilities(); 
    197         } 
     249    } 
    198250 
    199251 
    200252} 
     253 
     254/* Temporary storage for constantly updated start times */ 
     255class CurrentTimeRange{ 
     256    public DateTime currentTime; 
     257    public DateTime startToday; 
     258    public DateTime startWeek; 
     259    public DateTime startMonth; 
     260    public DateTime startYear;     
     261 
     262} 
  • raptor-web/trunk/src/main/resources/log4j.properties

    r476 r485  
    99#log4j.logger.org.springframework = DEBUG, stdout 
    1010log4j.logger.uk.ac = DEBUG, stdout 
     11log4j.logger.org.quartz=DEBUG,stdout 
    1112#log4j.logger.org.springframework.security=DEBUG, stdout 
  • raptor-web/trunk/src/main/webapp/WEB-INF/config/web-setup.xml

    r475 r485  
    6464 
    6565 
     66        <!-- Set up the start page background stats generator --> 
     67        <bean id="statsSchedular" class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> 
     68                <property name="triggers"> 
     69                        <list> 
     70                        <ref local="SystemStatsQuickTrigger"/>  
     71                        </list> 
     72                </property> 
     73        </bean> 
     74         
     75        <bean id="SystemStatsQuickTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean"> 
     76                <property name="jobDetail"> 
     77                        <ref local="SystemStatsJobDetail" /> 
     78                </property> 
     79                <property name="startDelay" value="5000"/> 
     80                <property name="repeatInterval" value="300000"/> 
     81        </bean> 
    6682 
     83        <bean id="SystemStatsJobDetail" 
     84                class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> 
     85                <property name="targetObject"> 
     86                        <ref bean="startService" /> 
     87                </property> 
     88                <property name="targetMethod"> 
     89                        <value>generateStatisticsBackground</value> 
     90                </property> 
     91                <property name="concurrent"> 
     92                        <value>false</value> 
     93                </property> 
     94        </bean> 
    6795 
    6896 
  • raptor-web/trunk/src/main/webapp/WEB-INF/flows/reports/startReport.jspx

    r484 r485  
    5151                                                        <tr:spacer height="10px" /> 
    5252                                                        <tr:chart id="chart" verticalMajorSections="15" 
    53                                                                 value="#{flowScope.websession.startmodel.headlineGraph}" 
    54                                                                 rendered="#{not empty flowScope.websession.startmodel.headlineGraph}" 
     53                                                                value="#{flowScope.websession.startmodel.startStatistics.headlineGraph}" 
     54                                                                rendered="#{not empty flowScope.websession.startmodel.startStatistics.headlineGraph}" 
    5555                                                                inlineStyle="width:100%; height:270px; border-style: hidden;" 
    5656                                                                type="stackedArea" width="98%" animationDuration="400" 
     
    7171                                                                <tr:spacer height="7px" /> 
    7272                                                                <tr:outputText 
    73                                                                         value="#{flowScope.websession.startmodel.numberOfAuthenticationsPerFormatted}" 
     73                                                                        value="#{flowScope.websession.startmodel.startStatistics.numberOfAuthenticationsPerFormatted}" 
    7474                                                                        partialTriggers=":quickStatsRangeSelector" 
    7575                                                                        inlineStyle="font-size:270%;font-weight: bold" /> 
     
    7979                                                                <tr:spacer height="7px" /> 
    8080                                                                <tr:outputText 
    81                                                                         value="#{flowScope.websession.startmodel.numberOfUniqueAuthenticationsPerFormatted}" 
     81                                                                        value="#{flowScope.websession.startmodel.startStatistics.numberOfUniqueAuthenticationsPerFormatted}" 
    8282                                                                        inlineStyle="font-size:270%;font-weight: bold" /> 
    8383                                                        </tr:panelFormLayout> 
     
    8585                                                        <tr:spacer width="30px" /> 
    8686 
    87                                                         <tr:table value="#{flowScope.websession.startmodel.topFiveResouces.rows}" 
     87                                                        <tr:table value="#{flowScope.websession.startmodel.startStatistics.topFiveResouces.rows}" 
    8888                                                                bandingInterval="2" banding="row" var="row" width="100%" 
    89                                                                 rendered="#{not empty flowScope.websession.startmodel.topFiveResouces}"> 
     89                                                                rendered="#{not empty flowScope.websession.startmodel.startStatistics.topFiveResouces}"> 
    9090                                                                <f:facet name="header"> 
    9191                                                                        <tr:outputText value="Top 5 eResources" /> 
     
    108108                                                        <tr:spacer width="15px" /> 
    109109 
    110                                                         <tr:table value="#{flowScope.websession.startmodel.bottomFiveResouces.rows}" 
     110                                                        <tr:table value="#{flowScope.websession.startmodel.startStatistics.bottomFiveResouces.rows}" 
    111111                                                                bandingInterval="2" banding="row" var="row" width="100%" 
    112                                                                 rendered="#{not empty flowScope.websession.startmodel.bottomFiveResouces}"> 
     112                                                                rendered="#{not empty flowScope.websession.startmodel.startStatistics.bottomFiveResouces}"> 
    113113                                                                <f:facet name="header"> 
    114114                                                                        <tr:outputText value="Bottom 5 eResources" /> 
  • raptor-web/trunk/src/main/webapp/WEB-INF/web.xml

    r475 r485  
    1414        version="2.4"> 
    1515 
    16         <description>Template Jsf Trinidad SWF Alephsa</description> 
    17         <!-- - Location of the XML file that defines the root application context  
    18                 - Applied by ContextLoaderListener. All standard beans are included in the  
    19                 raptor-servlet, security is seperated into the security.xml file --> 
     16        <description>RaptorWeb</description> 
     17         
     18         
     19        <!-- - defines setup that can be accessed by the entire servlet, not just spring 
     20        hence why security is defined here --> 
    2021        <context-param> 
    2122                <param-name>contextConfigLocation</param-name> 
    2223                <param-value> 
    23       /WEB-INF/config/raptorweb-servlet.xml 
    24       /WEB-INF/config/security.xml 
    25       </param-value> 
     24          /WEB-INF/config/security.xml 
     25      </param-value>  
    2626        </context-param> 
    2727 
     
    176176        </listener> 
    177177 
    178         <!-- Spring web flow servlet --> 
     178        <!-- Spring web flow servlet, defines config specific to the current 
     179        application instance --> 
    179180        <servlet> 
    180181                <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> 
    181182                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    182                 <init-param> 
     183                 <init-param> 
    183184                        <param-name>contextConfigLocation</param-name> 
    184                         <param-value>/WEB-INF/config/raptorweb-servlet.xml</param-value> 
     185                        <param-value>/WEB-INF/config/raptorweb-servlet.xml 
     186                        </param-value> 
    185187                </init-param> 
    186188                <load-on-startup>1</load-on-startup> 
Note: See TracChangeset for help on using the changeset viewer.