Skip to content

Commit

Permalink
updated syncing architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Apr 6, 2024
1 parent 80cb745 commit 6220be3
Show file tree
Hide file tree
Showing 21 changed files with 328 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data class ActionUploadFiles(
}
}
}

else -> {}
}
withContext(Dispatchers.IO) {
Expand All @@ -48,6 +49,7 @@ data class ActionUploadFiles(
it,
getParentId(entry),
uploadServerType = entry.uploadServer,
observerId = entry.observerID,
)
}
repository.setTotalTransferSize(result.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data class ActionUploadMedia(
}
}
}

else -> {}
}
withContext(Dispatchers.IO) {
Expand All @@ -45,6 +46,7 @@ data class ActionUploadMedia(
it,
getParentId(entry),
uploadServerType = entry.uploadServer,
observerId = entry.observerID,
)
}
repository.setTotalTransferSize(result.size)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alfresco.content.common

import com.alfresco.content.data.ParentEntry
import com.alfresco.content.data.payloads.FieldsData

/**
* Mark as EntryListener interface
Expand All @@ -18,4 +19,5 @@ interface EntryListener {
fun onProcessStart(entries: List<ParentEntry>) {}

fun onAttachFolder(entry: ParentEntry) {}
fun onAttachFiles(field: FieldsData) {}
}
7 changes: 6 additions & 1 deletion data/objectbox-models/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"entities": [
{
"id": "1:3882697123829827748",
"lastPropertyId": "32:675229831295035009",
"lastPropertyId": "33:8784310188115192790",
"name": "Entry",
"properties": [
{
Expand Down Expand Up @@ -153,6 +153,11 @@
"id": "32:675229831295035009",
"name": "canDelete",
"type": 1
},
{
"id": "33:8784310188115192790",
"name": "observerID",
"type": 9
}
],
"relations": []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package com.alfresco.content.data

import com.alfresco.content.data.payloads.FieldsData

data class AttachFolderSearchData(val entry: Entry? = null)
data class AttachFilesData(val field: FieldsData? = null)
9 changes: 6 additions & 3 deletions data/src/main/kotlin/com/alfresco/content/data/Entry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ data class Entry(
val uploadServer: UploadServerType = UploadServerType.DEFAULT,
val isReadOnly: Boolean = false,
var isSelectedForMultiSelection: Boolean = false,
var observerID: String = "",
) : ParentEntry(), Parcelable {

val isSynced: Boolean
Expand Down Expand Up @@ -146,6 +147,7 @@ data class Entry(
isFavorite = other.isFavorite,
canDelete = other.canDelete,
otherId = other.otherId,
observerID = other.observerID,
)

enum class Type {
Expand Down Expand Up @@ -395,7 +397,7 @@ data class Entry(
/**
* return the ContentEntry obj after converting the data from ContentDataEntry obj
*/
fun with(data: ContentDataEntry, parentId: String? = null, uploadServer: UploadServerType): Entry {
fun with(data: ContentDataEntry, parentId: String? = null, uploadServer: UploadServerType, observerID: String = ""): Entry {
return Entry(
id = data.id?.toString() ?: "",
parentId = parentId,
Expand All @@ -412,6 +414,7 @@ data class Entry(
previewStatus = data.previewStatus,
thumbnailStatus = data.thumbnailStatus,
uploadServer = uploadServer,
observerID = observerID,
)
}

Expand All @@ -432,8 +435,8 @@ data class Entry(
/**
* return the default Workflow content entry obj
*/
fun defaultWorkflowEntry(id: String?): Entry {
return Entry(uploadServer = UploadServerType.UPLOAD_TO_PROCESS, parentId = id)
fun defaultWorkflowEntry(id: String?, fieldId: String = ""): Entry {
return Entry(uploadServer = UploadServerType.UPLOAD_TO_PROCESS, parentId = id, observerID = fieldId)
}

fun withSelectedEntries(entries: List<Entry>): Entry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class OfflineRepository(otherSession: Session? = null) {
parentId: String,
isExtension: Boolean = false,
uploadServerType: UploadServerType = UploadServerType.DEFAULT,
observerId: String? = null,
) {
val resolver = context.contentResolver
var name: String? = null
Expand All @@ -217,9 +218,12 @@ class OfflineRepository(otherSession: Session? = null) {
offlineStatus = OfflineStatus.PENDING,
isExtension = isExtension,
uploadServer = uploadServerType,
observerID = observerId ?: "",
)

clearData()
if (observerId == null) {
clearData()
}

update(entry)

Expand Down Expand Up @@ -275,6 +279,17 @@ class OfflineRepository(otherSession: Session? = null) {
.build()
.find()

fun fetchProcessEntries(parentId: String, observerId: String): MutableList<Entry> {
val query = box.query()
.equal(Entry_.parentId, parentId, StringOrder.CASE_SENSITIVE)
.equal(Entry_.observerID, observerId, StringOrder.CASE_SENSITIVE)
.equal(Entry_.uploadServer, UploadServerType.UPLOAD_TO_PROCESS.value(), StringOrder.CASE_SENSITIVE)
.order(Entry_.name)
.build()
val list = query.find()
return list
}

/**
* returns the list of uploads which is being uploaded on the server.
*/
Expand All @@ -291,6 +306,22 @@ class OfflineRepository(otherSession: Session? = null) {
awaitClose { subscription.cancel() }
}

/**
* returns the list of uploads which is being uploaded on the server.
*/
fun observeProcessUploads(parentId: String, uploadServerType: UploadServerType = UploadServerType.DEFAULT): Flow<List<Entry>> = callbackFlow {
val query = box.query()
.equal(Entry_.parentId, parentId, StringOrder.CASE_SENSITIVE)
.equal(Entry_.isUpload, true)
.equal(Entry_.uploadServer, uploadServerType.value(), StringOrder.CASE_SENSITIVE)
.order(Entry_.name)
.build()
val subscription = query.subscribe().observer {
trySendBlocking(it)
}
awaitClose { subscription.cancel() }
}

/**
* observer for transfer uploads
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class TaskRepository {
),
local.parentId,
uploadServer = uploadServerType,
observerID = local.observerID,
)

else -> Entry()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.alfresco.content.data.payloads

import android.os.Parcelable
import com.alfresco.content.data.ProcessEntry
import kotlinx.parcelize.Parcelize

@Parcelize
data class UploadData(
val field: FieldsData = FieldsData(),
val process: ProcessEntry = ProcessEntry(),
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.alfresco.content.process.ui.theme.AlfrescoError
fun AttachFilesField(
contents: List<Entry> = emptyList(),
fieldsData: FieldsData = FieldsData(),
onUserTap: (Boolean) -> Unit = { },
navController: NavController,
errorData: Pair<Boolean, String> = Pair(false, ""),
) {
Expand Down Expand Up @@ -70,9 +71,7 @@ fun AttachFilesField(
)

IconButton(onClick = {
navController.navigate(
R.id.action_nav_process_form_to_nav_attach_files,
)
onUserTap(true)
}) {
Icon(
imageVector = Icons.Default.Attachment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import androidx.compose.ui.res.stringResource
import com.airbnb.mvrx.compose.collectAsState
import com.alfresco.content.component.ComponentBuilder
import com.alfresco.content.component.ComponentData
import com.alfresco.content.data.Entry
import com.alfresco.content.data.OptionsModel
import com.alfresco.content.data.payloads.FieldType
import com.alfresco.content.process.R
import com.alfresco.content.process.ui.fragments.FormViewModel
import com.alfresco.content.process.ui.fragments.ProcessFragment
Expand All @@ -33,7 +35,15 @@ fun FloatingActionButton(outcomes: List<OptionsModel>, fragment: ProcessFragment
)
ComponentBuilder(context, componentData)
.onApply { name, query, _ ->
val entry = state.listContents.find { it.isUpload }
val list = state.formFields.filter { it.type == FieldType.UPLOAD.value() }
.map { it.value as? List<*> ?: emptyList<Entry>() }.flatten()

val uploadList = state.formFields.filter { it.type == FieldType.UPLOAD.value() }

val entry = uploadList.flatMap { fieldsData ->
(fieldsData.value as? List<*>)?.mapNotNull { it as? Entry } ?: emptyList()
}.find { !it.isUpload }

if (entry != null) {
viewModel.optionsModel = OptionsModel(id = query, name = name)
fragment.confirmContentQueuePrompt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.airbnb.mvrx.compose.collectAsState
import com.alfresco.content.data.Entry
import com.alfresco.content.data.OptionsModel
import com.alfresco.content.data.payloads.FieldType
import com.alfresco.content.process.ui.fragments.FormViewModel
import com.alfresco.content.process.ui.fragments.ProcessFragment

Expand All @@ -25,7 +27,12 @@ fun Outcomes(outcomes: List<OptionsModel>, viewModel: FormViewModel, fragment: P
.fillMaxWidth()
.padding(horizontal = 12.dp, vertical = 4.dp),
onClick = {
val entry = state.listContents.find { it.isUpload }
val uploadList = state.formFields.filter { it.type == FieldType.UPLOAD.value() }

val entry = uploadList.flatMap { fieldsData ->
(fieldsData.value as? List<*>)?.mapNotNull { it as? Entry } ?: emptyList()
}.find { !it.isUpload }

if (entry != null) {
viewModel.optionsModel = it
fragment.confirmContentQueuePrompt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.alfresco.content.process.ui.composeviews

import android.os.Bundle
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -8,10 +9,13 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavController
import com.airbnb.mvrx.Mavericks
import com.alfresco.content.data.Entry
import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.UserGroupDetails
import com.alfresco.content.data.payloads.FieldType
import com.alfresco.content.data.payloads.FieldsData
import com.alfresco.content.data.payloads.UploadData
import com.alfresco.content.process.R
import com.alfresco.content.process.ui.components.AmountInputField
import com.alfresco.content.process.ui.components.AttachFilesField
Expand Down Expand Up @@ -188,10 +192,31 @@ fun FormScrollContent(field: FieldsData, viewModel: FormViewModel, state: FormVi
}

FieldType.UPLOAD.value() -> {
val listContents = (field.value as? List<*>)?.mapNotNull { it as? Entry } ?: emptyList()

AttachFilesField(
contents = state.listContents,
contents = listContents,
fieldsData = field,
navController = navController,
onUserTap = {
if (it) {
viewModel.selectedField = field

val bundle = Bundle().apply {
putParcelable(
Mavericks.KEY_ARG,
UploadData(
field = field,
process = state.parent,
),
)
}
navController.navigate(
R.id.action_nav_process_form_to_nav_attach_files,
bundle,
)
}
},
)
}

Expand Down
Loading

0 comments on commit 6220be3

Please sign in to comment.