Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bubble up fixes for documentUpload #304

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ final case class EServicesApiServiceImpl(
toEntityMarshallerCreatedEServiceDescriptor: ToEntityMarshaller[CreatedEServiceDescriptor]
): Route = {
val result: Future[CreatedEServiceDescriptor] = catalogProcessService
.createEService(eServiceSeed.toProcess)(contexts, ec)
.createEService(eServiceSeed.toProcess)(contexts)
.map(eservice => eservice.toApiWithDescriptorId(eservice.descriptors.head.id))

onComplete(result) {
Expand Down Expand Up @@ -1258,18 +1258,17 @@ final case class EServicesApiServiceImpl(
}
.flatMap(_ => pollEServiceById(catalogProcessService.getEServiceById(eService.id), _.riskAnalysis.nonEmpty))
}

descriptor = eService.descriptors.head
_ <- importedEservice.descriptor.interface match {
_ <- importedEservice.descriptor.interface match {
case Some(interface) =>
verifyAndCreateImportedDoc(eService, descriptor, folderPath, interface, "INTERFACE")
case None => Future.unit
}
_ <- pollEServiceById(
_ <- pollEServiceById(
catalogProcessService.getEServiceById(eService.id),
_.descriptors.exists(d => d.id == descriptor.id && d.interface.isDefined)
)
_ <- importedEservice.descriptor.docs
_ <- importedEservice.descriptor.docs
.traverse(doc =>
verifyAndCreateImportedDoc(eService, descriptor, folderPath, doc, "DOCUMENT")
.flatMap(_ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ import it.pagopa.interop.agreementprocess.client.{model => AgreementProcess}
import it.pagopa.interop.attributeregistryprocess.client.model.Attribute
import it.pagopa.interop.attributeregistryprocess.client.{model => AttributeRegistry}
import it.pagopa.interop.backendforfrontend.common.system.{ApplicationConfiguration, FileManagerUtils}
import it.pagopa.interop.backendforfrontend.error.BFFErrors.{
CreateDocumentBadRequest,
CreateDocumentUnexpectedError,
InvalidInterfaceFileDetected,
SamlNotValid
}
import it.pagopa.interop.backendforfrontend.error.BFFErrors.{InvalidInterfaceFileDetected, SamlNotValid}
import it.pagopa.interop.backendforfrontend.model._
import it.pagopa.interop.backendforfrontend.service.CatalogProcessService
import it.pagopa.interop.backendforfrontend.service.types.CatalogProcessServiceTypes.DocumentKindWrapper
Expand Down Expand Up @@ -299,12 +294,9 @@ object Utils {
serverUrls = serverUrls
)
)
.recoverWith {
case ex: CreateDocumentBadRequest =>
fileManager.delete(ApplicationConfiguration.eServiceDocumentsContainer)(filePath)
Future.failed(ex)
case ex: CreateDocumentUnexpectedError =>
Future.failed(ex)
.recoverWith { case ex: Throwable =>
fileManager.delete(ApplicationConfiguration.eServiceDocumentsContainer)(filePath)
Future.failed(ex)
}
} yield ()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,6 @@ object BFFErrors {
final case class InstitutionNotFound(selfcareId: UUID)
extends ComponentError("0033", s"Institution $selfcareId not found")

final case class CreateDocumentBadRequest(eServiceId: UUID, descriptorId: UUID)
extends ComponentError(
"0034",
s"Bad request creating document metadata for Eservice $eServiceId and descriptor $descriptorId"
)

final case class CreateDocumentUnexpectedError(eServiceId: UUID, descriptorId: UUID, filePath: String)
extends ComponentError(
"0035",
s"Unexpected error creating document metadata for Eservice $eServiceId and descriptor $descriptorId with path $filePath"
)

final case class ContractException(agreementId: String)
extends ComponentError("0036", s"Contract exception for agreement $agreementId")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ object Handlers {
case Failure(err: UnknownTenantOrigin) => badRequest(err, logMessage, headers)
case Failure(err: InvalidInterfaceContentTypeDetected) => badRequest(err, logMessage, headers)
case Failure(err: InvalidInterfaceFileDetected) => badRequest(err, logMessage, headers)
case Failure(err: CreateDocumentBadRequest) => badRequest(err, logMessage, headers)
case Failure(err: NotValidDescriptor) => badRequest(err, logMessage)
case Failure(err: InvalidZipStructure) => badRequest(err, logMessage, headers)
case Failure(err: InvalidEServiceRequester) => forbidden(err, logMessage, headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ trait CatalogProcessService {
contexts: Seq[(String, String)]
): Future[EService]

def createEService(
eServiceSeed: EServiceSeed
)(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[EService]
def createEService(eServiceSeed: EServiceSeed)(implicit contexts: Seq[(String, String)]): Future[EService]

def activateDescriptor(eServiceId: UUID, descriptorId: UUID)(implicit contexts: Seq[(String, String)]): Future[Unit]

Expand Down Expand Up @@ -66,9 +64,7 @@ trait CatalogProcessService {
): Future[Unit]

def createEServiceDocument(eServiceId: UUID, descriptorId: UUID, documentSeed: CreateEServiceDescriptorDocumentSeed)(
implicit
contexts: Seq[(String, String)],
ec: ExecutionContext
implicit contexts: Seq[(String, String)]
): Future[EService]

def getEServiceDocumentById(eServiceId: UUID, descriptorId: UUID, documentId: UUID)(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import akka.actor.typed.ActorSystem
import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit}
import it.pagopa.interop.backendforfrontend.service.CatalogProcessService
import it.pagopa.interop.catalogprocess.client.api.{EnumsSerializers, ProcessApi}
import it.pagopa.interop.catalogprocess.client.invoker.{ApiError, ApiInvoker, ApiRequest, BearerToken}
import it.pagopa.interop.catalogprocess.client.invoker.{ApiInvoker, ApiRequest, BearerToken}
import it.pagopa.interop.catalogprocess.client.model._
import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog}
import it.pagopa.interop.commons.utils.withHeaders
import it.pagopa.interop.backendforfrontend.error.BFFErrors.{
CreateDocumentBadRequest,
CreateDocumentUnexpectedError,
}

import java.util.UUID
import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future}
import scala.concurrent.{ExecutionContextExecutor, Future}

class CatalogProcessServiceImpl(catalogProcessUrl: String, blockingEc: ExecutionContextExecutor)(implicit
system: ActorSystem[_]
Expand All @@ -26,9 +22,7 @@ class CatalogProcessServiceImpl(catalogProcessUrl: String, blockingEc: Execution
private implicit val logger: LoggerTakingImplicit[ContextFieldsToLog] =
Logger.takingImplicit[ContextFieldsToLog](this.getClass)

override def createEService(
eServiceSeed: EServiceSeed
)(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[EService] =
override def createEService(eServiceSeed: EServiceSeed)(implicit contexts: Seq[(String, String)]): Future[EService] =
withHeaders { (bearerToken, correlationId) =>
val request: ApiRequest[EService] =
api.createEService(xCorrelationId = correlationId, eServiceSeed = eServiceSeed)(BearerToken(bearerToken))
Expand Down Expand Up @@ -208,25 +202,19 @@ class CatalogProcessServiceImpl(catalogProcessUrl: String, blockingEc: Execution
eServiceId: UUID,
descriptorId: UUID,
documentSeed: CreateEServiceDescriptorDocumentSeed
)(implicit contexts: Seq[(String, String)], ec: ExecutionContext): Future[EService] = withHeaders {
(bearerToken, correlationId) =>
val request: ApiRequest[EService] =
api.createEServiceDocument(
xCorrelationId = correlationId,
eServiceId = eServiceId,
descriptorId = descriptorId,
createEServiceDescriptorDocumentSeed = documentSeed
)(BearerToken(bearerToken))
invoker
.invoke(
request,
s"Creating eService document ${documentSeed.documentId.toString} of kind ${documentSeed.kind}, name ${documentSeed.fileName}, path ${documentSeed.filePath} for eService $eServiceId and descriptor $descriptorId"
)
.recoverWith {
case err: ApiError[_] if err.code < 500 => Future.failed(CreateDocumentBadRequest(eServiceId, descriptorId))
case err: ApiError[_] if err.code >= 500 =>
Future.failed(CreateDocumentUnexpectedError(eServiceId, descriptorId, documentSeed.filePath))
}
)(implicit contexts: Seq[(String, String)]): Future[EService] = withHeaders { (bearerToken, correlationId) =>
val request: ApiRequest[EService] =
api.createEServiceDocument(
xCorrelationId = correlationId,
eServiceId = eServiceId,
descriptorId = descriptorId,
createEServiceDescriptorDocumentSeed = documentSeed
)(BearerToken(bearerToken))
invoker
.invoke(
request,
s"Creating eService document ${documentSeed.documentId.toString} of kind ${documentSeed.kind}, name ${documentSeed.fileName}, path ${documentSeed.filePath} for eService $eServiceId and descriptor $descriptorId"
)
}
override def updateEServiceById(eServiceId: UUID, updateEServiceSeed: UpdateEServiceSeed)(implicit
contexts: Seq[(String, String)]
Expand Down
Loading