File: GAUtils.java

package info (click to toggle)
libjaba-client-java 2.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,052 kB
  • sloc: java: 17,308; makefile: 12
file content (92 lines) | stat: -rw-r--r-- 2,731 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package compbio.ws.server;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.log4j.Logger;

import compbio.engine.conf.PropertyHelperManager;
import compbio.stat.ga.AnalyticsConfigData;
import compbio.stat.ga.GoogleAnalyticsTracker;
import compbio.util.PropertyHelper;
import compbio.util.Util;
import compbio.ws.client.Services;

public class GAUtils {

	// MODIFY BEFORE RELEASE!
	final static String VERSION_TYPE = "WAR";

	private static final Logger log = Logger.getLogger(GAUtils.class);

	static PropertyHelper PROP_HELPER = PropertyHelperManager.getPropertyHelper();

	// compbio.dundee.ac.uk GA tracker
	private static AnalyticsConfigData config = new AnalyticsConfigData("UA-5356328-1");

	private static GoogleAnalyticsTracker TRACKER = new GoogleAnalyticsTracker(config);

	static final boolean IS_GA_ENABLED = isGoogleAnalyticsEnabled();

	private static String SERVER_ADDRESS = getServerIP();

	private static boolean isGoogleAnalyticsEnabled() {
		String val = PROP_HELPER.getProperty("enable.ga");
		if (Util.isEmpty(val)) {
			return false;
		}
		val = val.trim();
		if ("yes".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val)) {
			return true;
		}
		return false;
	}

	private static String getServerIP() {
		String IP = "127.0.0.1";
		if (!anonymizeIP()) {
			try {
				InetAddress localAddrIP = InetAddress.getLocalHost();
				IP = localAddrIP.getCanonicalHostName();
			} catch (UnknownHostException ignored) {
			}
		}
		return IP;
	}

	private static boolean anonymizeIP() {
		String val = PROP_HELPER.getProperty("anonymize.ip");
		if (Util.isEmpty(val)) {
			return false;
		}
		if ("yes".equalsIgnoreCase(val) || "true".equalsIgnoreCase(val)) {
			return true;
		}
		return false;
	}

	static void reportUsage(Services service) {
		String service_name = "UNKNOWN";
		if (service == null) {
			log.warn("GA: Services was NULL!");
		} else {
			service_name = service.toString();
		}
		String jabaws = "JABAWS/" + service.getJabawsVersion() + "/" + service_name;
		TRACKER.trackPageViewFromReferrer(jabaws, service_name, "http://www.compbio.dundee.ac.uk", SERVER_ADDRESS, VERSION_TYPE);
		TRACKER.resetSession();
	}

	static void reportUsage(Services service,  String CLIENT_ADDRESS) {
		String service_name = "UNKNOWN";
		if (service == null) {
			log.warn("GA: Services was NULL!");
		} else {
			service_name = service.toString();
		}
		String jabaws = "JABAWS/" + service.getJabawsVersion() + "/" + service_name;
		TRACKER.trackPageViewFromReferrer(jabaws, service_name, "http://www.compbio.dundee.ac.uk", CLIENT_ADDRESS, VERSION_TYPE);
		TRACKER.resetSession();
	}

}