Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement job control for entries processed on the server (issue #750)
1. Implement support for users with permission to cancel a content entry import job that is running on the server (e.g. file upload from web, or entry being imported from a url) 2. Add display of content entry import progress on app-react/JS version
- Loading branch information
1 parent
186493b
commit 78c82ca
Showing
20 changed files
with
338 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
45 changes: 45 additions & 0 deletions
45
...tadmobile/core/domain/contententry/importcontent/CancelImportContentEntryServerUseCase.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,45 @@ | ||
package com.ustadmobile.core.domain.contententry.importcontent | ||
|
||
import com.ustadmobile.core.account.Endpoint | ||
import com.ustadmobile.core.db.UmAppDatabase | ||
import com.ustadmobile.core.domain.usersession.ValidateUserSessionOnServerUseCase | ||
import io.github.aakira.napier.Napier | ||
|
||
/** | ||
* Server side implementation to cancel a running import job on request from a client. This will | ||
* validate that the request comes from a node that has a valid session representing the owner of | ||
* the import job. | ||
*/ | ||
class CancelImportContentEntryServerUseCase( | ||
private val cancelImportContentEntryUseCase: CancelImportContentEntryUseCase, | ||
private val validateUserSessionOnServerUseCase: ValidateUserSessionOnServerUseCase, | ||
private val db: UmAppDatabase, | ||
private val endpoint: Endpoint, | ||
) { | ||
|
||
suspend operator fun invoke( | ||
cjiUid: Long, | ||
remoteNodeId: Long, | ||
nodeAuth: String, | ||
accountPersonUid: Long, | ||
) { | ||
Napier.d { "CancelImportContentEntryServerUseCase: validating session to cancel #$cjiUid"} | ||
validateUserSessionOnServerUseCase( | ||
nodeId = remoteNodeId, | ||
nodeAuth = nodeAuth, | ||
accountPersonUid = accountPersonUid, | ||
) | ||
|
||
Napier.d { "CancelImportContentEntryServerUseCase: validating owner to cancel #$cjiUid"} | ||
|
||
val ownerPersonUid = db.contentEntryImportJobDao.findOwnerByUidAsync(cjiUid) | ||
if(ownerPersonUid != accountPersonUid) | ||
throw IllegalArgumentException("$accountPersonUid is not owner of the job $cjiUid ($ownerPersonUid)") | ||
|
||
Napier.d { "CancelImportContentEntryServerUseCase: requesting cancellation of #$cjiUid "} | ||
|
||
cancelImportContentEntryUseCase(cjiUid) | ||
Napier.d { "CancelImportContentEntryServerUseCase: Canceled import #$cjiUid on ${endpoint.url}" } | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...tadmobile/core/domain/contententry/importcontent/CancelRemoteContentEntryImportUseCase.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,36 @@ | ||
package com.ustadmobile.core.domain.contententry.importcontent | ||
|
||
import com.ustadmobile.core.account.Endpoint | ||
import com.ustadmobile.core.db.UmAppDatabase | ||
import com.ustadmobile.door.DoorDatabaseRepository | ||
import com.ustadmobile.door.ext.doorNodeIdHeader | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.header | ||
import io.ktor.client.request.parameter | ||
|
||
/** | ||
* Cancels a content entry import where the import is running on the server | ||
*/ | ||
class CancelRemoteContentEntryImportUseCase( | ||
private val endpoint: Endpoint, | ||
private val httpClient: HttpClient, | ||
private val repo: UmAppDatabase, | ||
) { | ||
|
||
suspend operator fun invoke( | ||
cjiUid: Long, | ||
activeUserPersonUid: Long, | ||
) { | ||
val repoVal = repo as? DoorDatabaseRepository | ||
?: throw IllegalArgumentException() | ||
|
||
httpClient.get("${endpoint.url}api/contententryimportjob/cancel") { | ||
parameter("jobUid", cjiUid) | ||
doorNodeIdHeader(repoVal) | ||
parameter("accountPersonUid", activeUserPersonUid) | ||
header("cache-control", "no-store") | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.