Changeset 537


Ignore:
Timestamp:
02/18/11 18:02:15 (2 years ago)
Author:
philsmart
Message:
 
Location:
raptor-mua/trunk/src/main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/engine/statistics/AuthenticationStatistic.java

    r535 r537  
    341341        } 
    342342 
    343         public Boolean average(String groupByField, String sqlWhere) throws StatisticalUnitException { 
     343        public Boolean groupByCountDistinct(String groupByField, String countDistinctField, String sqlWhere) throws StatisticalUnitException { 
    344344                log.debug("Performing groupByFrequency Statistical Operation"); 
    345345                log.debug("Params for method:  {},{}", statisticParameters.getMethodName(), statisticParameters.getUnitName()); 
    346                 log.debug("Grouping field: {}", groupByField); 
     346                log.debug("Grouping field: {}, count By distinct field {}", groupByField, countDistinctField); 
    347347 
    348348                DateTime start = startingTime(); 
    349349                DateTime end = endingTime(); 
    350350                log.debug("groupByFrequency between [start:{}] [end:{}]", start, end); 
    351                 String tableName = ReflectionHelper.findEntrySubclassForMethod(groupByField); 
     351                //need to find the lowest level class from which to perform these statistics 
     352                String tableName = ReflectionHelper.determineSubclassForMethods(groupByField,countDistinctField); 
     353 
    352354                log.debug("Select {}, tableName {}", groupByField, tableName); 
    353355                List results = getEntryHandler().query( 
    354                                 "select " + groupByField + ",count(*) from " + tableName + " where (eventTime between '" + start 
     356                                "select " + groupByField + ",count(distinct "+countDistinctField+") from " + tableName + " where (eventTime between '" + start 
    355357                                                + "' and '" + end + "') group by (" + groupByField + ")"); 
    356  
    357358 
    358359 
  • raptor-mua/trunk/src/main/java/uk/ac/cardiff/raptormua/runtimeutils/ReflectionHelper.java

    r417 r537  
    2929import java.util.jar.JarInputStream; 
    3030 
    31 import org.apache.log4j.Logger; 
     31import org.slf4j.Logger; 
     32import org.slf4j.LoggerFactory; 
     33 
    3234 
    3335import sun.misc.Launcher; 
     
    3537/** 
    3638 * @author philsmart 
    37  *  
     39 * 
    3840 */ 
    3941public class ReflectionHelper { 
    40         static Logger log = Logger.getLogger(ReflectionHelper.class); 
     42        static Logger log = LoggerFactory.getLogger(ReflectionHelper.class); 
     43 
     44        public static String determineSubclassForMethods(String methodOne, String methodTwo){ 
     45            Object methodOneObject = findEntrySubclassForMethodAsObject(methodOne); 
     46            Object methodTwoObject = findEntrySubclassForMethodAsObject(methodTwo); 
     47            log.debug("Classes found, methodOne {}, methodTwo {}",methodOneObject.getClass(),methodTwoObject.getClass()); 
     48            //is methodTwoObject a superclass of methodOneObject, if it is, then its either an equivalent class 
     49            //or its a subclass so return it 
     50            log.debug("Is methodOne a superclass of methodTwo {}",(methodOneObject.getClass().isAssignableFrom(methodTwoObject.getClass()))); 
     51            if (methodTwoObject.getClass().isAssignableFrom(methodOneObject.getClass())){ 
     52                return methodOneObject.getClass().getSimpleName(); 
     53            } 
     54            else{ 
     55                return methodTwoObject.getClass().getSimpleName(); 
     56            } 
     57 
     58        } 
     59 
     60 
     61        public static Object findEntrySubclassForMethodAsObject(String fieldName) { 
     62                String forPckgName = "uk.ac.cardiff.model"; 
     63                String jarFile = getJARFilePath(forPckgName); 
     64                jarFile = jarFile.replace("file:", ""); 
     65                List<String> classes = getClasseNamesInPackageJAR(jarFile, forPckgName); 
     66                ArrayList allclasses = new ArrayList(); 
     67                for (String classname : classes) { 
     68                        try { 
     69                                Object o = Class.forName(classname.replace(".class", "")).newInstance(); 
     70                                if (o instanceof uk.ac.cardiff.model.Entry) { 
     71                                    //log.debug("Found classname: "+classname.replace(".class", "")); 
     72                                        allclasses.add(o); 
     73                                } 
     74                        } catch (ClassNotFoundException cnfex) { 
     75                                log.error("{}",cnfex); 
     76                        } catch (InstantiationException iex) { 
     77                                // We try to instantiate an interface 
     78                                // or an object that does not have a 
     79                                // default constructor 
     80                        } catch (IllegalAccessException iaex) { 
     81                                // The class is not public 
     82                        } 
     83                } 
     84 
     85                Object objectWithMethod = null; 
     86                for (Object object : allclasses) { 
     87                        if (hasField(object, fieldName)) { 
     88                                objectWithMethod = object; 
     89                        } 
     90                } 
     91                if (objectWithMethod != null) { 
     92                        log.debug("Object " + objectWithMethod.getClass().getName() + " has method " + fieldName 
     93                                        + " returning simple name " + objectWithMethod.getClass().getSimpleName()); 
     94                        return objectWithMethod; 
     95                } 
     96 
     97                return null; 
     98 
     99        } 
    41100 
    42101        /** 
    43102         * This method finds the simple name of the class in the uk.ac.cardiff.model 
    44103         * package that contains the <code>fieldName</code>. 
    45          *  
     104         * 
    46105         * @param fieldName 
    47106         * @return 
     
    61120                                } 
    62121                        } catch (ClassNotFoundException cnfex) { 
    63                                 log.error(cnfex); 
     122                                log.error("{}",cnfex); 
    64123                        } catch (InstantiationException iex) { 
    65124                                // We try to instantiate an interface 
     
    70129                        } 
    71130                } 
    72                  
     131 
    73132                Object objectWithMethod = null; 
    74133                for (Object object : allclasses) { 
     
    113172         * Gets the names of the classes, as strings, in the jar <code>jarName</code> and package 
    114173         * <code>packageName</code> 
    115          *  
     174         * 
    116175         * @param jarName 
    117176         * @param packageName 
     
    143202         * the uk.ac.cardiff.model.Entry class in the package <code>pckgname</code> if they 
    144203         * exist outside any JAR libraries, use <code>getClasseNamesInPackageJAR</code> 
    145          *  
     204         * 
    146205         * @param pckgname 
    147206         * @return 
     
    182241                                                } 
    183242                                        } catch (ClassNotFoundException cnfex) { 
    184                                                 log.error(cnfex); 
     243                                                log.error("{}",cnfex); 
    185244                                        } catch (InstantiationException iex) { 
    186245                                                // We try to instantiate an interface 
     
    198257        /** 
    199258         * Checks whether the Object <code>object</code> has the field <code>fieldName</code> 
    200          *  
     259         * 
    201260         * @param object 
    202261         * @param fieldName 
  • raptor-mua/trunk/src/main/webapp/WEB-INF/statistical-units.xml

    r536 r537  
    507507                </property> 
    508508        </bean> 
    509          
    510          
     509 
     510 
    511511        <bean id="numberOfUniqueAuthenticationsPerSP" class="uk.ac.cardiff.raptormua.engine.statistics.AuthenticationStatistic"> 
    512512                <property name="statisticParameters"> 
    513513                        <bean class="uk.ac.cardiff.model.StatisticParameters"> 
    514                                         <property name="statisticType"><value>User</value></property> 
     514                                        <property name="statisticType"><value>System</value></property> 
    515515                                        <property name="unitName"><value>numberOfUniqueAuthenticationsPerSP</value></property> 
    516                                         <property name="methodName"><value>average</value></property> 
     516                                        <property name="methodName"><value>groupByCountDistinct</value></property> 
    517517                                        <property name="methodParams"> 
    518518                                                <list> 
    519519                                                        <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 
    520520                                                                <property name="parameter"><value>requestHost</value></property> 
     521 
     522                                                        </bean> 
     523                                                        <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 
     524                                                             <property name="parameter"><value>principleName</value></property> 
    521525                                                        </bean> 
    522526                                                </list> 
     
    526530                        <bean class="uk.ac.cardiff.model.Presentation"> 
    527531                            <property name="graphTitle" value="Number of Unique Authentications Per Service Provider"/> 
     532                            <property name="xAxisLabel" value="Time"/> 
     533                             <property name="yAxisLabel" value="Frequency"/> 
     534                        </bean> 
     535                    </property> 
     536 
     537                                        <property name="series"> 
     538                        <list> 
     539                            <bean class="uk.ac.cardiff.model.Series"> 
     540                                <property name="seriesLabel" value="Number of auths"/> 
     541                            </bean> 
     542                        </list> 
     543                    </property> 
     544 
     545                        </bean> 
     546                </property> 
     547                <property name="postprocessor"> 
     548                        <list> 
     549                                <ref bean="sortDsc"/> 
     550                                <ref bean="cut"/> 
     551                                <ref bean="ShibbolethMetadataNameFormatter"/> 
     552                        </list> 
     553                </property> 
     554        </bean> 
     555 
     556        <bean id="bottom5Resources" class="uk.ac.cardiff.raptormua.engine.statistics.AuthenticationStatistic"> 
     557                <property name="statisticParameters"> 
     558                        <bean class="uk.ac.cardiff.model.StatisticParameters"> 
     559                                        <property name="statisticType"><value>System</value></property> 
     560                                        <property name="unitName"><value>bottom5Resources</value></property> 
     561                                        <property name="methodName"><value>groupByFrequency</value></property> 
     562                                        <property name="methodParams"> 
     563                                                <list> 
     564                                                        <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 
     565                                                                <property name="parameter"><value>requestHost</value></property> 
     566                                                        </bean> 
     567                                                </list> 
     568                                        </property> 
     569 
     570                                         <property name="presentation"> 
     571                        <bean class="uk.ac.cardiff.model.Presentation"> 
     572                            <property name="graphTitle" value="Bottom 5 Resources"/> 
    528573                            <property name="xAxisLabel" value="Time"/> 
    529574                             <property name="yAxisLabel" value="Frequency"/> 
     
    550595        </bean> 
    551596 
    552         <bean id="bottom5Resources" class="uk.ac.cardiff.raptormua.engine.statistics.AuthenticationStatistic"> 
    553                 <property name="statisticParameters"> 
    554                         <bean class="uk.ac.cardiff.model.StatisticParameters"> 
    555                                         <property name="statisticType"><value>System</value></property> 
    556                                         <property name="unitName"><value>bottom5Resources</value></property> 
    557                                         <property name="methodName"><value>groupByFrequency</value></property> 
    558                                         <property name="methodParams"> 
    559                                                 <list> 
    560                                                         <bean class="uk.ac.cardiff.model.wsmodel.MethodParameter"> 
    561                                                                 <property name="parameter"><value>requestHost</value></property> 
    562                                                         </bean> 
    563                                                 </list> 
    564                                         </property> 
    565  
    566                                          <property name="presentation"> 
    567                         <bean class="uk.ac.cardiff.model.Presentation"> 
    568                             <property name="graphTitle" value="Bottom 5 Resources"/> 
    569                             <property name="xAxisLabel" value="Time"/> 
    570                              <property name="yAxisLabel" value="Frequency"/> 
    571                         </bean> 
    572                     </property> 
    573  
    574                                         <property name="series"> 
    575                         <list> 
    576                             <bean class="uk.ac.cardiff.model.Series"> 
    577                                 <property name="seriesLabel" value="Number of auths"/> 
    578                             </bean> 
    579                         </list> 
    580                     </property> 
    581  
    582                         </bean> 
    583                 </property> 
    584                 <property name="postprocessor"> 
    585                         <list> 
    586                                 <ref bean="sortAsc"/> 
    587                                 <ref bean="cut"/> 
    588                                 <ref bean="ShibbolethMetadataNameFormatter"/> 
    589                         </list> 
    590                 </property> 
    591         </bean> 
    592  
    593597 
    594598</beans> 
Note: See TracChangeset for help on using the changeset viewer.