Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Schuler-Gabriel committed Jun 4, 2024
1 parent 0e415e4 commit 8376a90
Show file tree
Hide file tree
Showing 112 changed files with 10,272 additions and 5,746 deletions.
22 changes: 13 additions & 9 deletions client/src/main/java/com/mytiki/publish/client/TikiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import android.content.Context
import android.graphics.Bitmap
import androidx.activity.ComponentActivity
import com.mytiki.publish.client.auth.AuthService
import com.mytiki.publish.client.capture.CaptureReceiptRsp
import com.mytiki.publish.client.capture.CaptureService
import com.mytiki.publish.client.capture.rsp.CaptureReceiptRsp
import com.mytiki.publish.client.config.Config
import com.mytiki.publish.client.email.Attachment
import com.mytiki.publish.client.email.EmailAttachment
import com.mytiki.publish.client.email.EmailKeys
import com.mytiki.publish.client.email.EmailProviderEnum
import com.mytiki.publish.client.email.EmailService
Expand Down Expand Up @@ -269,20 +269,24 @@ object TikiClient {
}

/**
* Publishes an array of attachments for receipt data extraction.
* Publishes an array of emailAttachments for receipt data extraction.
*
* This function publishes an array of attachments for receipt data extraction. The provided
* attachments are sent to the capture service for processing. The function is asynchronous and
* returns a CompletableDeferred object that will be completed when the data has been published.
* This function publishes an array of emailAttachments for receipt data extraction. The provided
* emailAttachments are sent to the capture service for processing. The function is asynchronous
* and returns a CompletableDeferred object that will be completed when the data has been
* published.
*
* @param context The Context instance. This is typically the current activity or application
* context from which this function is called. It is used to provide context for the publishing
* process.
* @param attachments The array of Attachment objects to be published.
* @param emailAttachments The array of EmailAttachment objects to be published.
* @return A CompletableDeferred object that will be completed when the data has been published.
*/
fun publish(context: Context, attachments: Array<Attachment>): CompletableDeferred<Unit> {
return capture.publish(context, attachments)
fun publish(
context: Context,
emailAttachments: Array<EmailAttachment>
): CompletableDeferred<Unit> {
return capture.publish(context, emailAttachments)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import android.content.Intent
import android.graphics.Bitmap
import androidx.activity.ComponentActivity
import com.mytiki.publish.client.TikiClient
import com.mytiki.publish.client.email.Attachment
import com.mytiki.publish.client.email.AttachmentType
import com.mytiki.publish.client.capture.rsp.CaptureReceiptRsp
import com.mytiki.publish.client.email.EmailAttachment
import com.mytiki.publish.client.email.EmailAttachmentType
import com.mytiki.publish.client.utils.apiService.ApiService
import java.util.*
import kotlinx.coroutines.*
Expand All @@ -32,72 +33,77 @@ class CaptureService {
}

/**
* Publishes an attachment based on its type.
* Publishes an emailAttachment based on its type.
*
* This function publishes an attachment. It offerUses the provided Context instance, a string pointer,
* and an Attachment object. The function calls the appropriate publish method based on the type
* of the attachment (IMAGE, PDF, TEXT).
* This function publishes an emailAttachment. It offerUses the provided Context instance, a
* string pointer, and an EmailAttachment object. The function calls the appropriate publish
* method based on the type of the emailAttachment (IMAGE, PDF, TEXT).
*
* @param context The Context instance. This is typically the current activity or application
* context from which this function is called. It is used to provide context for the publishing
* process.
* @param attachment The Attachment object containing the details of the attachment to be
* published.
* @return A CompletableDeferred object that will be completed when the attachment has been
* @param emailAttachment The EmailAttachment object containing the details of the emailAttachment
* to be published.
* @return A CompletableDeferred object that will be completed when the emailAttachment has been
* published.
*/
fun publish(context: Context, attachment: Attachment): CompletableDeferred<Unit> {
return when (attachment.type) {
AttachmentType.IMAGE -> publishImage(attachment)
AttachmentType.PDF -> publishPdf(context, attachment)
AttachmentType.TEXT -> publishText(attachment)
fun publish(context: Context, emailAttachment: EmailAttachment): CompletableDeferred<Unit> {
return when (emailAttachment.type) {
EmailAttachmentType.IMAGE -> publishImage(emailAttachment)
EmailAttachmentType.PDF -> publishPdf(context, emailAttachment)
EmailAttachmentType.TEXT -> publishText(emailAttachment)
}
}

/**
* Publishes an array of attachments.
*
* This function publishes an array of attachments. It offerUses the provided Context instance, a
* string pointer, and an array of Attachment objects. The function calls the publish method for
* each attachment in the array.
* string pointer, and an array of EmailAttachment objects. The function calls the publish method
* for each attachment in the array.
*
* @param context The Context instance. This is typically the current activity or application
* context from which this function is called. It is used to provide context for the publishing
* process.
* @param attachmentList The array of Attachment objects containing the details of the attachments
* to be published.
* @param emailAttachmentList The array of EmailAttachment objects containing the details of the
* attachments to be published.
* @return A CompletableDeferred object that will be completed when all the attachments have been
* published.
*/
fun publish(context: Context, attachmentList: Array<Attachment>): CompletableDeferred<Unit> {
fun publish(
context: Context,
emailAttachmentList: Array<EmailAttachment>
): CompletableDeferred<Unit> {
val isPublished = CompletableDeferred<Unit>()
MainScope().async {
attachmentList.forEachIndexed { index, attachment ->
emailAttachmentList.forEachIndexed { index, attachment ->
publish(context, attachment).await()
if (index == attachmentList.size - 1) isPublished.complete(Unit)
if (index == emailAttachmentList.size - 1) isPublished.complete(Unit)
}
}
return isPublished
}

/**
* Publishes an image attachment.
* Publishes an image emailAttachment.
*
* This function publishes an image attachment. It offerUses a string pointer and an Attachment object.
* The function calls the post method of the ApiService instance to publish the image.
* This function publishes an image emailAttachment. It offerUses a string pointer and an
* EmailAttachment object. The function calls the post method of the ApiService instance to
* publish the image.
*
* @param attachment The Attachment object containing the details of the image to be published.
* @param emailAttachment The EmailAttachment object containing the details of the image to be
* published.
* @return A CompletableDeferred object that will be completed when the image has been published.
* @throws Exception if there is an error during the publishing process.
*/
private fun publishImage(attachment: Attachment): CompletableDeferred<Unit> {
private fun publishImage(emailAttachment: EmailAttachment): CompletableDeferred<Unit> {
val isPublished = CompletableDeferred<Unit>()
CoroutineScope(Dispatchers.IO).launch {
if (!TikiClient.license.verify())
throw Exception(
"The License is invalid. OfferUse the TikiClient.license method to issue a new License.")
val auth = TikiClient.auth.addressToken().await()
val image = attachment.toImage()
val image = emailAttachment.toImage()
val id = UUID.randomUUID()
val body =
MultipartBody.Builder()
Expand All @@ -118,20 +124,24 @@ class CaptureService {
}

/**
* Publishes a PDF attachment.
* Publishes a PDF emailAttachment.
*
* This function publishes a PDF attachment. It offerUses the provided Context instance, a string
* pointer, and an Attachment object. The function calls the post method of the ApiService
* instance to publish the PDF.
* This function publishes a PDF emailAttachment. It offerUses the provided Context instance, a
* string pointer, and an EmailAttachment object. The function calls the post method of the
* ApiService instance to publish the PDF.
*
* @param context The Context instance. This is typically the current activity or application
* context from which this function is called. It is used to provide context for the publishing
* process.
* @param attachment The Attachment object containing the details of the PDF to be published.
* @param emailAttachment The EmailAttachment object containing the details of the PDF to be
* published.
* @return A CompletableDeferred object that will be completed when the PDF has been published.
* @throws Exception if there is an error during the publishing process.
*/
private fun publishPdf(context: Context, attachment: Attachment): CompletableDeferred<Unit> {
private fun publishPdf(
context: Context,
emailAttachment: EmailAttachment
): CompletableDeferred<Unit> {
val isPublished = CompletableDeferred<Unit>()
CoroutineScope(Dispatchers.IO).launch {
if (!TikiClient.license.verify())
Expand All @@ -140,7 +150,7 @@ class CaptureService {
val auth = TikiClient.auth.addressToken().await()

val id = UUID.randomUUID()
val pdf = attachment.toPdf(context)
val pdf = emailAttachment.toPdf(context)
val body =
MultipartBody.Builder()
.setType(MultipartBody.FORM)
Expand All @@ -162,16 +172,17 @@ class CaptureService {
}

/**
* Publishes a text attachment.
* Publishes a text emailAttachment.
*
* This function publishes a text attachment. It offerUses a string pointer and an Attachment object.
* The function completes the CompletableDeferred object immediately as there is no actual
* publishing process for text attachments.
* This function publishes a text emailAttachment. It offerUses a string pointer and an
* EmailAttachment object. The function completes the CompletableDeferred object immediately as
* there is no actual publishing process for text attachments.
*
* @param attachment The Attachment object containing the details of the text to be published.
* @param emailAttachment The EmailAttachment object containing the details of the text to be
* published.
* @return A CompletableDeferred object that will be completed immediately.
*/
private fun publishText(attachment: Attachment): CompletableDeferred<Unit> {
private fun publishText(emailAttachment: EmailAttachment): CompletableDeferred<Unit> {
val isPublished = CompletableDeferred<Unit>()
isPublished.complete(Unit)
return isPublished
Expand All @@ -184,8 +195,8 @@ class CaptureService {
*
* @param receiptId The unique identifier for the receipt obtained from the publish method.
* @param token The address token to connect with TIKI API.
* @param onResult A callback functions that revceives the array of CaptureReceiptRsp objects, each
* containing the structured data extracted from an image of the receipt, or null if the
* @param onResult A callback functions that revceives the array of CaptureReceiptRsp objects,
* each containing the structured data extracted from an image of the receipt, or null if the
* retrieval fails.
*/
suspend fun receipt(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.mytiki.publish.client.capture.rsp

data class BlockRsp(val confidence: Double, val text: String)
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.mytiki.publish.client.capture.rsp
import okhttp3.ResponseBody

data class CaptureReceiptRsp(
val documentMetadata: DocumentMetadata,
val expenseDocuments: Array<ExpenseDocument>
val documentMetadataRsp: DocumentMetadataRsp,
val expenseDocumentRsps: Array<ExpenseDocumentRsp>
) {
companion object {
fun from(response: ResponseBody): CaptureReceiptRsp {
val dummyDocumentMetadata = DocumentMetadata(0)
val dummyExpenseDocuments = arrayOf<ExpenseDocument>()
return CaptureReceiptRsp(dummyDocumentMetadata, dummyExpenseDocuments)
val dummyDocumentMetadataRsp = DocumentMetadataRsp(0)
val dummyExpenseDocumentRsps = arrayOf<ExpenseDocumentRsp>()
return CaptureReceiptRsp(dummyDocumentMetadataRsp, dummyExpenseDocumentRsps)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.mytiki.publish.client.capture.rsp

data class DocumentMetadata(val pages: Int)
data class DocumentMetadataRsp(val pages: Int)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mytiki.publish.client.capture.rsp

data class ExpenseDocumentRsp(
val blockRsps: Array<BlockRsp>,
val expenseIndex: Int,
val lineItemGroupRsps: Array<LineItemGroupRsp>,
val summaryFieldsRsp: Array<Map<String, SummaryFieldRsp>>
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mytiki.publish.client.capture.rsp

data class LineItemExpenseFieldRsp(
val productCode: SummaryFieldRsp?,
val item: SummaryFieldRsp?,
val price: SummaryFieldRsp?,
val expenseRow: SummaryFieldRsp?
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.mytiki.publish.client.capture.rsp

data class LineItemGroupRsp(val lineItemGroupIndex: Int, val lineItemRsps: Array<LineItemRsp>)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.mytiki.publish.client.capture.rsp

data class LineItemRsp(val lineItemExpenseFieldRsps: Array<LineItemExpenseFieldRsp>)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.mytiki.publish.client.capture.rsp

data class SummaryFieldRsp(val confidenceKey: Int, val confidenceValue: Int, val value: String)
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import com.mytiki.publish.client.TikiClient
import com.mytiki.publish.client.auth.AuthToken
import com.mytiki.publish.client.auth.AuthProviderEnum
import com.mytiki.publish.client.auth.AuthToken
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.util.*
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.async
import net.openid.appauth.AuthorizationResponse
Expand Down Expand Up @@ -65,7 +64,7 @@ class EmailActivity : AppCompatActivity() {
val emailResp =
TikiClient.email.repository.saveData(
this@EmailActivity,
IndexData(emailResponse.email, null, null, false))
EmailIndexData(emailResponse.email, null, null, false))
if (authResp && emailResp) {
TikiClient.email.loginCallback(authToken.username)
} else throw Exception("unable to save data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import java.io.File

class Attachment(val type: AttachmentType, val data: ByteArray) {
class EmailAttachment(val type: EmailAttachmentType, val data: ByteArray) {
fun toImage(): File {
val resp = BitmapFactory.decodeByteArray(data, 0, data.size)
val file = File.createTempFile("receipt", ".jpeg")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mytiki.publish.client.email

enum class AttachmentType {
enum class EmailAttachmentType {
PDF,
IMAGE,
TEXT,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package com.mytiki.publish.client.email

import java.time.LocalDateTime
import java.util.*
import org.json.JSONObject

class IndexData(
class EmailIndexData(
val email: String,
val lastDate: LocalDateTime?,
val historicDate: LocalDateTime?,
val downloadInProgress: Boolean
) {
companion object {
fun fromJson(data: String?, key: String): IndexData {
fun fromJson(data: String?, key: String): EmailIndexData {
val json = JSONObject(data)
return IndexData(
return EmailIndexData(
key,
try {
LocalDateTime.parse(json.getString("lastDate"))
Expand Down
Loading

0 comments on commit 8376a90

Please sign in to comment.