All Downloads are FREE. Search and download functionalities are using the official Maven repository.

prerna.util.usertracking.UserTrackerFactory Maven / Gradle / Ivy

The newest version!
package prerna.util.usertracking;

import prerna.util.Constants;
import prerna.util.Utility;

public class UserTrackerFactory {

	private static IUserTracker instance;
	private static boolean tOn = false;
	
	private UserTrackerFactory() {
		
	}
	
	public static IUserTracker getInstance() {
		if (instance == null) {
			instance = createInstance();
		}
		return instance;
	}

	public static boolean isTracking() {
		return tOn;
	}
	
	/**
	 * Determine if we should track based on key inside RDF_MAP
	 * @return
	 */
	private static IUserTracker createInstance() {
		String trackingOn = "true";
		try {
			trackingOn = Utility.getDIHelperProperty(Constants.T_ON);
			// for the old key that was google analytics specific
			if(trackingOn == null) {
				trackingOn = Utility.getDIHelperProperty("GA_TRACKING");
			}
		} catch(Exception e) {
			// this happens if DIHelper isn't loaded
			// occurs when testing
			trackingOn = "false";
		}
		boolean track = true;
		if(trackingOn != null) {
			track = Boolean.valueOf(trackingOn);
		}
		if(track) {
			String endpoint = null;
			try {
				endpoint = Utility.getDIHelperProperty("T_ENDPOINT");
				if(endpoint == null) {
					// well, can't do much without an endpoint
					return new NullUserTracker();
				}
				// set the endpoint
				TrackRequestThread.setEndpoint(endpoint);
			} catch(Exception e) {
				// this happens if DIHelper isn't loaded
				// occurs when testing
			}
			tOn= true;
			return new TableUserTracker();
		}
		return new NullUserTracker();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy