Skip to content

Commit

Permalink
Merge pull request #239 from pagopa/PIN-4561
Browse files Browse the repository at this point in the history
PIN-4561 BKE catalog-process Allow Eservice Update if has no descriptors but Technology is changed
  • Loading branch information
nttdata-rtorsoli authored Feb 13, 2024
2 parents 010af3b + 01cfdcb commit 912869a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,13 @@ final case class ProcessApiServiceImpl(
private def deleteInterfaceOnTechnologyUpdate(newTechnology: EServiceTechnology, catalogItem: CatalogItem)(implicit
contexts: Seq[(String, String)]
): Future[Unit] = {
if (catalogItem.technology.toApi != newTechnology)
for {
descriptor <- catalogItem.descriptors
.find(_.state == Draft)
.toFuture(EServiceCannotBeUpdated(catalogItem.id.toString))
_ <- descriptor.interface.traverse(interface =>
catalogManagementService
.deleteEServiceDocument(catalogItem.id.toString, descriptor.id.toString, interface.id.toString)
)
} yield ()
else Future.unit
if (catalogItem.technology.toApi != newTechnology) {
val descriptorAndInterface =
catalogItem.descriptors.find(_.state == Draft).flatMap(d => d.interface.map(i => (d, i)))
descriptorAndInterface.fold(Future.unit)(di =>
catalogManagementService.deleteEServiceDocument(catalogItem.id.toString, di._1.id.toString, di._2.id.toString)
)
} else Future.unit
}

private def deleteRiskAnalysisOnModeUpdate(newMode: EServiceMode, catalogItem: CatalogItem)(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,20 +962,24 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString)

val eService = SpecData.eService.copy(descriptors = Seq.empty, producerId = requesterId)
val eService = SpecData.eService.copy(
descriptors = Seq.empty,
producerId = requesterId,
technology = CatalogManagementDependency.EServiceTechnology.REST
)

val eServiceSeed =
UpdateEServiceSeed(
name = "newName",
description = "newDescription",
technology = EServiceTechnology.REST,
technology = EServiceTechnology.SOAP,
mode = EServiceMode.DELIVER
)

val updatedEServiceSeed = CatalogManagementDependency.UpdateEServiceSeed(
name = "newName",
description = "newDescription",
technology = eService.technology,
technology = CatalogManagementDependency.EServiceTechnology.SOAP,
mode = eService.mode
)

Expand All @@ -984,7 +988,7 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
producerId = requesterId,
name = "newName",
description = "newDescription",
technology = eService.technology,
technology = CatalogManagementDependency.EServiceTechnology.SOAP,
descriptors = Seq.empty,
riskAnalysis = Seq.empty,
mode = eService.mode
Expand Down Expand Up @@ -1200,70 +1204,6 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
status shouldEqual StatusCodes.NotFound
}
}
"fail when technology has changed in case of no descriptors" in {
val requesterId = UUID.randomUUID()

implicit val context: Seq[(String, String)] =
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString)

val eService = SpecData.catalogItem.copy(descriptors = Seq.empty, producerId = requesterId)

val eServiceSeed =
UpdateEServiceSeed(
name = "newName",
description = "newDescription",
technology = EServiceTechnology.SOAP,
mode = EServiceMode.DELIVER
)

val updatedEServiceSeed = CatalogManagementDependency.UpdateEServiceSeed(
name = "newName",
description = "newDescription",
technology = CatalogManagementDependency.EServiceTechnology.SOAP,
mode = CatalogManagementDependency.EServiceMode.DELIVER
)

(mockCatalogManagementService
.getEServices(
_: UUID,
_: Option[String],
_: Seq[UUID],
_: Seq[UUID],
_: Seq[UUID],
_: Seq[CatalogDescriptorState],
_: Option[CatalogItemMode],
_: Int,
_: Int,
_: Boolean
)(_: ExecutionContext, _: ReadModelService, _: Seq[(String, String)]))
.expects(
requesterId,
Some(updatedEServiceSeed.name),
Seq.empty,
Seq(requesterId),
Seq.empty,
Seq.empty,
None,
0,
1,
true,
*,
*,
context
)
.once()
.returns(Future.successful(PaginatedResult(results = Seq.empty, 0)))

(mockCatalogManagementService
.getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService))
.expects(eService.id, *, *)
.once()
.returns(Future.successful(eService))

Put() ~> service.updateEServiceById(eService.id.toString, eServiceSeed) ~> check {
status shouldEqual StatusCodes.BadRequest
}
}
"fail when technology has changed in case of multiple descriptors" in {
val requesterId = UUID.randomUUID()

Expand Down

0 comments on commit 912869a

Please sign in to comment.