Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanh committed Oct 10, 2023
1 parent a0c894e commit ff15cf9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 26 deletions.
1 change: 0 additions & 1 deletion src/main/resources/application.base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ referenceGenerator {
referenceLimit = ${REFERENCE_GENERATOR_LIMIT}
}


environment = ${ENVIRONMENT}

akka.http {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ trait GraphQLServerBase {
val referenceGeneratorService = new ReferenceGeneratorService(config, SimpleHttpClient())
val fileService = new FileService(
fileRepository,
consignmentRepository,
customMetadataPropertiesRepository,
ffidMetadataService,
antivirusMetadataService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import scala.math.min

class FileService(
fileRepository: FileRepository,
consignmentRepository: ConsignmentRepository,
customMetadataPropertiesRepository: CustomMetadataPropertiesRepository,
ffidMetadataService: FFIDMetadataService,
avMetadataService: AntivirusMetadataService,
Expand All @@ -55,14 +54,14 @@ class FileService(

val row: (UUID, String, String) => FilemetadataRow = FilemetadataRow(uuidSource.uuid, _, _, now, userId, _)
val rows: Future[List[Rows]] = customMetadataPropertiesRepository.getCustomMetadataValuesWithDefault.map(filePropertyValue => {
val filesAndFolderCombined = allEmptyDirectoryNodes ++ allFileNodes
val fileAndFolderAssignedRef = if (referenceGeneratorFeatureBlock) {
filesAndFolderCombined.keys.zip(filesAndFolderCombined.values.zip(List.fill(filesAndFolderCombined.size)(None))).toMap
val allNodes = allEmptyDirectoryNodes ++ allFileNodes
val allNodesWithReference = if (referenceGeneratorFeatureBlock) {
allNodes.keys.zip(allNodes.values.zip(List.fill(allNodes.size)(None))).toMap
} else {
val generatedReferences = referenceGeneratorService.getReferences(filesAndFolderCombined.size)
filesAndFolderCombined.keys.zip(filesAndFolderCombined.values.zip(generatedReferences.map(Some(_)))).toMap
val generatedReferences = referenceGeneratorService.getReferences(allNodes.size)
allNodes.keys.zip(allNodes.values.zip(generatedReferences.map(Some(_)))).toMap
}
(fileAndFolderAssignedRef map { case (path, (treeNode, reference)) =>
(allNodesWithReference map { case (path, (treeNode, reference)) =>
val parentId = treeNode.parentPath.map(path => allFileNodes.getOrElse(path, allEmptyDirectoryNodes(path)).id)
val fileId = treeNode.id
val fileRow = FileRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ class ReferenceGeneratorService(config: Config, client: SimpleHttpClient) {
}

@tailrec
def recursivelyFetchReferences(numberOfRefs: Int, acc: List[reference]): List[reference] = {
def fetchReferences(numberOfRefs: Int, acc: List[reference]): List[reference] = {
if (numberOfRefs <= 0) acc
else {
val batchSize = Math.min(numberOfRefs, refGeneratorLimit)
val response: Response[Either[String, reference]] = client.send(basicRequest.get(uri"$refGeneratorUrl/$environment/counter?numberofrefs=$batchSize"))
recursivelyFetchReferences(numberOfRefs - batchSize, acc ++ processResponse(response))
fetchReferences(numberOfRefs - batchSize, acc ++ processResponse(response))
}
}

if (numberOfRefs > refGeneratorLimit) {
recursivelyFetchReferences(numberOfRefs, Nil)
fetchReferences(numberOfRefs, Nil)
} else {
val response: Response[Either[String, reference]] = client.send(basicRequest.get(uri"$refGeneratorUrl/$environment/counter?numberofrefs=$numberOfRefs"))
processResponse(response)
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ featureAccessBlock {
}

referenceGenerator {
referenceGeneratorUrl = "https://q59yzinibd.execute-api.eu-west-2.amazonaws.com"
referenceGeneratorUrl = "https://dummy-reference-url.com"
referenceLimit = 2
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S
private val bodyId = UUID.randomUUID()
val uuidSource: FixedUUIDSource = new FixedUUIDSource()

val consignmentRepositoryMock: ConsignmentRepository = mock[ConsignmentRepository]
val consignmentStatusRepositoryMock: ConsignmentStatusRepository = mock[ConsignmentStatusRepository]
val customMetadataPropertiesRepositoryMock: CustomMetadataPropertiesRepository = mock[CustomMetadataPropertiesRepository]
val customMetadataServiceMock: CustomMetadataPropertiesService = mock[CustomMetadataPropertiesService]
Expand Down Expand Up @@ -125,7 +124,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val fileService = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -171,7 +169,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
mock[ConsignmentRepository],
mock[CustomMetadataPropertiesRepository],
mock[FFIDMetadataService],
mock[AntivirusMetadataService],
Expand Down Expand Up @@ -250,7 +247,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -390,7 +386,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -489,7 +484,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -601,7 +595,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -689,7 +682,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -745,7 +737,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -837,7 +828,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -941,7 +931,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

val service = new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down Expand Up @@ -1382,7 +1371,6 @@ class FileServiceSpec extends AnyFlatSpec with MockitoSugar with Matchers with S

new FileService(
fileRepositoryMock,
consignmentRepositoryMock,
customMetadataPropertiesRepositoryMock,
ffidMetadataService,
antivirusMetadataService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ReferenceGeneratorServiceSpec extends AnyFlatSpec with Matchers {
getReferences shouldBe List("REF1", "REF2")
}

"getReferences" should "return a list of references if referenceLimit is exceeded" in {
"getReferences" should "return the correct number of reference if 'referenceLimit' is exceeded in the request" in {
val sttpBackendStub = SttpBackendStub.synchronous
.whenRequestMatches(_.uri.path.startsWith(List("intg", "counter")))
.thenRespondCyclic("""["REF1","REF2"]""", """["REF3"]""")
Expand Down

0 comments on commit ff15cf9

Please sign in to comment.