Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package com.linkedplanet.kotlininsightclient.sdk
import arrow.core.Either
import arrow.core.raise.either
import com.linkedplanet.kotlininsightclient.api.error.InsightClientError
import com.linkedplanet.kotlininsightclient.api.error.OtherNotFoundError
import com.linkedplanet.kotlininsightclient.api.interfaces.InsightAttachmentOperator
import com.linkedplanet.kotlininsightclient.api.model.AttachmentId
import com.linkedplanet.kotlininsightclient.api.model.InsightAttachment
Expand Down Expand Up @@ -66,7 +67,7 @@ object SdkInsightAttachmentOperator : InsightAttachmentOperator {
val attachmentId = attachmentUrlResolver.parseAttachmentIdFromPathInformation(url)
val attachmentBean = objectFacade.loadAttachmentBeanById(attachmentId)
fileManager.getObjectAttachmentContent(attachmentBean.objectId, attachmentBean.nameInFileSystem)
}
}.mapLeft { OtherNotFoundError("Attachment download failed for url:$url") }

override suspend fun downloadAttachmentZip(objectId: InsightObjectId): Either<InsightClientError, InputStream> =
either {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class ReverseEngineeredAttachmentUrlResolver {

private val applicationProperties: ApplicationProperties by getComponent()

private val pattern = Pattern.compile(".*/(\\d+)/?")
private val pattern = Pattern.compile(".*/(\\d+)(/[^/]*)?$")
private val INSIGHT_REST_BASE_URL = "/rest/insight/1.0"

private fun baseUrl(): String = applicationProperties.jiraBaseUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface InsightAttachmentOperatorTest {
assertThat(firstAttachment.created, endsWith(":06:08.208Z")) // 7 works fine locally and should be correct,
assertThat(firstAttachment.created, startsWith("2023-02-21T0")) // but github pipeline insists on 8 o'clock

val downloadContent = insightAttachmentOperator.downloadAttachment(attachments.first().url).orNull()!!
val downloadContent = insightAttachmentOperator.downloadAttachment(attachments.first().url).getOrNull()!!
val sha256HashIS = calculateSha256(downloadContent.readBytes())
assertThat(sha256HashIS, equalTo("fd411837a51c43670e8d7367e64f72dbbcda5016f59988547c12d067505ef75b"))
}
Expand All @@ -67,34 +67,39 @@ interface InsightAttachmentOperatorTest {

@Test
fun attachmentTestAttachmentCRUD() = runBlocking {
insightObjectOperator.makeSureObjectWithNameDoesNotExist(Country.id, "Attachistan")
try {
val disclaimer = "created by Test and should only exist during test run. Deutsches ß und ä."
val country = insightObjectOperator.createObject(
Country.id,
CountryName.attributeId toValue "Attachistan",
CountryShortName.attributeId toValue disclaimer,
toDomain = ::identity
).orFail()

val attachment = insightAttachmentOperator.uploadAttachment(
country.id, "attachistan.txt", "content".byteInputStream()
).orFail()

assertThat(attachment.filename, equalTo("attachistan.txt"))

val downloadContent = insightAttachmentOperator.downloadAttachment(attachment.url).orFail()
val downloadContentString = String(downloadContent.readBytes())
assertThat(downloadContentString, equalTo("content"))

insightAttachmentOperator.deleteAttachment(attachment.id).orFail()
assertThat(insightAttachmentOperator.downloadAttachment(attachment.url).isLeft(), equalTo(true))
} finally {
insightObjectOperator.makeSureObjectWithNameDoesNotExist(Country.id, "Attachistan")
mapOf(
"AttachmentWithSimpleName" to "simple.txt",
"AttachmentWithNumber" to "01231515_a_1241.txt",
"AttachmentWithImg" to "cover-L.jpg",
).forEach { (attachmentName, fileName) ->
insightObjectOperator.makeSureObjectWithNameDoesNotExist(Country.id, attachmentName)
try {
val disclaimer = "created by Test and should only exist during test run. Deutsches ß und ä."
val country = insightObjectOperator.createObject(
Country.id,
CountryName.attributeId toValue attachmentName,
CountryShortName.attributeId toValue disclaimer,
toDomain = ::identity
).orFail()

val attachment = insightAttachmentOperator.uploadAttachment(
country.id, fileName, "content".byteInputStream()
).orFail()

assertThat(attachment.filename, equalTo(fileName))

val downloadContent = insightAttachmentOperator.downloadAttachment(attachment.url).orFail()
val downloadContentString = String(downloadContent.readBytes())
assertThat(downloadContentString, equalTo("content"))

insightAttachmentOperator.deleteAttachment(attachment.id).orFail()
assertThat(insightAttachmentOperator.downloadAttachment(attachment.url).isLeft(), equalTo(true))
} finally {
insightObjectOperator.makeSureObjectWithNameDoesNotExist(Country.id, attachmentName)
}
}
}


@Test
fun attachmentTestGetAttachmentsForNotExistingObject() = runBlocking {
val responseError = insightAttachmentOperator.getAttachments(InsightObjectId.notPersistedObjectId).asError()
Expand Down
Loading