use of ve.com.abicelis.remindy.exception.PlaceNotFoundException in project Remindy by abicelis.
the class RemindyDAO method getPlace.
/**
* Returns a Place given a placeId.
* @param placeId The id of the place
*/
public Place getPlace(int placeId) throws PlaceNotFoundException, SQLiteConstraintException {
SQLiteDatabase db = mDatabaseHelper.getReadableDatabase();
Cursor cursor = db.query(RemindyContract.PlaceTable.TABLE_NAME, null, RemindyContract.PlaceTable._ID + "=?", new String[] { String.valueOf(placeId) }, null, null, null);
if (cursor.getCount() == 0)
throw new PlaceNotFoundException("Specified Place not found in the database. Passed id=" + placeId);
if (cursor.getCount() > 1)
throw new SQLiteConstraintException("Database UNIQUE constraint failure, more than one record found. Passed value=" + placeId);
cursor.moveToNext();
return getPlaceFromCursor(cursor);
}
use of ve.com.abicelis.remindy.exception.PlaceNotFoundException in project Remindy by abicelis.
the class GeofenceNotificationIntentService method getGeofenceNotificationTitle.
private String getGeofenceNotificationTitle(int geofenceTransition, Geofence triggeringGeofence) {
String transition = "";
switch(geofenceTransition) {
case Geofence.GEOFENCE_TRANSITION_ENTER:
transition = getResources().getString(R.string.notification_service_geofence_enter);
break;
case Geofence.GEOFENCE_TRANSITION_EXIT:
transition = getResources().getString(R.string.notification_service_geofence_exit);
break;
case Geofence.GEOFENCE_TRANSITION_DWELL:
// transition = getResources().getString(R.string.notification_service_geofence_dwell);
transition = getResources().getString(R.string.notification_service_geofence_enter);
break;
}
int placeId = Integer.valueOf(triggeringGeofence.getRequestId());
try {
Place place = new RemindyDAO(this).getPlace(placeId);
return String.format(Locale.getDefault(), getResources().getString(R.string.notification_service_geofence_title), transition, place.getAlias());
} catch (PlaceNotFoundException e) {
return "";
}
}
use of ve.com.abicelis.remindy.exception.PlaceNotFoundException in project Remindy by abicelis.
the class RemindyDAO method getReminderOfTask.
/**
* Returns a Reminder given its taskId and reminderType
* @param taskId The ID of the task
* @param reminderType The Type of reminder
*/
public Reminder getReminderOfTask(int taskId, @NonNull ReminderType reminderType) throws CouldNotGetDataException, SQLiteConstraintException {
SQLiteDatabase db = mDatabaseHelper.getWritableDatabase();
Reminder reminder;
String tableName, whereClause;
switch(reminderType) {
case ONE_TIME:
whereClause = RemindyContract.OneTimeReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
tableName = RemindyContract.OneTimeReminderTable.TABLE_NAME;
break;
case REPEATING:
whereClause = RemindyContract.RepeatingReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
tableName = RemindyContract.RepeatingReminderTable.TABLE_NAME;
break;
case LOCATION_BASED:
whereClause = RemindyContract.LocationBasedReminderTable.COLUMN_NAME_TASK_FK.getName() + " =?";
tableName = RemindyContract.LocationBasedReminderTable.TABLE_NAME;
break;
default:
throw new CouldNotGetDataException("ReminderType is invalid. Type=" + reminderType);
}
Cursor cursor = db.query(tableName, null, whereClause, new String[] { String.valueOf(taskId) }, null, null, null);
try {
if (cursor.getCount() == 0)
throw new CouldNotGetDataException("Specified Reminder not found in the database. Passed id=" + taskId);
if (cursor.getCount() > 1)
throw new SQLiteConstraintException("Database UNIQUE constraint failure, more than one Reminder found. Passed id=" + taskId);
cursor.moveToNext();
switch(reminderType) {
case ONE_TIME:
reminder = getOneTimeReminderFromCursor(cursor);
break;
case REPEATING:
reminder = getRepeatingReminderFromCursor(cursor);
break;
case LOCATION_BASED:
reminder = getLocationBasedReminderFromCursor(cursor);
int placeId = ((LocationBasedReminder) reminder).getPlaceId();
try {
((LocationBasedReminder) reminder).setPlace(getPlace(placeId));
} catch (PlaceNotFoundException | SQLiteConstraintException e) {
throw new CouldNotGetDataException("Error trying to get Place for Location-based Reminder", e);
}
break;
default:
throw new CouldNotGetDataException("ReminderType is invalid. Type=" + reminderType);
}
} finally {
cursor.close();
}
return reminder;
}
Aggregations