Skip to content

Commit

Permalink
Pivotal ID # 170971193: Prepare Model For Async Processing (#173)
Browse files Browse the repository at this point in the history
* Pivotal ID # 170971193: Prepare Model For Async Processing

- added independent domain model object ext
  • Loading branch information
Juan-EBI authored Mar 2, 2020
1 parent d2df630 commit b4ff24e
Show file tree
Hide file tree
Showing 74 changed files with 851 additions and 1,215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ private const val GROUP_URL = "/groups"
private const val PROJECTS_URL = "/projects"

class CommonOperationsClient(private val template: RestTemplate) : GeneralOperations {
override fun getGroups(): List<Group> = template.getForObject<Array<Group>>(GROUP_URL).orEmpty().toList()
override fun getGroups(): List<Group> = template.getForObject<Array<Group>>(GROUP_URL).toList()

override fun getProjects(): List<Project> = template.getForObject<Array<Project>>(PROJECTS_URL).orEmpty().toList()
override fun getProjects(): List<Project> = template.getForObject<Array<Project>>(PROJECTS_URL).toList()
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import ac.uk.ebi.biostd.client.integration.web.FilesOperations
import ac.uk.ebi.biostd.client.integration.web.GeneralOperations
import ac.uk.ebi.biostd.client.integration.web.GroupFilesOperations
import ac.uk.ebi.biostd.client.integration.web.MultipartSubmissionOperations
import ac.uk.ebi.biostd.client.integration.web.ProjectOperations
import ac.uk.ebi.biostd.client.integration.web.SubmissionClient
import ac.uk.ebi.biostd.client.integration.web.SubmissionOperations
import ac.uk.ebi.biostd.integration.SerializationService
Expand All @@ -18,7 +17,6 @@ internal class SubmissionClientImpl(
FilesOperations by UserFilesClient(template),
GroupFilesOperations by GroupFilesClient(template),
SubmissionOperations by SubmissionClient(template, serializationService),
ProjectOperations by ProjectClient(template, serializationService),
MultipartSubmissionOperations by MultiPartSubmissionClient(template, serializationService),
GeneralOperations by CommonOperationsClient(template),
DraftSubmissionOperations by SubmissionDraftClient(template)
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ interface SubmissionClient :
SubmissionOperations,
FilesOperations,
GroupFilesOperations,
ProjectOperations,
MultipartSubmissionOperations,
GeneralOperations,
DraftSubmissionOperations
Expand Down Expand Up @@ -80,12 +79,6 @@ interface MultipartSubmissionOperations {
): ResponseEntity<Submission>
}

interface ProjectOperations {
fun submitProject(project: File): ResponseEntity<Submission>

fun attachSubmission(projectAccNo: String, submission: File, files: List<File>): ResponseEntity<Submission>
}

interface SecurityOperations {
fun getAuthenticatedClient(user: String, password: String): BioWebClient

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ebi.ac.uk.api.dto

import ebi.ac.uk.model.SubmissionMethod
import java.time.OffsetDateTime

data class SubmissionDto(
Expand All @@ -8,5 +9,6 @@ data class SubmissionDto(
val version: Int,
val ctime: OffsetDateTime,
val mtime: OffsetDateTime,
val rtime: OffsetDateTime?
val rtime: OffsetDateTime?,
val method: SubmissionMethod?
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ebi.ac.uk.model

import ebi.ac.uk.base.EMPTY

/**
* Represents an submission accession number which include a pattern an a numeric value.
*/
class AccNumber(val prefix: String, val numericValue: Long) {
override fun toString() = "$prefix$numericValue"
data class AccNumber(val prefix: String, val numericValue: Long? = null) {
override fun toString() = "$prefix${numericValue ?: EMPTY}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class SubmissionFolderResolver(private val basePath: Path) {
fun getSubmissionFolder(submission: ExtendedSubmission): Path =
basePath.resolve(SUBMISSION_PATH).resolve(submission.relPath)

fun getSubmissionFolder(submissionRelPath: String): Path =
basePath.resolve(SUBMISSION_PATH).resolve(submissionRelPath)

fun getSubFilePath(relPath: String, fileName: String): Path =
basePath.resolve(SUBMISSION_PATH).resolve(relPath).resolve(FILES_PATH).resolve(escapeFileName(fileName))

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import ebi.ac.uk.extended.model.ExtAttribute
import ebi.ac.uk.extended.model.ExtAttributeDetail
import ebi.ac.uk.model.Attribute
import ebi.ac.uk.model.AttributeDetail
import ebi.ac.uk.model.constants.SectionFields

internal const val TO_EXT_ATTRIBUTE_EXTENSIONS = "ebi.ac.uk.extended.mapping.serialization.from.ToExtAttributeKt"

fun Attribute.toExtAttribute() = ExtAttribute(name, value, reference, toDetails(nameAttrs), toDetails(valueAttrs))
fun Attribute.toExtAttribute(): ExtAttribute {
val attrValue = if (name == SectionFields.FILE_LIST.value) value.substringBeforeLast(".") else value
return ExtAttribute(name, attrValue, reference, toDetails(nameAttrs), toDetails(valueAttrs))
}

private fun toDetails(details: List<AttributeDetail>) = details.map { ExtAttributeDetail(it.name, it.value) }
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ import ebi.ac.uk.model.FileList
internal const val TO_EXT_LIBRARY_FILE_EXTENSIONS = "ebi.ac.uk.extended.mapping.serialization.from.ToExtFileListKt"

fun FileList.toExtFileList(fileSource: FilesSource): ExtFileList =
ExtFileList(name, fileSource.getFile(name), referencedFiles.map { it.toExtFile(fileSource) })
ExtFileList(
name.substringBeforeLast("."),
fileSource.getFile(name),
referencedFiles.map { it.toExtFile(fileSource) })
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,5 @@ fun Section.toExtSection(source: FilesSource): ExtSection {
attributes = attributes.map { it.toExtAttribute() },
files = files.map { either -> either.bimap({ it.toExtFile(source) }, { it.toExtTable(source) }) },
links = links.map { either -> either.bimap({ it.toExtLink() }, { it.toExtTable() }) },
sections = sections.map { either -> either.bimap({ it.toExtSubSection(source) }, { it.toExtTable(source) }) })
}

fun Section.toExtSubSection(source: FilesSource): ExtSection {
return ExtSection(
type = type,
accNo = accNo,
fileList = fileList?.toExtFileList(source),
attributes = attributes.map { it.toExtAttribute() }
)
sections = sections.map { either -> either.bimap({ it.toExtSection(source) }, { it.toExtTable(source) }) })
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,5 @@ fun ExtSection.toSection(): Section {
attributes = attributes.mapTo(mutableListOf()) { it.toAttribute() },
files = files.mapTo(mutableListOf()) { either -> either.bimap({ it.toFile() }, { it.toTable() }) },
links = links.mapTo(mutableListOf()) { either -> either.bimap({ it.toLink() }, { it.toTable() }) },
sections = sections.mapTo(mutableListOf()) { either -> either.bimap({ it.toSubSection() }, { it.toTable() }) })
}

fun ExtSection.toSubSection(): Section {
return Section(
type = type,
accNo = accNo,
fileList = fileList?.toFileList(),
attributes = attributes.mapTo(mutableListOf()) { it.toAttribute() })
sections = sections.mapTo(mutableListOf()) { either -> either.bimap({ it.toSection() }, { it.toTable() }) })
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package ebi.ac.uk.extended.mapping.serialization.to

import ebi.ac.uk.extended.model.ExtSubmission
import ebi.ac.uk.model.Attribute
import ebi.ac.uk.model.Submission
import ebi.ac.uk.model.constants.SubFields
import ebi.ac.uk.model.extensions.creationTime
import ebi.ac.uk.model.extensions.modificationTime
import ebi.ac.uk.model.extensions.releaseTime
Expand All @@ -14,11 +16,20 @@ fun ExtSubmission.toSimpleSubmission(): Submission {
return Submission(
accNo = accNo,
section = section.toSection(),
attributes = attributes.map { it.toAttribute() }.toMutableList(),
attributes = getSubmissionAttributes(),
tags = tags.mapTo(mutableListOf()) { Pair(it.name, it.value) }
)
}

private fun ExtSubmission.getSubmissionAttributes(): List<Attribute> {
val subAttrs = attributes.map { it.toAttribute() }.toMutableList()

return when (releaseTime) {
null -> subAttrs
else -> subAttrs.plus(Attribute(SubFields.RELEASE_DATE, releaseTime.toLocalDate()))
}
}

/**
* Return a extended submission which contains submission secret information and internal information.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ val ExtSubmission.allReferencedFiles
val ExtSubmission.allFiles
get(): List<ExtFile> = allSections.flatMap { it.allFiles }

val ExtSubmission.allFileLists
val ExtSubmission.allFileListSections
get(): List<ExtFileList> = allSections.mapNotNull { it.fileList }
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ebi.ac.uk.extended.model

import arrow.core.Either
import ebi.ac.uk.model.SubmissionMethod
import ebi.ac.uk.model.constants.ProcessingStatus
import java.io.File
import java.time.OffsetDateTime
Expand Down Expand Up @@ -38,7 +39,9 @@ data class ExtSection(

data class ExtSubmission(
val accNo: String,
var version: Int,
val title: String?,
val method: SubmissionMethod,
val relPath: String,
val rootPath: String?,
val released: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ebi.ac.uk.extended.model.ExtFileList
import ebi.ac.uk.extended.model.ExtFileTable
import ebi.ac.uk.extended.model.ExtLink
import ebi.ac.uk.extended.model.ExtLinkTable
import ebi.ac.uk.extended.model.ExtSection
import ebi.ac.uk.extended.model.ExtSectionTable
import ebi.ac.uk.io.sources.FilesSource
import ebi.ac.uk.model.Attribute
Expand Down Expand Up @@ -37,25 +36,24 @@ class ToExtSectionTest(
@MockK val fileTable: FilesTable,
@MockK val link: Link,
@MockK val linkTable: LinksTable,
@MockK val subsection: Section,
@MockK val sectionTable: SectionsTable,
@MockK val extFileList: ExtFileList,
@MockK val extAttribute: ExtAttribute,
@MockK val extFile: ExtFile,
@MockK val extFileTable: ExtFileTable,
@MockK val extLink: ExtLink,
@MockK val extLinkTable: ExtLinkTable,
@MockK val extSubsection: ExtSection,
@MockK val extSectionTable: ExtSectionTable
) {
private val subSection = Section(type = "subtype", accNo = "accNo1")
private val section = Section(
type = "type",
accNo = "accNo",
fileList = fileList,
attributes = listOf(attribute),
files = mutableListOf(left(file), right(fileTable)),
links = mutableListOf(left(link), right(linkTable)),
sections = mutableListOf(left(subsection), right(sectionTable))
sections = mutableListOf(left(subSection), right(sectionTable))
)

@Test
Expand All @@ -76,7 +74,6 @@ class ToExtSectionTest(
every { linkTable.toExtTable() } returns extLinkTable
every { sectionTable.toExtTable(fileSource) } returns extSectionTable
every { fileList.toExtFileList(fileSource) } returns extFileList
every { subsection.toExtSubSection(fileSource) } returns extSubsection

val sectionResult = section.toExtSection(fileSource)
assertThat(sectionResult.accNo).isEqualTo(section.accNo)
Expand All @@ -87,8 +84,11 @@ class ToExtSectionTest(
assertThat(sectionResult.files.second()).isEqualTo(right(extFileTable))
assertThat(sectionResult.links.first()).isEqualTo(left(extLink))
assertThat(sectionResult.links.second()).isEqualTo(right(extLinkTable))
assertThat(sectionResult.sections.first()).isEqualTo(left(extSubsection))
assertThat(sectionResult.sections.second()).isEqualTo(right(extSectionTable))
sectionResult.sections.first().mapLeft {
assertThat(it.type).isEqualTo("subtype")
assertThat(it.accNo).isEqualTo("accNo1")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import ebi.ac.uk.model.FileList
import ebi.ac.uk.model.FilesTable
import ebi.ac.uk.model.Link
import ebi.ac.uk.model.LinksTable
import ebi.ac.uk.model.Section
import ebi.ac.uk.model.SectionsTable
import ebi.ac.uk.util.collections.second
import io.mockk.every
Expand All @@ -35,25 +34,24 @@ class ToSectionTest(
@MockK val fileTable: FilesTable,
@MockK val link: Link,
@MockK val linkTable: LinksTable,
@MockK val subsection: Section,
@MockK val sectionTable: SectionsTable,
@MockK val extFileList: ExtFileList,
@MockK val extAttribute: ExtAttribute,
@MockK val extFile: ExtFile,
@MockK val extFileTable: ExtFileTable,
@MockK val extLink: ExtLink,
@MockK val extLinkTable: ExtLinkTable,
@MockK val extSubsection: ExtSection,
@MockK val extSectionTable: ExtSectionTable
) {
private val subSection = ExtSection(type = "subtype", accNo = "accNo1")
private val section = ExtSection(
type = "type",
accNo = "accNo",
fileList = extFileList,
attributes = listOf(extAttribute),
files = listOf(left(extFile), right(extFileTable)),
links = listOf(left(extLink), right(extLinkTable)),
sections = listOf(left(extSubsection), right(extSectionTable))
sections = listOf(left(subSection), right(extSectionTable))
)

@Test
Expand All @@ -74,7 +72,6 @@ class ToSectionTest(
every { extLinkTable.toTable() } returns linkTable
every { extSectionTable.toTable() } returns sectionTable
every { extFileList.toFileList() } returns fileList
every { extSubsection.toSubSection() } returns subsection

val sectionResult = section.toSection()
assertThat(sectionResult.accNo).isEqualTo(section.accNo)
Expand All @@ -85,8 +82,11 @@ class ToSectionTest(
assertThat(sectionResult.files.second()).isEqualTo(right(fileTable))
assertThat(sectionResult.links.first()).isEqualTo(left(link))
assertThat(sectionResult.links.second()).isEqualTo(right(linkTable))
assertThat(sectionResult.sections.first()).isEqualTo(left(subsection))
assertThat(sectionResult.sections.second()).isEqualTo(right(sectionTable))
sectionResult.sections.first().mapLeft {
assertThat(it.type).isEqualTo("subtype")
assertThat(it.accNo).isEqualTo("accNo1")
}
}
}
}
Loading

0 comments on commit b4ff24e

Please sign in to comment.