Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions AutomatticTracks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.novoda:bintray-release:0.3.4'
}
}
Expand All @@ -20,13 +20,13 @@ dependencies {
}

android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
compileSdkVersion 25
buildToolsVersion "25.0.2"

defaultConfig {
versionName "1.1.1"
versionName "1.1.2"
minSdkVersion 14
targetSdkVersion 24
targetSdkVersion 25
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.automattic.android.tracks;

import android.text.TextUtils;
import android.util.Log;

import com.automattic.android.tracks.Exceptions.EventDetailsException;
import com.automattic.android.tracks.Exceptions.EventNameException;

import org.json.JSONException;
Expand Down Expand Up @@ -33,12 +35,25 @@ public class Event implements Serializable {
private JSONObject mCustomEventProps;

public Event(String mEventName, String userID, TracksClient.NosaraUserType uType,
String userAgent, long timeStamp) throws EventNameException {
String userAgent, long timeStamp) throws EventNameException, EventDetailsException {

checkEventName(mEventName);
if (TextUtils.isEmpty(userID)) {
throw new EventDetailsException("Username cannot be empty!");
}

if (uType == null) {
throw new EventDetailsException("NosaraUserType cannot be null!");
}

if (TextUtils.isEmpty(userAgent)) {
Log.w(LOGTAG, "User Agent string is empty!");
}

this.mEventName = mEventName;
this.mUser = userID;
this.mUserType = uType;
this.mUserAgent = userAgent;
this.mUserAgent = StringUtils.notNullStr(userAgent);
this.mTimeStamp = timeStamp;
}

Expand All @@ -48,6 +63,10 @@ private void checkEventName(String name) throws EventNameException {
return;
}

if (TextUtils.isEmpty(name)) {
throw new EventNameException("Event name must not ne empty or null");
}

if (name.contains("-")) {
String errorMessage = "Event name must not contains dashes.";
throw new EventNameException(errorMessage);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.automattic.android.tracks.Exceptions;

public class EventDetailsException extends Exception {
public EventDetailsException(String detailMessage) {
super(detailMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ public static boolean containsWhiteSpace(final String testCode) {
return false;
}

/*
* returns empty string if passed string is null, otherwise returns passed string
*/
public static String notNullStr(String s) {
if (s == null) {
return "";
}
return s;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Handler;
import android.util.Log;

import com.automattic.android.tracks.Exceptions.EventDetailsException;
import com.automattic.android.tracks.Exceptions.EventNameException;
import com.automattic.android.tracks.datasets.EventTable;

Expand Down Expand Up @@ -368,7 +369,7 @@ public void track(String eventName, String user, NosaraUserType userType) {
}

public void track(String eventName, JSONObject customProps, String user, NosaraUserType userType) {
Event event = null;
Event event;
try {
event = new Event(
eventName,
Expand All @@ -377,7 +378,7 @@ public void track(String eventName, JSONObject customProps, String user, NosaraU
getUserAgent(),
System.currentTimeMillis()
);
} catch (EventNameException e) {
} catch (EventNameException | EventDetailsException e) {
Log.e(LOGTAG, "Cannot create the event: " +eventName, e);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static void insertEvent(Context ctx, Event event) {
stmt.bindString(1, event.getEventName());
stmt.bindString(2, event.getUser());
stmt.bindString(3, event.getUserAgent());
stmt.bindLong(4, event.getUserType().ordinal());
stmt.bindLong(4, event.getUserType().ordinal());

if (event.getUserProperties() != null) {
stmt.bindString(5, event.getUserProperties().toString());
Expand All @@ -97,11 +97,13 @@ public static void insertEvent(Context ctx, Event event) {
}

stmt.bindLong(8, event.getTimeStamp());
stmt.bindLong(9, event.getRetryCount());
stmt.bindLong(9, event.getRetryCount());

stmt.execute();

db.setTransactionSuccessful();
} catch (IllegalArgumentException e) {
Log.e(TracksDatabaseHelper.LOGTAG, "Cannot insert the current event. Please check the details of the event!", e);
} finally {
db.endTransaction();
SqlUtils.closeStatement(stmt);
Expand Down