Skip to content

Commit

Permalink
Merge pull request #108 from boschglobal/feature-105
Browse files Browse the repository at this point in the history
Add possibility to test the update of generated VSS Models
  • Loading branch information
wba2hi authored Mar 25, 2024
2 parents aa7e9e1 + 79dbe87 commit 5edcd3b
Show file tree
Hide file tree
Showing 28 changed files with 821 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
import org.eclipse.kuksa.connectivity.databroker.request.UpdateRequest;
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeFetchRequest;
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeSubscribeRequest;
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeUpdateRequest;
import org.eclipse.kuksa.connectivity.databroker.response.VssNodeUpdateResponse;
import org.eclipse.kuksa.coroutine.CoroutineCallback;
import org.eclipse.kuksa.proto.v1.KuksaValV1.GetResponse;
import org.eclipse.kuksa.proto.v1.KuksaValV1.SetResponse;
import org.eclipse.kuksa.testapp.databroker.connection.DataBrokerConnectorFactory;
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo;
import org.eclipse.kuksa.testapp.databroker.connection.factory.DataBrokerConnectorFactory;
import org.eclipse.kuksa.testapp.databroker.connection.model.ConnectionInfo;
import org.eclipse.kuksa.vsscore.model.VssNode;

import java.util.HashSet;
Expand Down Expand Up @@ -124,6 +126,18 @@ public void update(
dataBrokerConnection.update(request, callback);
}

@Override
public <T extends VssNode> void update(
@NonNull VssNodeUpdateRequest<T> request,
@NonNull CoroutineCallback<VssNodeUpdateResponse> callback
) {
if (dataBrokerConnection == null) {
return;
}

dataBrokerConnection.update(request, callback );
}

@Override
public void subscribe(@NonNull SubscribeRequest request, @NonNull VssPathListener listener) {
if (dataBrokerConnection == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ import org.eclipse.kuksa.connectivity.databroker.request.SubscribeRequest
import org.eclipse.kuksa.connectivity.databroker.request.UpdateRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeFetchRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeSubscribeRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeUpdateRequest
import org.eclipse.kuksa.connectivity.databroker.response.VssNodeUpdateResponse
import org.eclipse.kuksa.coroutine.CoroutineCallback
import org.eclipse.kuksa.extension.entriesMetadata
import org.eclipse.kuksa.extension.firstValue
import org.eclipse.kuksa.extension.stringValue
import org.eclipse.kuksa.extension.valueType
import org.eclipse.kuksa.proto.v1.KuksaValV1
import org.eclipse.kuksa.proto.v1.KuksaValV1.GetResponse
Expand All @@ -48,16 +52,16 @@ import org.eclipse.kuksa.proto.v1.Types.Field
import org.eclipse.kuksa.testapp.databroker.DataBrokerEngine
import org.eclipse.kuksa.testapp.databroker.JavaDataBrokerEngine
import org.eclipse.kuksa.testapp.databroker.KotlinDataBrokerEngine
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.viewmodel.ConnectionViewModel
import org.eclipse.kuksa.testapp.databroker.connection.viewmodel.ConnectionViewModel.ConnectionViewState
import org.eclipse.kuksa.testapp.databroker.view.DataBrokerView
import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel
import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel.ConnectionViewState
import org.eclipse.kuksa.testapp.databroker.viewmodel.DataBrokerProperty
import org.eclipse.kuksa.testapp.databroker.viewmodel.OutputEntry
import org.eclipse.kuksa.testapp.databroker.viewmodel.OutputViewModel
import org.eclipse.kuksa.testapp.databroker.viewmodel.TopAppBarViewModel
import org.eclipse.kuksa.testapp.databroker.viewmodel.VSSPathsViewModel
import org.eclipse.kuksa.testapp.databroker.viewmodel.VssNodesViewModel
import org.eclipse.kuksa.testapp.databroker.vssnodes.viewmodel.VssNodesViewModel
import org.eclipse.kuksa.testapp.databroker.vsspaths.viewmodel.DataBrokerProperty
import org.eclipse.kuksa.testapp.databroker.vsspaths.viewmodel.VSSPathsViewModel
import org.eclipse.kuksa.testapp.extension.TAG
import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository
import org.eclipse.kuksa.testapp.ui.theme.KuksaAppAndroidTheme
Expand Down Expand Up @@ -167,6 +171,28 @@ class KuksaDataBrokerActivity : ComponentActivity() {
dataBrokerEngine.unsubscribe(request, vssNodeListener)
}

vssNodesViewModel.onUpdateSignal = { signal ->
val request = VssNodeUpdateRequest(signal)
dataBrokerEngine.update(
request,
object : CoroutineCallback<VssNodeUpdateResponse>() {
override fun onSuccess(result: VssNodeUpdateResponse?) {
val errorsList = result?.flatMap { it.errorsList }
errorsList?.forEach {
outputViewModel.addOutputEntry(it.toString())
return
}

outputViewModel.addOutputEntry(result.toString())
}

override fun onError(error: Throwable) {
outputViewModel.addOutputEntry("Connection to data broker failed: ${error.message}")
}
},
)
}

vssNodesViewModel.onGetNode = { vssNode ->
fetchVssNode(vssNode)
}
Expand Down Expand Up @@ -277,21 +303,29 @@ class KuksaDataBrokerActivity : ComponentActivity() {
request,
object : CoroutineCallback<GetResponse>() {
override fun onSuccess(result: GetResponse?) {
val errorsList = result?.errorsList
if (result == null) return

val errorsList = result.errorsList
errorsList?.forEach {
outputViewModel.addOutputEntry(it.toString())

return
}

val outputEntry = OutputEntry()
result?.entriesList?.withIndex()?.forEach {
result.entriesList?.withIndex()?.forEach {
val dataEntry = it.value
val text = dataEntry.toString().substringAfter("\n")

outputEntry.addMessage(text)
}

outputViewModel.addOutputEntry(outputEntry)

val updatedValue = result.firstValue?.stringValue ?: ""
val dataBrokerProperty = vssPathsViewModel.dataBrokerProperty
.copy(value = updatedValue)
vssPathsViewModel.updateDataBrokerProperty(dataBrokerProperty)
}

override fun onError(error: Throwable) {
Expand Down Expand Up @@ -333,6 +367,11 @@ class KuksaDataBrokerActivity : ComponentActivity() {
object : CoroutineCallback<VssNode>() {
override fun onSuccess(result: VssNode?) {
Log.d(TAG, "Fetched node: $result")

if (result == null) return

vssNodesViewModel.updateNode(result)

outputViewModel.addOutputEntry("Fetched node: $result")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import org.eclipse.kuksa.connectivity.databroker.request.SubscribeRequest
import org.eclipse.kuksa.connectivity.databroker.request.UpdateRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeFetchRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeSubscribeRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeUpdateRequest
import org.eclipse.kuksa.connectivity.databroker.response.VssNodeUpdateResponse
import org.eclipse.kuksa.coroutine.CoroutineCallback
import org.eclipse.kuksa.proto.v1.KuksaValV1.GetResponse
import org.eclipse.kuksa.proto.v1.KuksaValV1.SetResponse
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.model.ConnectionInfo
import org.eclipse.kuksa.vsscore.model.VssNode

@Suppress("complexity:TooManyFunctions") // required to test the api
Expand All @@ -57,15 +59,20 @@ interface DataBrokerEngine {
callback: CoroutineCallback<SetResponse>,
)

fun subscribe(request: SubscribeRequest, listener: VssPathListener)
fun <T : VssNode> update(
request: VssNodeUpdateRequest<T>,
callback: CoroutineCallback<VssNodeUpdateResponse>,
)

fun unsubscribe(request: SubscribeRequest, listener: VssPathListener)
fun subscribe(request: SubscribeRequest, listener: VssPathListener)

fun <T : VssNode> subscribe(
request: VssNodeSubscribeRequest<T>,
vssNodeListener: VssNodeListener<T>,
)

fun unsubscribe(request: SubscribeRequest, listener: VssPathListener)

fun <T : VssNode> unsubscribe(
request: VssNodeSubscribeRequest<T>,
vssNodeListener: VssNodeListener<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ import org.eclipse.kuksa.connectivity.databroker.request.SubscribeRequest
import org.eclipse.kuksa.connectivity.databroker.request.UpdateRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeFetchRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeSubscribeRequest
import org.eclipse.kuksa.connectivity.databroker.request.VssNodeUpdateRequest
import org.eclipse.kuksa.connectivity.databroker.response.VssNodeUpdateResponse
import org.eclipse.kuksa.coroutine.CoroutineCallback
import org.eclipse.kuksa.proto.v1.KuksaValV1.GetResponse
import org.eclipse.kuksa.proto.v1.KuksaValV1.SetResponse
import org.eclipse.kuksa.testapp.databroker.connection.DataBrokerConnectorFactory
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.factory.DataBrokerConnectorFactory
import org.eclipse.kuksa.testapp.databroker.connection.model.ConnectionInfo
import org.eclipse.kuksa.vsscore.model.VssNode

@Suppress("complexity:TooManyFunctions")
Expand Down Expand Up @@ -110,6 +112,20 @@ class KotlinDataBrokerEngine(
}
}

override fun <T : VssNode> update(
request: VssNodeUpdateRequest<T>,
callback: CoroutineCallback<VssNodeUpdateResponse>,
) {
lifecycleScope.launch {
try {
val response = dataBrokerConnection?.update(request) ?: return@launch
callback.onSuccess(response)
} catch (e: DataBrokerException) {
callback.onError(e)
}
}
}

override fun subscribe(request: SubscribeRequest, listener: VssPathListener) {
dataBrokerConnection?.subscribe(request, listener)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,10 +14,9 @@
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.testapp.databroker.connection
package org.eclipse.kuksa.testapp.databroker.connection.factory

import android.content.Context
import android.net.Uri
Expand All @@ -29,7 +28,7 @@ import io.grpc.TlsChannelCredentials
import org.eclipse.kuksa.connectivity.authentication.JsonWebToken
import org.eclipse.kuksa.connectivity.databroker.DataBrokerConnector
import org.eclipse.kuksa.model.TimeoutConfig
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.model.ConnectionInfo
import org.eclipse.kuksa.testapp.extension.readAsText
import java.io.IOException
import java.util.concurrent.TimeUnit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.testapp.databroker.model
package org.eclipse.kuksa.testapp.databroker.connection.model

import android.net.Uri
import androidx.compose.runtime.Immutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.testapp.databroker.model
package org.eclipse.kuksa.testapp.databroker.connection.model

import androidx.compose.runtime.Immutable
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,10 +14,9 @@
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.testapp.databroker.view.connection
package org.eclipse.kuksa.testapp.databroker.connection.view.connection

import android.net.Uri
import androidx.compose.foundation.clickable
Expand All @@ -33,7 +32,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.view.DefaultEdgePadding
import org.eclipse.kuksa.testapp.databroker.view.FileSelectorSettingView
import org.eclipse.kuksa.testapp.extension.fetchFileName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,10 +14,9 @@
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.testapp.databroker.view.connection
package org.eclipse.kuksa.testapp.databroker.connection.view.connection

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
Expand All @@ -40,7 +39,6 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
Expand All @@ -49,19 +47,18 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.viewmodel.ConnectionViewModel
import org.eclipse.kuksa.testapp.databroker.connection.viewmodel.ConnectionViewModel.ConnectionViewState
import org.eclipse.kuksa.testapp.databroker.view.DefaultEdgePadding
import org.eclipse.kuksa.testapp.databroker.view.DefaultElementPadding
import org.eclipse.kuksa.testapp.databroker.view.MinimumButtonWidth
import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel
import org.eclipse.kuksa.testapp.databroker.viewmodel.ConnectionViewModel.ConnectionViewState
import org.eclipse.kuksa.testapp.extension.compose.Headline
import org.eclipse.kuksa.testapp.extension.compose.RememberCountdown
import org.eclipse.kuksa.testapp.preferences.ConnectionInfoRepository

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun DataBrokerConnectionView(viewModel: ConnectionViewModel) {
fun ConnectionView(viewModel: ConnectionViewModel) {
val keyboardController = LocalSoftwareKeyboardController.current

val repositoryConnectionInfoState =
Expand Down Expand Up @@ -224,7 +221,7 @@ private fun ConnectedPreview() {
val connectionInfoRepository = ConnectionInfoRepository(LocalContext.current)
val viewModel = ConnectionViewModel(connectionInfoRepository)
Surface {
DataBrokerConnectionView(viewModel = viewModel)
ConnectionView(viewModel = viewModel)
}
}

Expand All @@ -235,6 +232,6 @@ private fun DisconnectedPreview() {
val viewModel = ConnectionViewModel(connectionInfoRepository)
viewModel.updateConnectionState(ConnectionViewState.CONNECTING)
Surface {
DataBrokerConnectionView(viewModel = viewModel)
ConnectionView(viewModel = viewModel)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Contributors to the Eclipse Foundation
* Copyright (c) 2023 Contributors to the Eclipse Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,10 +14,9 @@
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*
*/

package org.eclipse.kuksa.testapp.databroker.view.connection
package org.eclipse.kuksa.testapp.databroker.connection.view.connection

import android.net.Uri
import androidx.compose.foundation.clickable
Expand All @@ -37,7 +36,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import org.eclipse.kuksa.testapp.databroker.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.connection.model.ConnectionInfo
import org.eclipse.kuksa.testapp.databroker.view.DefaultEdgePadding
import org.eclipse.kuksa.testapp.databroker.view.DefaultElementPadding
import org.eclipse.kuksa.testapp.databroker.view.FileSelectorSettingView
Expand Down
Loading

0 comments on commit 5edcd3b

Please sign in to comment.