-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pivotal #ID 176479720: Mongo Metadata Query (#328)
* added project and basic submission query support
- Loading branch information
Showing
11 changed files
with
261 additions
and
55 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
commons/commons-test/src/main/kotlin/ebi/ac/uk/db/Versions.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,4 @@ | ||
package ebi.ac.uk.db | ||
|
||
const val MONGO_VERSION = "mongo:4.0.10" | ||
const val MYSQL_VERSION = "mysql:5.7.33" |
File renamed without changes.
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
36 changes: 36 additions & 0 deletions
36
...sistence-mongo/src/main/kotlin/ac/uk/ebi/biostd/persistence/doc/model/SubmissionDocExt.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 ac.uk.ebi.biostd.persistence.doc.model | ||
|
||
import ac.uk.ebi.biostd.persistence.common.model.BasicSubmission | ||
import ebi.ac.uk.model.SubmissionMethod | ||
import ebi.ac.uk.model.constants.ProcessingStatus | ||
import java.time.ZoneOffset | ||
|
||
fun DocSubmission.asBasicSubmission(): BasicSubmission { | ||
return BasicSubmission( | ||
accNo = accNo, | ||
version = version, | ||
secretKey = secretKey, | ||
title = title, | ||
relPath = relPath, | ||
released = released, | ||
creationTime = creationTime.atOffset(ZoneOffset.UTC), | ||
modificationTime = modificationTime.atOffset(ZoneOffset.UTC), | ||
releaseTime = releaseTime?.atOffset(ZoneOffset.UTC), | ||
status = status.toProcessingStatus(), | ||
method = method.toSubmissionMethod(), | ||
owner = owner) | ||
} | ||
|
||
private fun DocProcessingStatus.toProcessingStatus(): ProcessingStatus = | ||
when (this) { | ||
DocProcessingStatus.PROCESSED -> ProcessingStatus.PROCESSED | ||
DocProcessingStatus.PROCESSING -> ProcessingStatus.PROCESSING | ||
DocProcessingStatus.REQUESTED -> ProcessingStatus.REQUESTED | ||
} | ||
|
||
private fun DocSubmissionMethod.toSubmissionMethod(): SubmissionMethod = | ||
when (this) { | ||
DocSubmissionMethod.FILE -> SubmissionMethod.FILE | ||
DocSubmissionMethod.PAGE_TAB -> SubmissionMethod.PAGE_TAB | ||
DocSubmissionMethod.UNKNOWN -> SubmissionMethod.UNKNOWN | ||
} |
File renamed without changes.
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
87 changes: 87 additions & 0 deletions
87
...st/kotlin/ac/uk/ebi/biostd/persistence/doc/service/SubmissionMongoMetaQueryServiceTest.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,87 @@ | ||
package ac.uk.ebi.biostd.persistence.doc.service | ||
|
||
import ac.uk.ebi.biostd.persistence.doc.db.repositories.SubmissionMongoRepository | ||
import ac.uk.ebi.biostd.persistence.doc.integration.MongoDbReposConfig | ||
import ac.uk.ebi.biostd.persistence.doc.model.DocAttribute | ||
import ac.uk.ebi.biostd.persistence.doc.model.DocProcessingStatus.PROCESSED | ||
import ac.uk.ebi.biostd.persistence.doc.test.doc.testDocSubmission | ||
import ebi.ac.uk.db.MONGO_VERSION | ||
import ebi.ac.uk.model.constants.SubFields | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.test.context.DynamicPropertyRegistry | ||
import org.springframework.test.context.DynamicPropertySource | ||
import org.springframework.test.context.junit.jupiter.SpringExtension | ||
import org.testcontainers.containers.MongoDBContainer | ||
import org.testcontainers.junit.jupiter.Container | ||
import org.testcontainers.junit.jupiter.Testcontainers | ||
import org.testcontainers.utility.DockerImageName | ||
|
||
@ExtendWith(SpringExtension::class) | ||
@Testcontainers | ||
@SpringBootTest(classes = [MongoDbReposConfig::class]) | ||
internal class SubmissionMongoMetaQueryServiceTest { | ||
|
||
@Autowired | ||
lateinit var testInstance: SubmissionMongoMetaQueryService | ||
|
||
@Autowired | ||
lateinit var submissionMongoRepository: SubmissionMongoRepository | ||
|
||
@Test | ||
fun getBasicProject() { | ||
submissionMongoRepository.save(testDocSubmission.copy( | ||
accNo = "accNo1", | ||
version = 1, | ||
status = PROCESSED, | ||
attributes = listOf(DocAttribute(SubFields.ACC_NO_TEMPLATE.value, "template")) | ||
)) | ||
|
||
val result = testInstance.getBasicProject("accNo1") | ||
|
||
assertThat(result.accNo).isEqualTo("accNo1") | ||
} | ||
|
||
@Test | ||
fun findLatestBasicByAccNo() { | ||
submissionMongoRepository.save(testDocSubmission.copy(accNo = "accNo2", version = 1, status = PROCESSED)) | ||
submissionMongoRepository.save(testDocSubmission.copy(accNo = "accNo2", version = -2, status = PROCESSED)) | ||
submissionMongoRepository.save(testDocSubmission.copy(accNo = "accNo2", version = 4, status = PROCESSED)) | ||
|
||
val lastVersion = testInstance.findLatestBasicByAccNo("accNo2") | ||
|
||
assertThat(lastVersion).isNotNull() | ||
assertThat(lastVersion!!.version).isEqualTo(4) | ||
} | ||
|
||
@Test | ||
fun `exists by AccNo when exists`() { | ||
submissionMongoRepository.save(testDocSubmission.copy(accNo = "accNo3", version = 1, status = PROCESSED)) | ||
|
||
assertThat(submissionMongoRepository.existsByAccNo("accNo3")).isTrue() | ||
} | ||
|
||
@Test | ||
fun `exist by AccNo when don't exists`() { | ||
submissionMongoRepository.save(testDocSubmission.copy(accNo = "accNo4", version = 1, status = PROCESSED)) | ||
|
||
assertThat(submissionMongoRepository.existsByAccNo("accNo5")).isFalse() | ||
} | ||
|
||
companion object { | ||
|
||
@Container | ||
val mongoContainer: MongoDBContainer = MongoDBContainer(DockerImageName.parse(MONGO_VERSION)) | ||
|
||
@JvmStatic | ||
@DynamicPropertySource | ||
fun propertySource(register: DynamicPropertyRegistry) { | ||
register.add("spring.data.mongodb.uri") { mongoContainer.getReplicaSetUrl("testDb") } | ||
register.add("spring.data.mongodb.database") { "testDb" } | ||
register.add("app.persistence.enableMongo") { "true" } | ||
} | ||
} | ||
} |
Oops, something went wrong.