From dc5a165effaf847a45b9a5067bc98952a09c1ef1 Mon Sep 17 00:00:00 2001 From: "ITHQ2084\\anju.mg" Date: Mon, 26 Aug 2024 21:07:33 +0530 Subject: [PATCH] Api changes required for streak widget implementation https://github.com/BIDMCDigitalPsychiatry/LAMP-platform/issues/807 Pending indent null checking added in Wifi class --- .../lamp_core/apis/ActivityEventAPI.kt | 244 ++++++++++-------- .../lamp/lamp_kotlin/sensor_core/WiFi.kt | 96 ++++--- 2 files changed, 193 insertions(+), 147 deletions(-) diff --git a/lamp_kotlin/src/main/java/digital/lamp/lamp_kotlin/lamp_core/apis/ActivityEventAPI.kt b/lamp_kotlin/src/main/java/digital/lamp/lamp_kotlin/lamp_core/apis/ActivityEventAPI.kt index a931af8..bdc03dc 100644 --- a/lamp_kotlin/src/main/java/digital/lamp/lamp_kotlin/lamp_core/apis/ActivityEventAPI.kt +++ b/lamp_kotlin/src/main/java/digital/lamp/lamp_kotlin/lamp_core/apis/ActivityEventAPI.kt @@ -1,19 +1,28 @@ /** -* LAMP Platform -* The LAMP Platform API. -* -* The version of the OpenAPI document: 1.0.0 -* Contact: team@digitalpsych.org -* -* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). -* https://openapi-generator.tech -* Do not edit the class manually. -*/ + * LAMP Platform + * The LAMP Platform API. + * + * The version of the OpenAPI document: 1.0.0 + * Contact: team@digitalpsych.org + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ package digital.lamp.lamp_kotlin.lamp_core.apis -import digital.lamp.lamp_kotlin.lamp_core.infrastructure.* -import digital.lamp.lamp_kotlin.lamp_core.models.ActivityEvent +import android.util.Log import digital.lamp.lamp_kotlin.lamp_core.infrastructure.ApiClient +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.ClientError +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.ClientException +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.MultiValueMap +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.RequestConfig +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.RequestMethod +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.ResponseType +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.ServerError +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.ServerException +import digital.lamp.lamp_kotlin.lamp_core.infrastructure.Success +import digital.lamp.lamp_kotlin.lamp_core.models.ActivityEvent class ActivityEventAPI(basePath: kotlin.String = defaultBasePath) : ApiClient(basePath) { @@ -25,77 +34,98 @@ class ActivityEventAPI(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } /** - * Get all activity events for a participant. - * Get the set of all activity events produced by a given participant, by identifier. - * @param participantId - * @param origin (optional) - * @param from (optional) - * @param to (optional) - * @param transform (optional) - * @return kotlin.Array - * @throws UnsupportedOperationException If the API returns an informational or redirection response - * @throws ClientException If the API returns a client error response - * @throws ServerException If the API returns a server error response - */ + * Get all activity events for a participant. + * Get the set of all activity events produced by a given participant, by identifier. + * @param participantId + * @param origin (optional) + * @param from (optional) + * @param to (optional) + * @param transform (optional) + * @return kotlin.Array + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) - fun activityEventAllByParticipant(participantId: kotlin.String, origin: kotlin.String?, from: java.sql.Timestamp?, to: java.sql.Timestamp?, transform: kotlin.String?) : kotlin.Array { - val localVariableBody: kotlin.Any? = null - val localVariableQuery: MultiValueMap = mutableMapOf>() - .apply { - if (origin != null) { - put("origin", listOf(origin.toString())) - } - if (from != null) { - put("from", listOf(from.toString())) - } - if (to != null) { - put("to", listOf(to.toString())) - } - if (transform != null) { - put("transform", listOf(transform.toString())) - } + fun activityEventAllByParticipant(participantId: kotlin.String, origin: kotlin.String?, from: Long?, to: Long?, transform: kotlin.String?,basic: String) :Any { + try { + val localVariableBody: kotlin.Any? = null + val localVariableQuery: MultiValueMap = + mutableMapOf>() + .apply { + if (origin != null) { + put("origin", listOf(origin.toString())) + } + if (from != null) { + put("from", listOf(from.toString())) + } + if (to != null) { + put("to", listOf(to.toString())) + } + if (transform != null) { + put("transform", listOf(transform.toString())) + } + } + val localVariableHeaders: MutableMap = mutableMapOf() + localVariableHeaders.apply { + put("Authorization", basic) } - val localVariableHeaders: MutableMap = mutableMapOf() - val localVariableConfig = RequestConfig( - RequestMethod.GET, - "/participant/{participant_id}/activity_event".replace("{"+"participant_id"+"}", "$participantId"), - query = localVariableQuery, - headers = localVariableHeaders - ) - val localVarResponse = request>( - localVariableConfig, - localVariableBody - ) + val localVariableConfig = RequestConfig( + RequestMethod.GET, + "/participant/{participant_id}/activity_event".replace( + "{" + "participant_id" + "}", + "$participantId" + ), + query = localVariableQuery, + headers = localVariableHeaders + ) + val localVarResponse = request>( + localVariableConfig, + localVariableBody + ) - return when (localVarResponse.responseType) { - ResponseType.Success -> (localVarResponse as Success<*>).data as kotlin.Array - ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") - ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") - ResponseType.ClientError -> { - val localVarError = localVarResponse as ClientError<*> - throw ClientException("Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) - } - ResponseType.ServerError -> { - val localVarError = localVarResponse as ServerError<*> - throw ServerException("Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", localVarError.statusCode, localVarResponse) + return when (localVarResponse.responseType) { + ResponseType.Success -> (localVarResponse as Success<*>).data as Any + ResponseType.Informational -> throw UnsupportedOperationException("Client does not support Informational responses.") + ResponseType.Redirection -> throw UnsupportedOperationException("Client does not support Redirection responses.") + ResponseType.ClientError -> { + val localVarError = localVarResponse as ClientError<*> + throw ClientException( + "Client error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", + localVarError.statusCode, + localVarResponse + ) + } + + ResponseType.ServerError -> { + val localVarError = localVarResponse as ServerError<*> + throw ServerException( + "Server error : ${localVarError.statusCode} ${localVarError.message.orEmpty()}", + localVarError.statusCode, + localVarResponse + ) + } } + }catch (e:Exception){ + Log.e("activity api event","${e.message}") + return e } } /** - * Get all activity events for a researcher by participant. - * Get the set of all activity events produced by participants of any study conducted by a researcher, by researcher identifier. - * @param researcherId - * @param origin (optional) - * @param from (optional) - * @param to (optional) - * @param transform (optional) - * @return kotlin.Array - * @throws UnsupportedOperationException If the API returns an informational or redirection response - * @throws ClientException If the API returns a client error response - * @throws ServerException If the API returns a server error response - */ + * Get all activity events for a researcher by participant. + * Get the set of all activity events produced by participants of any study conducted by a researcher, by researcher identifier. + * @param researcherId + * @param origin (optional) + * @param from (optional) + * @param to (optional) + * @param transform (optional) + * @return kotlin.Array + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun activityEventAllByResearcher(researcherId: kotlin.String, origin: kotlin.String?, from: java.sql.Timestamp?, to: java.sql.Timestamp?, transform: kotlin.String?) : kotlin.Array { @@ -143,18 +173,18 @@ class ActivityEventAPI(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } /** - * Get all activity events for a study by participant. - * Get the set of all activity events produced by participants of a single study, by study identifier. - * @param studyId - * @param origin (optional) - * @param from (optional) - * @param to (optional) - * @param transform (optional) - * @return kotlin.Array - * @throws UnsupportedOperationException If the API returns an informational or redirection response - * @throws ClientException If the API returns a client error response - * @throws ServerException If the API returns a server error response - */ + * Get all activity events for a study by participant. + * Get the set of all activity events produced by participants of a single study, by study identifier. + * @param studyId + * @param origin (optional) + * @param from (optional) + * @param to (optional) + * @param transform (optional) + * @return kotlin.Array + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun activityEventAllByStudy(studyId: kotlin.String, origin: kotlin.String?, from: java.sql.Timestamp?, to: java.sql.Timestamp?, transform: kotlin.String?) : kotlin.Array { @@ -202,15 +232,15 @@ class ActivityEventAPI(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } /** - * Create a new ActivityEvent for the given Participant. - * Create a new ActivityEvent for the given Participant. - * @param participantId - * @param activityEvent - * @return kotlin.String - * @throws UnsupportedOperationException If the API returns an informational or redirection response - * @throws ClientException If the API returns a client error response - * @throws ServerException If the API returns a server error response - */ + * Create a new ActivityEvent for the given Participant. + * Create a new ActivityEvent for the given Participant. + * @param participantId + * @param activityEvent + * @return kotlin.String + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun activityEventCreate(participantId: kotlin.String, activityEvent: ActivityEvent) : kotlin.String { @@ -244,18 +274,18 @@ class ActivityEventAPI(basePath: kotlin.String = defaultBasePath) : ApiClient(ba } /** - * Delete a ActivityEvent. - * Delete a ActivityEvent. - * @param participantId - * @param origin (optional) - * @param from (optional) - * @param to (optional) - * @param transform (optional) - * @return kotlin.String - * @throws UnsupportedOperationException If the API returns an informational or redirection response - * @throws ClientException If the API returns a client error response - * @throws ServerException If the API returns a server error response - */ + * Delete a ActivityEvent. + * Delete a ActivityEvent. + * @param participantId + * @param origin (optional) + * @param from (optional) + * @param to (optional) + * @param transform (optional) + * @return kotlin.String + * @throws UnsupportedOperationException If the API returns an informational or redirection response + * @throws ClientException If the API returns a client error response + * @throws ServerException If the API returns a server error response + */ @Suppress("UNCHECKED_CAST") @Throws(UnsupportedOperationException::class, ClientException::class, ServerException::class) fun activityEventDelete(participantId: kotlin.String, origin: kotlin.String?, from: java.sql.Timestamp?, to: java.sql.Timestamp?, transform: kotlin.String?) : kotlin.String { diff --git a/lamp_kotlin/src/main/java/digital/lamp/lamp_kotlin/sensor_core/WiFi.kt b/lamp_kotlin/src/main/java/digital/lamp/lamp_kotlin/sensor_core/WiFi.kt index d7e010b..71c0ea9 100644 --- a/lamp_kotlin/src/main/java/digital/lamp/lamp_kotlin/sensor_core/WiFi.kt +++ b/lamp_kotlin/src/main/java/digital/lamp/lamp_kotlin/sensor_core/WiFi.kt @@ -35,7 +35,7 @@ class WiFi : Service() { wifiManager = this.applicationContext.getSystemService(WIFI_SERVICE) as WifiManager val filter = IntentFilter() filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) - registerReceiver(wifiMonitor, filter) + registerReceiver(wifiMonitor, filter, RECEIVER_EXPORTED) backgroundService = Intent(this, BackgroundService::class.java) backgroundService!!.action = ACTION_LAMP_WIFI_REQUEST_SCAN wifiScan = PendingIntent.getService( @@ -46,7 +46,7 @@ class WiFi : Service() { ) val bluetoothFilter = IntentFilter(BluetoothDevice.ACTION_FOUND) - registerReceiver(bluetoothMonitor, bluetoothFilter) + registerReceiver(bluetoothMonitor, bluetoothFilter, RECEIVER_EXPORTED) bluetoothBackgroundService = Intent(this, BluetoothBackgroundService::class.java) bluetoothBackgroundService!!.action = ACTION_LAMP_BLUETOOTH_REQUEST_SCAN bluetoothScan = PendingIntent.getService( @@ -78,30 +78,39 @@ class WiFi : Service() { if (frequency != null) { if (frequency!! >= LampConstants.FREQUENCY_WIFI) { - alarmManager?.cancel(wifiScan) - alarmManager?.setRepeating( - AlarmManager.RTC_WAKEUP, - System.currentTimeMillis(), - frequency!! * 1000, - wifiScan - ) + wifiScan?.let { + alarmManager?.cancel(it) + alarmManager?.setRepeating( + AlarmManager.RTC_WAKEUP, + System.currentTimeMillis(), + frequency!! * 1000, + it + ) + } + }else{ - alarmManager?.cancel(wifiScan) + wifiScan?.let { + alarmManager?.cancel(it) + alarmManager?.setRepeating( + AlarmManager.RTC_WAKEUP, + System.currentTimeMillis(), + (LampConstants.FREQUENCY_WIFI * 1000).toLong(), + it + ) + } + + } + } else { + wifiScan?.let { + alarmManager?.cancel(it) alarmManager?.setRepeating( AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), (LampConstants.FREQUENCY_WIFI * 1000).toLong(), - wifiScan + it ) } - } else { - alarmManager?.cancel(wifiScan) - alarmManager?.setRepeating( - AlarmManager.RTC_WAKEUP, - System.currentTimeMillis(), - (LampConstants.FREQUENCY_WIFI * 1000).toLong(), - wifiScan - ) + } @@ -118,31 +127,38 @@ class WiFi : Service() { val startTime = System.currentTimeMillis() if (frequency != null) { if (frequency!! >= LampConstants.FREQUENCY_WIFI) { - bluetoothAlarmManager?.cancel(bluetoothScan) - bluetoothAlarmManager?.setRepeating( - AlarmManager.RTC_WAKEUP, - startTime, - frequency!! * 1000, - bluetoothScan - ) + bluetoothScan?.let { bluetoothScan-> + bluetoothAlarmManager?.cancel(bluetoothScan) + bluetoothAlarmManager?.setRepeating( + AlarmManager.RTC_WAKEUP, + startTime, + frequency!! * 1000, + bluetoothScan + ) + } + }else { - bluetoothAlarmManager?.cancel(bluetoothScan) + bluetoothScan?.let { bluetoothScan-> + bluetoothAlarmManager?.cancel(bluetoothScan) + bluetoothAlarmManager?.setRepeating( + AlarmManager.RTC_WAKEUP, + startTime, + (LampConstants.FREQUENCY_WIFI * 1000).toLong(), + bluetoothScan + ) + } + } + + } else { + bluetoothScan?.let { + bluetoothAlarmManager?.cancel(it) bluetoothAlarmManager?.setRepeating( AlarmManager.RTC_WAKEUP, startTime, (LampConstants.FREQUENCY_WIFI * 1000).toLong(), - bluetoothScan + it ) } - - } else { - bluetoothAlarmManager?.cancel(bluetoothScan) - bluetoothAlarmManager?.setRepeating( - AlarmManager.RTC_WAKEUP, - startTime, - (LampConstants.FREQUENCY_WIFI * 1000).toLong(), - bluetoothScan - ) } @@ -152,8 +168,8 @@ class WiFi : Service() { super.onDestroy() unregisterReceiver(wifiMonitor) unregisterReceiver(bluetoothMonitor) - if (wifiScan != null) alarmManager!!.cancel(wifiScan) - if (bluetoothScan != null) bluetoothAlarmManager!!.cancel(bluetoothScan) + if (wifiScan != null) alarmManager!!.cancel(wifiScan!!) + if (bluetoothScan != null) bluetoothAlarmManager!!.cancel(bluetoothScan!!) if (Lamp.DEBUG) Log.d(TAG, "WiFi service terminated...") } @@ -189,7 +205,7 @@ class WiFi : Service() { override fun onCreate() { super.onCreate() val filter = IntentFilter(BluetoothDevice.ACTION_FOUND) - registerReceiver(bluetoothReceiver, filter) + registerReceiver(bluetoothReceiver, filter, RECEIVER_EXPORTED) } private val bluetoothReceiver = object : BroadcastReceiver() {