Skip to content

Commit

Permalink
Merge pull request #33 from niscy-eudiw/main
Browse files Browse the repository at this point in the history
Minor refactor for Session Data, Updated to latest RQES Core
  • Loading branch information
stzouvaras authored Dec 2, 2024
2 parents 41bbf22 + 32a58ea commit 1afffcb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
eudiRqesCore = "0.0.4-SNAPSHOT"
eudiRqesCore = "0.1.0"
agp = "8.7.2"
kotlin = "2.0.21"
kotlinxCoroutines = "1.8.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ internal class RqesControllerImpl(

override fun getSelectedFile(): EudiRqesGetSelectedFilePartialState {
return runCatching {
val selectedFile = eudiRQESUi.getCurrentSelection().file
val selectedFile = eudiRQESUi.getSessionData().file
selectedFile?.let { safeSelectedFile ->
EudiRqesGetSelectedFilePartialState.Success(file = safeSelectedFile)
} ?: EudiRqesGetSelectedFilePartialState.Failure(
Expand Down Expand Up @@ -117,8 +117,8 @@ internal class RqesControllerImpl(
override fun setSelectedQtsp(qtspData: QtspData): EudiRqesSetSelectedQtspPartialState {
return runCatching {

eudiRQESUi.setCurrentSelection(
eudiRQESUi.getCurrentSelection().copy(
eudiRQESUi.setSessionData(
eudiRQESUi.getSessionData().copy(
qtsp = qtspData
)
)
Expand All @@ -143,7 +143,7 @@ internal class RqesControllerImpl(

override fun getSelectedQtsp(): EudiRqesGetSelectedQtspPartialState {
return runCatching {
val selectedQtsp = eudiRQESUi.getCurrentSelection().qtsp
val selectedQtsp = eudiRQESUi.getSessionData().qtsp
selectedQtsp?.let { safeSelectedQtsp ->
EudiRqesGetSelectedQtspPartialState.Success(qtsp = safeSelectedQtsp)
} ?: EudiRqesGetSelectedQtspPartialState.Failure(
Expand Down Expand Up @@ -182,7 +182,7 @@ internal class RqesControllerImpl(
runCatching {
safeLet(
eudiRQESUi.getRqesService(),
eudiRQESUi.getCurrentSelection().authorizationCode
eudiRQESUi.getSessionData().authorizationCode
) { safeService, safeAuthorizationCode ->
val authorizedService = safeService.authorizeService(
authorizationCode = AuthorizationCode(safeAuthorizationCode)
Expand Down Expand Up @@ -250,7 +250,7 @@ internal class RqesControllerImpl(
): EudiRqesGetCredentialAuthorizationUrlPartialState {
return withContext(Dispatchers.IO) {
runCatching {
eudiRQESUi.getCurrentSelection().file?.let { safeSelectedFile ->
eudiRQESUi.getSessionData().file?.let { safeSelectedFile ->

val fileToBeSigned = uriToFile(
context = resourceProvider.provideContext(),
Expand Down Expand Up @@ -296,7 +296,7 @@ internal class RqesControllerImpl(
runCatching {
safeLet(
getAuthorizedService(),
eudiRQESUi.getCurrentSelection().authorizationCode
eudiRQESUi.getSessionData().authorizationCode
) { safeAuthorizedService, safeAuthorizationCode ->
val authorizedCredential: RQESService.CredentialAuthorized =
safeAuthorizedService.authorizeCredential(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object EudiRQESUi {
"Before calling resume, SDK must be initialized firstly. Call EudiRQESUi.launchSDK()"

private lateinit var _eudiRQESUiConfig: EudiRQESUiConfig
private lateinit var currentSelection: CurrentSelection
private lateinit var sessionData: SessionData

private var state: State = State.None
private var rqesService: RQESService? = null
Expand Down Expand Up @@ -79,7 +79,7 @@ object EudiRQESUi {
uri = documentUri
)

currentSelection = CurrentSelection(
sessionData = SessionData(
file = documentData,
qtsp = null,
authorizationCode = null,
Expand Down Expand Up @@ -122,12 +122,12 @@ object EudiRQESUi {
context: Context,
authorizationCode: String
) {
if (!::currentSelection.isInitialized) {
if (!::sessionData.isInitialized) {
throw EudiRQESUiError(
message = SDK_NOT_INITIALIZED_MESSAGE
)
}
currentSelection = currentSelection.copy(
sessionData = sessionData.copy(
authorizationCode = authorizationCode
)
setState(calculateNextState())
Expand Down Expand Up @@ -167,12 +167,12 @@ object EudiRQESUi {
return authorizedService
}

internal fun setCurrentSelection(currentSelection: CurrentSelection) {
this.currentSelection = currentSelection
internal fun setSessionData(sessionData: SessionData) {
this.sessionData = sessionData
}

internal fun getCurrentSelection(): CurrentSelection {
return currentSelection
internal fun getSessionData(): SessionData {
return sessionData
}

/**
Expand Down Expand Up @@ -210,7 +210,7 @@ object EudiRQESUi {
* @throws EudiRQESUiError If the SDK is not initialized (no file selected).
*/
private fun calculateNextState(): State {
currentSelection.file?.let { safeFile ->
sessionData.file?.let { safeFile ->
return when (getState()) {
is State.None -> {
State.Initial(
Expand Down Expand Up @@ -257,7 +257,7 @@ object EudiRQESUi {
data object Success : State()
}

internal data class CurrentSelection(
internal data class SessionData(
val file: DocumentData?,
val qtsp: QtspData?,
val authorizationCode: String?,
Expand Down
Loading

0 comments on commit 1afffcb

Please sign in to comment.