Skip to content

Commit

Permalink
Merge branch '1.0.x' into PIN-4061
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli committed Nov 1, 2023
2 parents baeaf1f + 8b75279 commit b5b77ad
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 102 deletions.
44 changes: 19 additions & 25 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ paths:
/purposes:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
get:
tags:
- purpose
Expand Down Expand Up @@ -152,11 +151,9 @@ paths:
/reverse/purposes:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
post:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
tags:
- purpose
operationId: createPurposeFromEService
Expand Down Expand Up @@ -195,7 +192,6 @@ paths:
/reverse/purposes/{id}:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: id
in: path
description: the purpose id
Expand All @@ -206,7 +202,6 @@ paths:
post:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
tags:
- purpose
operationId: updateReversePurpose
Expand All @@ -233,7 +228,6 @@ paths:
/purposes/{id}:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: id
in: path
description: the purpose id
Expand Down Expand Up @@ -268,7 +262,6 @@ paths:
post:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
tags:
- purpose
operationId: updatePurpose
Expand All @@ -295,7 +288,6 @@ paths:
delete:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
tags:
- purpose
operationId: deletePurpose
Expand Down Expand Up @@ -324,7 +316,6 @@ paths:
/purposes/{purposeId}/versions:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: purposeId
in: path
description: the purpose id
Expand Down Expand Up @@ -359,7 +350,6 @@ paths:
/purposes/{purposeId}/versions/{versionId}:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: purposeId
in: path
required: true
Expand Down Expand Up @@ -396,7 +386,6 @@ paths:
/purposes/{purposeId}/versions/{versionId}/documents/{documentId}:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
get:
security:
- bearerAuth: []
Expand Down Expand Up @@ -460,7 +449,6 @@ paths:
/purposes/{purposeId}/versions/{versionId}/activate:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: purposeId
in: path
required: true
Expand Down Expand Up @@ -501,7 +489,6 @@ paths:
/purposes/{purposeId}/clone:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: purposeId
in: path
required: true
Expand Down Expand Up @@ -548,7 +535,6 @@ paths:
/purposes/{purposeId}/versions/{versionId}/suspend:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: purposeId
in: path
required: true
Expand Down Expand Up @@ -589,7 +575,6 @@ paths:
/purposes/{purposeId}/versions/{versionId}/archive:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: purposeId
in: path
required: true
Expand Down Expand Up @@ -630,7 +615,6 @@ paths:
/purposes/{purposeId}/versions/{versionId}/update/waitingForApproval:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: purposeId
in: path
required: true
Expand Down Expand Up @@ -682,7 +666,6 @@ paths:
/purposes/riskAnalysis/latest:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: tenantKind
in: query
schema:
Expand Down Expand Up @@ -714,7 +697,6 @@ paths:
/purposes/riskAnalysis/version/{riskAnalysisVersion}:
parameters:
- $ref: '#/components/parameters/CorrelationIdHeader'
- $ref: '#/components/parameters/IpAddress'
- name: riskAnalysisVersion
in: path
required: true
Expand Down Expand Up @@ -756,11 +738,6 @@ components:
required: true
schema:
type: string
IpAddress:
in: header
name: X-Forwarded-For
schema:
type: string
schemas:
TenantKind:
type: string
Expand Down Expand Up @@ -1048,7 +1025,7 @@ components:
freeOfChargeReason:
type: string
riskAnalysisForm:
$ref: '#/components/schemas/RiskAnalysisForm'
$ref: '#/components/schemas/RiskAnalysisFormSeed'
dailyCalls:
description: 'maximum number of daily calls that this version can perform.'
type: integer
Expand Down Expand Up @@ -1213,7 +1190,7 @@ components:
type: string
format: uuid
riskAnalysisForm:
$ref: '#/components/schemas/RiskAnalysisForm'
$ref: '#/components/schemas/RiskAnalysisFormSeed'
title:
type: string
minLength: 5
Expand Down Expand Up @@ -1267,6 +1244,23 @@ components:
required:
- version
- answers
RiskAnalysisFormSeed:
type: object
properties:
version:
type: string
minLength: 1
maxLength: 250
answers:
additionalProperties:
type: array
items:
type: string
minLength: 1
maxLength: 250
required:
- version
- answers
Problem:
properties:
type:
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/riskAnalysisTemplate/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ <h1>Analisi del rischio</h1>
<div class="label">Numero chiamate API/giorno</div>
<div class="value">${dailyCalls}</div>
</div>

<div class="item">
<div class="label">L’e-service riceve o eroga dati?</div>
<div class="value">${eServiceMode}</div>
</div>
</div>

<!-- Blocco titolo gratuito -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object Adapters {
.validate(risk.toTemplate, schemaOnlyValidation)(kind.toTemplate)
.leftMap(RiskAnalysisValidationFailed(_))
.toEither
.map(_.toManagement(risk.riskAnalysisId))
.map(_.toManagement(riskAnalysisId = None))
)
} yield Management.PurposeSeed(
eserviceId = seed.eserviceId,
Expand Down Expand Up @@ -199,6 +199,11 @@ object Adapters {
Template.RiskAnalysisForm(version = riskAnalysis.version, answers = riskAnalysis.answers)
}

implicit class RiskAnalysisFormSeedWrapper(private val riskAnalysis: RiskAnalysisFormSeed) extends AnyVal {
def toTemplate: Template.RiskAnalysisForm =
Template.RiskAnalysisForm(version = riskAnalysis.version, answers = riskAnalysis.answers)
}

implicit class TenantKindWrapper(private val kind: TenantKind) extends AnyVal {
def toPersistent: PersistentTenantKind = kind match {
case TenantKind.PA => PersistentTenantKind.PA
Expand Down Expand Up @@ -515,7 +520,7 @@ object Adapters {
.validate(risk.toTemplate, schemaOnlyValidation = schemaOnlyValidation)(kind.toTemplate)
.leftMap(RiskAnalysisValidationFailed(_))
.toEither
.map(_.toManagement(risk.riskAnalysisId))
.map(_.toManagement(riskAnalysisId = None))
)
} yield Management.PurposeUpdateContent(
title = content.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import it.pagopa.interop.purposemanagement.model.purpose.{
Draft,
PersistentPurpose,
PersistentPurposeVersion,
PersistentRiskAnalysisForm,
PersistentRiskAnalysisMultiAnswer,
PersistentRiskAnalysisSingleAnswer,
WaitingForApproval
}
import it.pagopa.interop.catalogmanagement.model.{CatalogItem, Deliver, Receive}
Expand Down Expand Up @@ -576,11 +579,35 @@ final case class PurposeApiServiceImpl(
states != Seq(Draft)
}

def createPurposeSeed(purpose: PersistentPurpose, dailyCalls: Int, eserviceId: UUID): PurposeSeed =
PurposeSeed(
def singleAnswerToSeed(
answer: PersistentRiskAnalysisSingleAnswer
): PurposeManagementDependency.RiskAnalysisSingleAnswerSeed =
PurposeManagementDependency.RiskAnalysisSingleAnswerSeed(key = answer.key, value = answer.value)

def multiAnswerToSeed(
answer: PersistentRiskAnalysisMultiAnswer
): PurposeManagementDependency.RiskAnalysisMultiAnswerSeed =
PurposeManagementDependency.RiskAnalysisMultiAnswerSeed(key = answer.key, values = answer.values)

def riskAnalysisToSeed(
riskAnalysis: PersistentRiskAnalysisForm
): PurposeManagementDependency.RiskAnalysisFormSeed =
PurposeManagementDependency.RiskAnalysisFormSeed(
riskAnalysisId = riskAnalysis.riskAnalysisId,
version = riskAnalysis.version,
singleAnswers = riskAnalysis.singleAnswers.map(singleAnswerToSeed),
multiAnswers = riskAnalysis.multiAnswers.map(multiAnswerToSeed)
)

def createPurposeSeed(
purpose: PersistentPurpose,
dailyCalls: Int,
eserviceId: UUID
): PurposeManagementDependency.PurposeSeed =
PurposeManagementDependency.PurposeSeed(
eserviceId = eserviceId,
consumerId = purpose.consumerId,
riskAnalysisForm = purpose.riskAnalysisForm.map(_.toApi),
riskAnalysisForm = purpose.riskAnalysisForm.map(riskAnalysisToSeed),
title = s"${purpose.title} - clone",
description = purpose.description,
isFreeOfCharge = purpose.isFreeOfCharge,
Expand Down Expand Up @@ -613,11 +640,8 @@ final case class PurposeApiServiceImpl(
if (isClonable(purpose)) Future.successful(purpose)
else Future.failed(PurposeCannotBeCloned(purposeId))
dependencySeed = createPurposeSeed(purpose, dailyCalls, seed.eserviceId)
tenantKind <- tenant.kind.toFuture(TenantKindNotFound(tenant.id))
purposeSeed <- dependencySeed
.toManagement(schemaOnlyValidation = true)(tenantKind)
.toFuture
newPurpose <- purposeManagementService.createPurpose(purposeSeed)
tenantKind <- tenant.kind.toFuture(TenantKindNotFound(tenant.id))
newPurpose <- purposeManagementService.createPurpose(dependencySeed)
isValidRiskAnalysisForm = isRiskAnalysisFormValid(newPurpose.riskAnalysisForm.map(_.toApi))(tenantKind)
} yield newPurpose.toApi(isRiskAnalysisValid = isValidRiskAnalysisForm)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ final case class PurposeVersionActivation(
(producer, consumer) <- getTenant(eService.producerId).zip(getTenant(purpose.consumerId))
eServiceInfo = EServiceInfo(
name = eService.name,
mode = eService.mode,
producerName = producer.name,
producerOrigin = producer.externalId.origin,
producerIPACode = producer.externalId.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package object impl extends SprayJsonSupport with DefaultJsonProtocol {
implicit def agreementFormat: RootJsonFormat[Agreement] = jsonFormat2(Agreement)

implicit def riskAnalysisFormFormat: RootJsonFormat[RiskAnalysisForm] = jsonFormat3(RiskAnalysisForm)
implicit def riskAnalysisFormSeedFormat: RootJsonFormat[RiskAnalysisFormSeed] = jsonFormat2(RiskAnalysisFormSeed)
implicit def purposeVersionDocumentFormat: RootJsonFormat[PurposeVersionDocument] =
jsonFormat4(PurposeVersionDocument)
implicit def purposeFormat: RootJsonFormat[Purpose] = jsonFormat14(Purpose)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package it.pagopa.interop.purposeprocess.model

import it.pagopa.interop.catalogmanagement.model.CatalogItemMode

final case class EServiceInfo(
name: String,
mode: CatalogItemMode,
producerName: String,
producerOrigin: String,
producerIPACode: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ final case class AuthorizationManagementServiceImpl(
override def updateStateOnClients(purposeId: UUID, versionId: UUID, state: ClientComponentState)(implicit
contexts: Seq[(String, String)]
): Future[Unit] =
withHeaders { (bearerToken, correlationId, ip) =>
withHeaders { (bearerToken, correlationId) =>
val request = purposeApi.updatePurposeState(
xCorrelationId = correlationId,
purposeId = purposeId,
clientPurposeDetailsUpdate = ClientPurposeDetailsUpdate(versionId = versionId, state = state),
xForwardedFor = ip
clientPurposeDetailsUpdate = ClientPurposeDetailsUpdate(versionId = versionId, state = state)
)(BearerToken(bearerToken))
// Do not fail because this service should not be blocked by this update
invoker
Expand All @@ -41,11 +40,9 @@ final case class AuthorizationManagementServiceImpl(

override def removePurposeFromClient(purposeId: UUID, clientId: UUID)(implicit
contexts: Seq[(String, String)]
): Future[Unit] = withHeaders { (bearerToken, correlationId, ip) =>
): Future[Unit] = withHeaders { (bearerToken, correlationId) =>
val request =
purposeApi.removeClientPurpose(xCorrelationId = correlationId, clientId, purposeId, xForwardedFor = ip)(
BearerToken(bearerToken)
)
purposeApi.removeClientPurpose(xCorrelationId = correlationId, clientId, purposeId)(BearerToken(bearerToken))
invoker.invoke(request, s"Removing purpose $purposeId from client $clientId")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package it.pagopa.interop.purposeprocess.service.impl

import cats.implicits.toTraverseOps
import com.openhtmltopdf.util.XRLog
import it.pagopa.interop.catalogmanagement.model.{Deliver, Receive}
import it.pagopa.interop.commons.files.model.PDFConfiguration
import it.pagopa.interop.commons.files.service.PDFManager
import it.pagopa.interop.commons.utils.TypeConversions._
Expand Down Expand Up @@ -81,8 +82,12 @@ object PDFCreatorImpl extends PDFCreator with PDFManager {
for {
answers <- sortedAnswers(formConfig, riskAnalysisForm, language)
(freeOfChargeHtml, freeOfChargeReasonHtml) = formatFreeOfCharge(isFreeOfCharge, freeOfChargeReason)
localizedMode = eServiceInfo.mode match {
case Receive => getLocalizedLabel(LocalizedText(it = "Riceve", en = "Receives"), language)
case Deliver => getLocalizedLabel(LocalizedText(it = "Eroga", en = "Delivers"), language)
}
} yield Map(
"dailyCalls" -> dailyCalls.toString,
"dailyCalls" -> dailyCalls.toString,
"answers" -> answers.mkString("\n"),
"eServiceName" -> eServiceInfo.name,
"producerText" -> getDescriptionText(
Expand All @@ -97,7 +102,8 @@ object PDFCreatorImpl extends PDFCreator with PDFManager {
),
"freeOfCharge" -> freeOfChargeHtml,
"freeOfChargeReason" -> freeOfChargeReasonHtml,
"date" -> LocalDateTime.now().format(printedDateFormatter)
"date" -> LocalDateTime.now().format(printedDateFormatter),
"eServiceMode" -> localizedMode
)

def getDescriptionText(name: String, origin: String, value: String): String =
Expand Down
Loading

0 comments on commit b5b77ad

Please sign in to comment.