From f8902d43cb189b408210ae7c80e2112346bdc037 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Thu, 28 Sep 2017 18:26:36 +0700 Subject: Fixed generators of entities for ReP; Implemented json examples for swagger for ReP --- .../fakes/entities/rep/BridgeUploadQueueGen.scala | 15 ++----- .../fakes/entities/rep/DocumentGen.scala | 48 +++++++++++--------- .../fakes/entities/rep/ExtractedDataGen.scala | 14 +++++- .../fakes/entities/rep/MedicalRecordGen.scala | 52 +++++++++++----------- .../fakes/entities/rep/ProviderTypeGen.scala | 14 ++++++ 5 files changed, 81 insertions(+), 62 deletions(-) create mode 100644 src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala (limited to 'src/main/scala/xyz/driver/pdsuidomain/fakes/entities') diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala index fb1d3e3..e7cbd19 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/BridgeUploadQueueGen.scala @@ -2,30 +2,21 @@ package xyz.driver.pdsuidomain.fakes.entities.rep import xyz.driver.core.generators.{nextBoolean, nextInt, nextOption, nextString} import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueue -import xyz.driver.pdsuidomain.entities.ProviderType -import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId} +import xyz.driver.pdsuidomain.fakes.entities.common.nextLocalDateTime object BridgeUploadQueueGen { - private val maxAttemtsNumber = 100 + private val maxAttemptsNumber = 100 def nextBridgeUploadQueueItem(): BridgeUploadQueue.Item = { BridgeUploadQueue.Item( kind = nextString(), tag = nextString(), created = nextLocalDateTime, - attempts = nextInt(maxAttemtsNumber, minValue = 0), + attempts = nextInt(maxAttemptsNumber, minValue = 0), nextAttempt = nextLocalDateTime, completed = nextBoolean(), dependencyKind = nextOption(nextString()), dependencyTag = nextOption(nextString()) ) } - - def nextProviderType(): ProviderType = { - ProviderType( - id = nextLongId[ProviderType], - name = nextString() - ) - } - } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala index 2f07f1d..0d32495 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/DocumentGen.scala @@ -18,43 +18,47 @@ object DocumentGen { } } - private def nextDates = + private def nextDates() = Common.genBoundedRangeOption[LocalDate](nextLocalDate, nextLocalDate) - private def nextStartAndEndPagesOption = + private def nextStartAndEndPagesOption() = Common.nextStartAndEndPages - private def nextStartAndEndPage = + private def nextStartAndEndPage() = Common.genBoundedRange(nextDouble(),nextDouble()) - def nextDocumentStatus: Document.Status = - generators.oneOf[Document.Status](Document.Status.All) + def nextDocumentStatus(): Document.Status = + Document.Status.New - def nextDocumentRequiredType: Document.RequiredType = + def nextDocumentRequiredType(): Document.RequiredType = generators.oneOf[Document.RequiredType](Document.RequiredType.All) - def nextDocumentHistoryState: DocumentHistory.State = + def nextDocumentHistoryState(): DocumentHistory.State = generators.oneOf[DocumentHistory.State](DocumentHistory.State.All) - def nextDocumentHistoryAction: DocumentHistory.Action = + def nextDocumentHistoryAction(): DocumentHistory.Action = generators.oneOf[DocumentHistory.Action](DocumentHistory.Action.All) - def nextDocumentMeta: Document.Meta = { - val (startPage, endPage) = nextStartAndEndPage + def nextDocumentMeta(): Document.Meta = { + val (startPage, endPage) = nextStartAndEndPage() Document.Meta( nextOption(nextBoolean()), startPage, endPage ) } - def nextDocument: Document = { - val dates = nextDates + def nextDocumentMetaJson(): TextJson[Document.Meta] = { + TextJson(nextDocumentMeta()) + } + + def nextDocument(): Document = { + val dates = nextDates() Document( id = nextLongId[Document], - status = nextDocumentStatus, - previousStatus = nextOption(nextDocumentStatus), + status = nextDocumentStatus(), + previousStatus = None, assignee = nextOption(nextStringId[User]), previousAssignee = nextOption(nextStringId[User]), lastActiveUserId = nextOption(nextStringId[User]), @@ -63,23 +67,23 @@ object DocumentGen { typeId = nextOption(nextLongId[DocumentType]), providerName = nextOption(nextString()), providerTypeId = nextOption(nextLongId[ProviderType]), - requiredType = nextOption(nextDocumentRequiredType), - meta = nextOption(TextJson(nextDocumentMeta)), + requiredType = nextOption(nextDocumentRequiredType()), + meta = nextOption(nextDocumentMetaJson()), startDate = dates._1, endDate = dates._2, lastUpdate = nextLocalDateTime ) } - def nextDocumentType: DocumentType = { + def nextDocumentType(): DocumentType = { DocumentType( id = nextLongId[DocumentType], name = nextString() ) } - def nextDocumentIssue(documentId: LongId[Document]): DocumentIssue = { - val pages = nextStartAndEndPagesOption + def nextDocumentIssue(documentId: LongId[Document] = nextLongId): DocumentIssue = { + val pages = nextStartAndEndPagesOption() DocumentIssue( id = nextLongId[DocumentIssue], @@ -95,13 +99,13 @@ object DocumentGen { } - def nextDocumentHistory(documentId: LongId[Document]): DocumentHistory = { + def nextDocumentHistory(documentId: LongId[Document] = nextLongId): DocumentHistory = { DocumentHistory( id = nextLongId[DocumentHistory], executor = nextStringId[User], documentId = documentId, - state = nextDocumentHistoryState, - action = nextDocumentHistoryAction, + state = nextDocumentHistoryState(), + action = nextDocumentHistoryAction(), created = nextLocalDateTime ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala index 512e324..0d99d19 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ExtractedDataGen.scala @@ -67,13 +67,23 @@ object ExtractedDataGen { ) } + def nextExtractedDataMetaJson(): TextJson[Meta] = { + TextJson( + ExtractedData.Meta( + nextExtractedDataMetaKeyword(), + nextExtractedDataMetaEvidence() + ) + ) + } + + def nextExtractedData(documentId: LongId[Document]): ExtractedData = { ExtractedData( id = nextLongId[ExtractedData], documentId = documentId, keywordId = nextOption(nextLongId[xyz.driver.pdsuidomain.entities.Keyword]), evidenceText = nextOption(nextString()), - meta = nextOption(TextJson(nextExtractedDataMeta())) + meta = nextOption(nextExtractedDataMetaJson()) ) } @@ -88,7 +98,7 @@ object ExtractedDataGen { ) } - def nextRichExtractedData(documentId: LongId[Document]): RichExtractedData = { + def nextRichExtractedData(documentId: LongId[Document] = nextLongId): RichExtractedData = { RichExtractedData( extractedData = nextExtractedData(documentId), labels = List.fill( diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala index 0ea3cdd..90c98c3 100644 --- a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/MedicalRecordGen.scala @@ -7,31 +7,31 @@ import xyz.driver.pdsuicommon.domain.{LongId, TextJson, User} import xyz.driver.pdsuidomain.fakes.entities.common.{nextLocalDateTime, nextLongId, nextStringId, nextUuidId} object MedicalRecordGen { - private val maxItemsInCollectionNumber = 50 + private val maxItemsInCollectionNumber: Int = 50 - private val pageMaxNumber = 1000 + private val pageMaxNumber: Int = 1000 - private val medicalRecordMetas = { + private val medicalRecordMetas: Set[() => MedicalRecord.Meta] = { Set( - () => nextMedicalRecordMetaReorder, - () => nextMedicalRecordMetaDuplicate, - () => nextMedicalRecordMetaRotation + () => nextMedicalRecordMetaReorder(), + () => nextMedicalRecordMetaDuplicate(), + () => nextMedicalRecordMetaRotation() ) } def nextMedicalRecordMetas(count: Int): List[MedicalRecord.Meta] = - List.fill(count)(nextMedicalRecordMeta) + List.fill(count)(nextMedicalRecordMeta()) - private def nextMedicalRecordMetasJson: TextJson[List[MedicalRecord.Meta]] = + def nextMedicalRecordMetasJson(): TextJson[List[MedicalRecord.Meta]] = TextJson(nextMedicalRecordMetas(nextInt(maxItemsInCollectionNumber, minValue = 0))) - private def nextDocument: Document = - DocumentGen.nextDocument + private def nextDocument(): Document = + DocumentGen.nextDocument() private def nextDocuments(count: Int): List[Document] = - List.fill(count)(nextDocument) + List.fill(count)(nextDocument()) - private def nextDocuments(recordId: LongId[MedicalRecord]): TextJson[List[Document]] = { + def nextDocuments(recordId: LongId[MedicalRecord]): TextJson[List[Document]] = { val documents = nextDocuments( nextInt(maxItemsInCollectionNumber, minValue = 0) ) @@ -40,17 +40,17 @@ object MedicalRecordGen { } - def nextMedicalRecordStatus: MedicalRecord.Status = - generators.oneOf[MedicalRecord.Status](MedicalRecord.Status.All) + def nextMedicalRecordStatus(): MedicalRecord.Status = + MedicalRecord.Status.New - def nextMedicalRecordHistoryState: MedicalRecordHistory.State = + def nextMedicalRecordHistoryState(): MedicalRecordHistory.State = generators.oneOf[MedicalRecordHistory.State](MedicalRecordHistory.State.All) - def nextMedicalRecordHistoryAction: MedicalRecordHistory.Action = + def nextMedicalRecordHistoryAction(): MedicalRecordHistory.Action = generators.oneOf[MedicalRecordHistory.Action](MedicalRecordHistory.Action.All) - def nextMedicalRecordMetaReorder: MedicalRecord.Meta.Reorder = { + def nextMedicalRecordMetaReorder(): MedicalRecord.Meta.Reorder = { val itemsNumber = maxItemsInCollectionNumber val items = scala.util.Random @@ -63,7 +63,7 @@ object MedicalRecordGen { } - def nextMedicalRecordMetaDuplicate: MedicalRecord.Meta.Duplicate = { + def nextMedicalRecordMetaDuplicate(): MedicalRecord.Meta.Duplicate = { val startPageGen = nextInt(pageMaxNumber, minValue = 0) val endPageGen = @@ -78,7 +78,7 @@ object MedicalRecordGen { ) } - def nextMedicalRecordMetaRotation: MedicalRecord.Meta.Rotation = { + def nextMedicalRecordMetaRotation(): MedicalRecord.Meta.Rotation = { val items = Array.tabulate(maxItemsInCollectionNumber)( index => nextString() -> index @@ -90,7 +90,7 @@ object MedicalRecordGen { ) } - def nextMedicalRecordMeta: MedicalRecord.Meta = { + def nextMedicalRecordMeta(): MedicalRecord.Meta = { generators.oneOf(medicalRecordMetas)() } @@ -99,8 +99,8 @@ object MedicalRecordGen { val id = nextLongId[MedicalRecord] MedicalRecord( id = nextLongId[MedicalRecord], - status = nextMedicalRecordStatus, - previousStatus = nextOption(nextMedicalRecordStatus), + status = nextMedicalRecordStatus(), + previousStatus = None, assignee = nextOption(nextStringId), previousAssignee = nextOption(nextStringId), lastActiveUserId = nextOption(nextStringId), @@ -109,8 +109,8 @@ object MedicalRecordGen { disease = generators.nextString(), caseId = nextOption(CaseId(generators.nextString())), physician = nextOption(generators.nextString()), - meta = nextOption(nextMedicalRecordMetasJson), - predictedMeta = nextOption(nextMedicalRecordMetasJson), + meta = nextOption(nextMedicalRecordMetasJson()), + predictedMeta = nextOption(nextMedicalRecordMetasJson()), predictedDocuments = nextOption(nextDocuments(id)), lastUpdate = nextLocalDateTime ) @@ -121,8 +121,8 @@ object MedicalRecordGen { id = nextLongId[MedicalRecordHistory], executor = nextStringId[User], recordId = nextLongId[MedicalRecord], - state = nextMedicalRecordHistoryState, - action = nextMedicalRecordHistoryAction, + state = nextMedicalRecordHistoryState(), + action = nextMedicalRecordHistoryAction(), created = nextLocalDateTime ) } diff --git a/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala new file mode 100644 index 0000000..168f7af --- /dev/null +++ b/src/main/scala/xyz/driver/pdsuidomain/fakes/entities/rep/ProviderTypeGen.scala @@ -0,0 +1,14 @@ +package xyz.driver.pdsuidomain.fakes.entities.rep + +import xyz.driver.core.generators.nextString +import xyz.driver.pdsuidomain.entities.ProviderType +import xyz.driver.pdsuidomain.fakes.entities.common.nextLongId + +object ProviderTypeGen { + def nextProviderType(): ProviderType = { + ProviderType( + id = nextLongId[ProviderType], + name = nextString() + ) + } +} -- cgit v1.2.3