Google Analytics statistics is added
authorpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Tue, 11 Oct 2011 11:37:05 +0000 (11:37 +0000)
committerpvtroshin <pvtroshin@e3abac25-378b-4346-85de-24260fe3988d>
Tue, 11 Oct 2011 11:37:05 +0000 (11:37 +0000)
git-svn-id: link to svn.lifesci.dundee.ac.uk/svn/barton/ptroshin/JABA2@4651 e3abac25-378b-4346-85de-24260fe3988d

13 files changed:
.classpath
WEB-INF/lib/compbio-ga-1.0.jar [new file with mode: 0644]
build.xml
conf/GA.properties
engine/compbio/engine/conf/PropertyHelperManager.java
lib/src/compbio-ga-src-1.0.jar [new file with mode: 0644]
webservices/compbio/ws/server/GAUtils.java [new file with mode: 0644]
webservices/compbio/ws/server/LocalURL.txt [deleted file]
webservices/compbio/ws/server/MafftWS.java
webservices/compbio/ws/server/MuscleWS.java
webservices/compbio/ws/server/ProbconsWS.java
webservices/compbio/ws/server/TcoffeeWS.java
webservices/compbio/ws/server/WSUtil.java

index 9651a3f..c9f256a 100644 (file)
@@ -13,5 +13,6 @@
        <classpathentry kind="lib" path="WEB-INF/lib/compbio-annotations-1.0.jar"/>\r
        <classpathentry kind="lib" path="WEB-INF/lib/compbio-util-1.4.jar"/>\r
        <classpathentry kind="lib" path="WEB-INF/lib/derby.jar"/>\r
+       <classpathentry kind="lib" path="WEB-INF/lib/compbio-ga-1.0.jar"/>\r
        <classpathentry kind="output" path="WEB-INF/classes"/>\r
 </classpath>\r
diff --git a/WEB-INF/lib/compbio-ga-1.0.jar b/WEB-INF/lib/compbio-ga-1.0.jar
new file mode 100644 (file)
index 0000000..378a99a
Binary files /dev/null and b/WEB-INF/lib/compbio-ga-1.0.jar differ
index 208fcbf..426e3ca 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -17,6 +17,7 @@
        <!-- dependencies on other compbio projects  -->\r
        <property name="compbio-annotation" value="compbio-annotations-1.0.jar"/>\r
        <property name="compbio-util" value="compbio-util-1.4.jar"/>\r
+       <property name="compbio-ga" value="compbio-ga-1.0.jar"/>\r
        \r
        <!-- products -->\r
        <property name="jaba_version" value="2.0"/>\r
index 223b9a7..526a654 100644 (file)
@@ -1,14 +1,14 @@
-# This file contains settings for Google Analytics Statistics Engine.\r
+# This file contains settings for Google Analytics (GA) Statistics Engine.\r
 # Feel free to remove/delete this file if you do not want us to see that you\r
 # use JABAWS. However, we would appreciate it greatly if you could leave it on.  \r
-# We depend on the JABAWS usage statistics for our future funding. We do not \r
-# collect any personal data. That data that we submit is as follows\r
+# JABAWS usage statistics are collected for funding and reporting purposes, and \r
+# no private information is collected. The data sent by JABAWS is as follows: \r
 # 1) The IP address of the JABAWS server machine.\r
 # 2) The name of the web service that was called.   \r
 # 3) A few details of the system such as java version, user language, color depth, screen\r
 # resolution and character encoding.\r
 \r
-# All calls to statistics are completed asynchronously and create very little\r
+# All calls to GA are completed asynchronously and create very little\r
 # overhead. Thus they do not influence the server response time or performance.\r
 \r
 # Values yes or true = enable GA, any other value will disable it\r
index fb35362..b3d2b66 100644 (file)
@@ -61,8 +61,10 @@ public final class PropertyHelperManager {
                                                + "Engine.cluster.properties");\r
                                File execProp = getResourceFromClasspath(confDir\r
                                                + "Executable.properties");\r
+                               File gaProp = getResourceFromClasspath(confDir\r
+                                               + "GA.properties");\r
                                ph = new PropertyHelper(locEngineProp, clustEngineProp,\r
-                                               execProp);\r
+                                               execProp, gaProp);\r
                        } catch (IOException e) {\r
                                log.warn(\r
                                                "Cannot read property files! Reason: "\r
diff --git a/lib/src/compbio-ga-src-1.0.jar b/lib/src/compbio-ga-src-1.0.jar
new file mode 100644 (file)
index 0000000..fad0585
Binary files /dev/null and b/lib/src/compbio-ga-src-1.0.jar differ
diff --git a/webservices/compbio/ws/server/GAUtils.java b/webservices/compbio/ws/server/GAUtils.java
new file mode 100644 (file)
index 0000000..e4473d1
--- /dev/null
@@ -0,0 +1,82 @@
+package compbio.ws.server;\r
+\r
+import java.net.InetAddress;\r
+import java.net.UnknownHostException;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import compbio.engine.conf.PropertyHelperManager;\r
+import compbio.stat.ga.AnalyticsConfigData;\r
+import compbio.stat.ga.GoogleAnalyticsTracker;\r
+import compbio.util.PropertyHelper;\r
+import compbio.util.Util;\r
+import compbio.ws.client.Services;\r
+\r
+public class GAUtils {\r
+\r
+       // MODIFY BEFORE RELEASE!\r
+       final static String VERSION_TYPE = "WAR";\r
+\r
+       private static final Logger log = Logger.getLogger(GAUtils.class);\r
+\r
+       static PropertyHelper PROP_HELPER = PropertyHelperManager\r
+                       .getPropertyHelper();\r
+\r
+       private static AnalyticsConfigData config = new AnalyticsConfigData(\r
+                       "UA-26161150-1");\r
+\r
+       private static GoogleAnalyticsTracker TRACKER = new GoogleAnalyticsTracker(\r
+                       config);\r
+\r
+       public static final boolean IS_GA_ENABLED = isGoogleAnalyticsEnabled();\r
+\r
+       private static String SERVER_ADDRESS = getServerIP();\r
+\r
+       private static boolean isGoogleAnalyticsEnabled() {\r
+               String val = PROP_HELPER.getProperty("enable.ga");\r
+               if (Util.isEmpty(val)) {\r
+                       return false;\r
+               }\r
+               val = val.trim();\r
+               if ("yes".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val)) {\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       private static String getServerIP() {\r
+               String IP = "127.0.0.1";\r
+               if (!anonymizeIP()) {\r
+                       try {\r
+                               InetAddress localAddrIP = InetAddress.getLocalHost();\r
+                               IP = localAddrIP.getCanonicalHostName();\r
+                       } catch (UnknownHostException ignored) {\r
+                       }\r
+               }\r
+               return IP;\r
+       }\r
+\r
+       private static boolean anonymizeIP() {\r
+               String val = PROP_HELPER.getProperty("anonymize.ip");\r
+               if (Util.isEmpty(val)) {\r
+                       return false;\r
+               }\r
+               if ("yes".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val)) {\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       static void reportUsage(Services service) {\r
+               String service_name = "UNKNOWN";\r
+               if (service == null) {\r
+                       log.warn("GA: Services was NULL!");\r
+               } else {\r
+                       service_name = service.toString();\r
+               }\r
+               TRACKER.trackPageViewFromReferrer("JABAWS/2.0/" + service_name,\r
+                               service_name, "http://www.compbio.dundee.ac.uk",\r
+                               SERVER_ADDRESS, VERSION_TYPE);\r
+               TRACKER.resetSession();\r
+       }\r
+}\r
diff --git a/webservices/compbio/ws/server/LocalURL.txt b/webservices/compbio/ws/server/LocalURL.txt
deleted file mode 100644 (file)
index aa70a6f..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-http://localhost:7979/Clustal\r
-http://localhost:8080/ws/Clustal\r
-http://localhost:7979/Muscle\r
index 63de39b..f293ae7 100644 (file)
@@ -66,7 +66,7 @@ public class MafftWS implements MsaWS<Mafft> {
                        throws JobSubmissionException {\r
                WSUtil.validateFastaInput(sequences);\r
                ConfiguredExecutable<Mafft> confMafft = init(sequences);\r
-               return WSUtil.align(sequences, confMafft, null, "align", getLimit(""));\r
+               return WSUtil.align(sequences, confMafft, log, "align", getLimit(""));\r
        }\r
 \r
        ConfiguredExecutable<Mafft> init(List<FastaSequence> dataSet)\r
@@ -88,7 +88,7 @@ public class MafftWS implements MsaWS<Mafft> {
                                Mafft.KEY_VALUE_SEPARATOR);\r
                log.info("Setting parameters: " + params);\r
                confMafft.addParameters(params);\r
-               return WSUtil.align(sequences, confMafft, null, "customAlign",\r
+               return WSUtil.align(sequences, confMafft, log, "customAlign",\r
                                getLimit(""));\r
        }\r
 \r
@@ -106,7 +106,7 @@ public class MafftWS implements MsaWS<Mafft> {
                // particular preset is not found\r
                Limit<Mafft> limit = getLimit(preset.getName());\r
 \r
-               return WSUtil.align(sequences, confMafft, null, "presetAlign", limit);\r
+               return WSUtil.align(sequences, confMafft, log, "presetAlign", limit);\r
        }\r
 \r
        @SuppressWarnings("unchecked")\r
index 95cef8b..a9d6c52 100644 (file)
@@ -66,7 +66,7 @@ public class MuscleWS implements MsaWS<Muscle> {
                        throws JobSubmissionException {\r
                WSUtil.validateFastaInput(sequences);\r
                ConfiguredExecutable<Muscle> confMuscle = init(sequences);\r
-               return WSUtil.align(sequences, confMuscle, null, "align", getLimit(""));\r
+               return WSUtil.align(sequences, confMuscle, log, "align", getLimit(""));\r
        }\r
 \r
        ConfiguredExecutable<Muscle> init(List<FastaSequence> sequences)\r
@@ -90,7 +90,7 @@ public class MuscleWS implements MsaWS<Muscle> {
                List<String> params = WSUtil.getCommands(options,\r
                                Muscle.KEY_VALUE_SEPARATOR);\r
                confMuscle.addParameters(params);\r
-               return WSUtil.align(sequences, confMuscle, null, "customAlign",\r
+               return WSUtil.align(sequences, confMuscle, log, "customAlign",\r
                                getLimit(""));\r
        }\r
 \r
@@ -105,7 +105,7 @@ public class MuscleWS implements MsaWS<Muscle> {
                ConfiguredExecutable<Muscle> confMuscle = init(sequences);\r
                confMuscle.addParameters(preset.getOptions());\r
                Limit<Muscle> limit = getLimit(preset.getName());\r
-               return WSUtil.align(sequences, confMuscle, null, "presetAlign", limit);\r
+               return WSUtil.align(sequences, confMuscle, log, "presetAlign", limit);\r
        }\r
 \r
        @SuppressWarnings("unchecked")\r
index 3d80cad..71f4730 100644 (file)
@@ -63,8 +63,8 @@ public class ProbconsWS implements MsaWS<Probcons> {
                        throws JobSubmissionException {\r
                WSUtil.validateFastaInput(sequences);\r
                ConfiguredExecutable<Probcons> confProbcons = init(sequences);\r
-               return WSUtil.align(sequences, confProbcons, null, "align",\r
-                               getLimit(""));\r
+               return WSUtil\r
+                               .align(sequences, confProbcons, log, "align", getLimit(""));\r
        }\r
 \r
        ConfiguredExecutable<Probcons> init(List<FastaSequence> dataSet)\r
@@ -86,7 +86,7 @@ public class ProbconsWS implements MsaWS<Probcons> {
                                Probcons.KEY_VALUE_SEPARATOR);\r
                log.info("Setting parameters:" + params);\r
                confProbcons.addParameters(params);\r
-               return WSUtil.align(sequences, confProbcons, null, "customAlign",\r
+               return WSUtil.align(sequences, confProbcons, log, "customAlign",\r
                                getLimit(""));\r
        }\r
 \r
@@ -101,8 +101,7 @@ public class ProbconsWS implements MsaWS<Probcons> {
                ConfiguredExecutable<Probcons> confProbcons = init(sequences);\r
                confProbcons.addParameters(preset.getOptions());\r
                Limit<Probcons> limit = getLimit(preset.getName());\r
-               return WSUtil\r
-                               .align(sequences, confProbcons, null, "presetAlign", limit);\r
+               return WSUtil.align(sequences, confProbcons, log, "presetAlign", limit);\r
        }\r
 \r
        @SuppressWarnings("unchecked")\r
index e9bda4d..086d870 100644 (file)
@@ -67,8 +67,7 @@ public class TcoffeeWS implements MsaWS<Tcoffee> {
                        throws JobSubmissionException {\r
                WSUtil.validateFastaInput(sequences);\r
                ConfiguredExecutable<Tcoffee> confTcoffee = init(sequences);\r
-               return WSUtil\r
-                               .align(sequences, confTcoffee, null, "align", getLimit(""));\r
+               return WSUtil.align(sequences, confTcoffee, log, "align", getLimit(""));\r
        }\r
 \r
        ConfiguredExecutable<Tcoffee> init(List<FastaSequence> sequences)\r
@@ -101,7 +100,7 @@ public class TcoffeeWS implements MsaWS<Tcoffee> {
                                Tcoffee.KEY_VALUE_SEPARATOR);\r
                log.info("Setting parameters:" + params);\r
                confTcoffee.addParameters(params);\r
-               return WSUtil.align(sequences, confTcoffee, null, "customAlign",\r
+               return WSUtil.align(sequences, confTcoffee, log, "customAlign",\r
                                getLimit(""));\r
        }\r
 \r
@@ -116,7 +115,7 @@ public class TcoffeeWS implements MsaWS<Tcoffee> {
                ConfiguredExecutable<Tcoffee> confTcoffee = init(sequences);\r
                confTcoffee.addParameters(preset.getOptions());\r
                Limit<Tcoffee> limit = getLimit(preset.getName());\r
-               return WSUtil.align(sequences, confTcoffee, null, "presetAlign", limit);\r
+               return WSUtil.align(sequences, confTcoffee, log, "presetAlign", limit);\r
        }\r
 \r
        @SuppressWarnings("unchecked")\r
index fb96de8..7341989 100644 (file)
@@ -38,6 +38,8 @@ import compbio.metadata.Limit;
 import compbio.metadata.LimitExceededException;\r
 import compbio.metadata.Option;\r
 import compbio.metadata.ResultNotAvailableException;\r
+import compbio.ws.client.Services;\r
+import compbio.ws.client.ServicesUtil;\r
 \r
 public final class WSUtil {\r
 \r
@@ -106,9 +108,19 @@ public final class WSUtil {
                compbio.runner.Util.writeInput(sequences, confExec);\r
                AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
                String jobId = engine.submitJob(confExec);\r
+               reportUsage(confExec, logger);\r
                return jobId;\r
        }\r
 \r
+       static <T> void reportUsage(ConfiguredExecutable<T> confExec, Logger logger) {\r
+               if (GAUtils.IS_GA_ENABLED) {\r
+                       Services service = ServicesUtil.getServiceByRunner(confExec\r
+                                       .getExecutable().getClass());\r
+                       GAUtils.reportUsage(service);\r
+                       logger.info("Reporting GA usage for " + service);\r
+               }\r
+       }\r
+\r
        public static <T> String analize(List<FastaSequence> sequences,\r
                        ConfiguredExecutable<T> confExec, Logger log, String method,\r
                        Limit<T> limit) throws JobSubmissionException {\r
@@ -120,7 +132,7 @@ public final class WSUtil {
                compbio.runner.Util.writeInput(sequences, confExec);\r
                AsyncExecutor engine = Configurator.getAsyncEngine(confExec);\r
                String jobId = engine.submitJob(confExec);\r
-\r
+               reportUsage(confExec, log);\r
                return jobId;\r
        }\r
 \r