Skip to content

Commit

Permalink
PIN-4488 Corrections after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli committed Feb 6, 2024
1 parent 6c79321 commit ad102b6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final case class ProcessApiServiceImpl(
origin <- getExternalIdOriginFuture(contexts)
_ <- if (origin == IPA) Future.unit else Future.failed(OriginIsNotCompliant(IPA))
clientSeed = eServiceSeed.toDependency(organizationId)
_ <- checkDuplicateName(None, eServiceSeed.name, clientSeed.producerId)
_ <- checkDuplicateName(organizationId, None, eServiceSeed.name, clientSeed.producerId)
createdEService <- catalogManagementService.createEService(clientSeed)
} yield createdEService.toApi

Expand Down Expand Up @@ -481,9 +481,25 @@ final case class ProcessApiServiceImpl(
}
}

private def checkDuplicateName(eServiceId: Option[UUID], name: String, producerId: UUID): Future[Unit] = for {
private def checkDuplicateName(
requesterId: UUID,
eServiceId: Option[UUID],
name: String,
producerId: UUID
): Future[Unit] = for {
result <- catalogManagementService
.getEServices(name.some, Seq.empty, Seq(producerId), Seq.empty, Seq.empty, None, 0, 1, exactMatchOnName = true)
.getEServices(
requesterId,
name.some,
Seq.empty,
Seq(producerId),
Seq.empty,
Seq.empty,
None,
0,
1,
exactMatchOnName = true
)
eservice = eServiceId.fold(result.results)(id => result.results.filterNot(_.id == id))
_ <- eservice.headOption.map(_.name).fold(Future.unit)(_ => Future.failed(DuplicatedEServiceName(name)))
} yield ()
Expand All @@ -497,13 +513,13 @@ final case class ProcessApiServiceImpl(
logger.info(operationLabel)

val result = for {
organizationId <- getOrganizationIdFutureUUID(contexts)
eServiceUuid <- eServiceId.toFutureUUID
catalogItem <- catalogManagementService.getEServiceById(eServiceUuid)
_ <- assertRequesterAllowed(catalogItem.producerId)(organizationId)
_ <- eServiceCanBeUpdated(catalogItem).toFuture
_ <- checkDuplicateName(Some(eServiceUuid), updateEServiceSeed.name, catalogItem.producerId)
_ <- deleteRiskAnalysisOnModeUpdate(updateEServiceSeed.mode, catalogItem)
organizationId <- getOrganizationIdFutureUUID(contexts)
eServiceUuid <- eServiceId.toFutureUUID
catalogItem <- catalogManagementService.getEServiceById(eServiceUuid)
_ <- assertRequesterAllowed(catalogItem.producerId)(organizationId)
_ <- eServiceCanBeUpdated(catalogItem).toFuture
_ <- checkDuplicateName(organizationId, Some(eServiceUuid), updateEServiceSeed.name, catalogItem.producerId)
_ <- deleteRiskAnalysisOnModeUpdate(updateEServiceSeed.mode, catalogItem)
updatedEService <- catalogManagementService.updateEServiceById(eServiceId, updateEServiceSeed.toDependency)
} yield updatedEService.toApi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR

(mockCatalogManagementService
.getEServices(
_: UUID,
_: Option[String],
_: Seq[UUID],
_: Seq[UUID],
Expand All @@ -636,9 +637,11 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
_: Option[CatalogItemMode],
_: Int,
_: Int,
_: Boolean,
_: Boolean
)(_: ExecutionContext, _: ReadModelService))
.expects(
requesterId,
Some(updatedEServiceSeed.name),
Seq.empty,
Seq(requesterId),
Expand All @@ -648,6 +651,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
0,
1,
true,
false,
*,
*
)
Expand Down Expand Up @@ -709,6 +713,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR

(mockCatalogManagementService
.getEServices(
_: UUID,
_: Option[String],
_: Seq[UUID],
_: Seq[UUID],
Expand All @@ -717,9 +722,11 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
_: Option[CatalogItemMode],
_: Int,
_: Int,
_: Boolean,
_: Boolean
)(_: ExecutionContext, _: ReadModelService))
.expects(
requesterId,
Some(updatedEServiceSeed.name),
Seq.empty,
Seq(requesterId),
Expand All @@ -729,6 +736,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
0,
1,
true,
false,
*,
*
)
Expand Down Expand Up @@ -810,6 +818,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR

(mockCatalogManagementService
.getEServices(
_: UUID,
_: Option[String],
_: Seq[UUID],
_: Seq[UUID],
Expand All @@ -818,9 +827,11 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
_: Option[CatalogItemMode],
_: Int,
_: Int,
_: Boolean,
_: Boolean
)(_: ExecutionContext, _: ReadModelService))
.expects(
requesterId,
Some(updatedEServiceSeed.name),
Seq.empty,
Seq(requesterId),
Expand All @@ -830,6 +841,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
0,
1,
true,
false,
*,
*
)
Expand Down Expand Up @@ -896,6 +908,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR

(mockCatalogManagementService
.getEServices(
_: UUID,
_: Option[String],
_: Seq[UUID],
_: Seq[UUID],
Expand All @@ -904,9 +917,11 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
_: Option[CatalogItemMode],
_: Int,
_: Int,
_: Boolean,
_: Boolean
)(_: ExecutionContext, _: ReadModelService))
.expects(
requesterId,
Some(updatedEServiceSeed.name),
Seq.empty,
Seq(requesterId),
Expand All @@ -916,6 +931,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
0,
1,
true,
false,
*,
*
)
Expand Down Expand Up @@ -960,6 +976,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR

(mockCatalogManagementService
.getEServices(
_: UUID,
_: Option[String],
_: Seq[UUID],
_: Seq[UUID],
Expand All @@ -968,9 +985,11 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
_: Option[CatalogItemMode],
_: Int,
_: Int,
_: Boolean,
_: Boolean
)(_: ExecutionContext, _: ReadModelService))
.expects(
requesterId,
Some(updatedEServiceSeed.name),
Seq.empty,
Seq(requesterId),
Expand All @@ -980,6 +999,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
0,
1,
true,
false,
*,
*
)
Expand Down

0 comments on commit ad102b6

Please sign in to comment.