-
Notifications
You must be signed in to change notification settings - Fork 426
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AC-1101: Migrate LocationDAO to Kotlin (#1020)
* Rename .java to .kt * AC-1101: Migrate LocationDAO to Kotlin
- Loading branch information
1 parent
c97e767
commit 2b48736
Showing
2 changed files
with
107 additions
and
115 deletions.
There are no files selected for viewing
115 changes: 0 additions & 115 deletions
115
openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/dao/LocationDAO.java
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
openmrs-android-sdk/src/main/java/com/openmrs/android_sdk/library/dao/LocationDAO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package com.openmrs.android_sdk.library.dao | ||
|
||
import com.openmrs.android_sdk.library.OpenmrsAndroid | ||
import com.openmrs.android_sdk.library.databases.AppDatabase | ||
import com.openmrs.android_sdk.library.databases.AppDatabaseHelper.createObservableIO | ||
import com.openmrs.android_sdk.library.databases.entities.LocationEntity | ||
import com.openmrs.android_sdk.utilities.StringUtils.notNull | ||
import rx.Observable | ||
import java.util.concurrent.Callable | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
|
||
/** | ||
* The type Location dao. | ||
*/ | ||
@Singleton | ||
class LocationDAO @Inject constructor() { | ||
/** | ||
* The Location room dao. | ||
*/ | ||
var locationRoomDAO = AppDatabase.getDatabase( | ||
OpenmrsAndroid.getInstance()!!.applicationContext | ||
).locationRoomDAO() | ||
|
||
/** | ||
* Save location observable. | ||
* | ||
* @param location the location | ||
* @return the observable | ||
*/ | ||
fun saveLocation(location: LocationEntity): Observable<Long> { | ||
return createObservableIO(Callable { locationRoomDAO.addLocation(location) }) | ||
} | ||
|
||
/** | ||
* Delete all locations. | ||
* @return boolean true if successful | ||
*/ | ||
fun deleteAllLocations(): Observable<Boolean> { | ||
return createObservableIO(Callable { | ||
locationRoomDAO.deleteAllLocations() | ||
true | ||
}) | ||
} | ||
|
||
/** | ||
* Gets locations. | ||
* | ||
* @return the locations | ||
*/ | ||
fun getLocations(): Observable<List<LocationEntity>>{ | ||
return createObservableIO(Callable<List<LocationEntity>> { | ||
try { | ||
return@Callable locationRoomDAO.getLocations().blockingGet() | ||
} catch (e: java.lang.Exception) { | ||
return@Callable ArrayList<LocationEntity>() | ||
} | ||
}) | ||
} | ||
|
||
|
||
/** | ||
* Find location by name location entity. | ||
* | ||
* @param name the name | ||
* @return the location entity | ||
*/ | ||
fun findLocationByName(name: String?): LocationEntity? { | ||
return if (!notNull(name)) { | ||
null | ||
} else try { | ||
locationRoomDAO.findLocationByName(name).blockingGet() | ||
} catch (e: Exception) { | ||
LocationEntity(name!!) | ||
} | ||
} | ||
|
||
/** | ||
* Find location by uuid location entity. | ||
* | ||
* @param uuid the uuid | ||
* @return the location entity | ||
*/ | ||
fun findLocationByUUID(uuid: String?): LocationEntity? { | ||
return if (!notNull(uuid)) { | ||
null | ||
} else try { | ||
locationRoomDAO.findLocationByUUID(uuid).blockingGet() | ||
} catch (e: Exception) { | ||
LocationEntity("") | ||
} | ||
} | ||
} |