Skip to content

Commit

Permalink
Merge branch '1.0.x' into PIN-4138
Browse files Browse the repository at this point in the history
  • Loading branch information
nttdata-rtorsoli authored Oct 31, 2023
2 parents fe5d446 + 856ad61 commit 60e6fe7
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 17 deletions.
21 changes: 19 additions & 2 deletions src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,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 @@ -1176,7 +1176,7 @@ components:
type: string
format: uuid
riskAnalysisForm:
$ref: '#/components/schemas/RiskAnalysisForm'
$ref: '#/components/schemas/RiskAnalysisFormSeed'
title:
type: string
minLength: 5
Expand Down Expand Up @@ -1230,6 +1230,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,31 @@ final case class PurposeApiServiceImpl(
states != Seq(Draft)
}

def createPurposeSeed(purpose: PersistentPurpose, dailyCalls: Int): 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): PurposeManagementDependency.PurposeSeed =
PurposeManagementDependency.PurposeSeed(
eserviceId = purpose.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 +636,8 @@ final case class PurposeApiServiceImpl(
if (isClonable(purpose)) Future.successful(purpose)
else Future.failed(PurposeCannotBeCloned(purposeId))
dependencySeed = createPurposeSeed(purpose, dailyCalls)
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 @@ -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,6 +82,10 @@ 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,
"answers" -> answers.mkString("\n"),
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.pagopa.interop.purposeprocess

import it.pagopa.interop.catalogmanagement.model.Receive
import it.pagopa.interop.purposemanagement.model.purpose.{
PersistentRiskAnalysisForm,
PersistentRiskAnalysisMultiAnswer,
Expand Down Expand Up @@ -273,6 +274,7 @@ object PDFCreatorSpec {
val eServiceInfo: EServiceInfo =
EServiceInfo(
"EServiceName",
Receive,
"ProducerName",
"ProducerOrigin",
"ProducerIPACode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
consumerId = consumerId,
title = "A title",
description = "A description",
riskAnalysisForm = Some(SpecData.validRiskAnalysis2_0_Private),
riskAnalysisForm = Some(SpecData.validRiskAnalysis2_0_PrivateSeed),
isFreeOfCharge = false,
dailyCalls = 100
)
Expand Down Expand Up @@ -646,7 +646,7 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
consumerId = consumerId,
title = "A title",
description = "A description",
riskAnalysisForm = Some(SpecData.validRiskAnalysis2_0_Private),
riskAnalysisForm = Some(SpecData.validRiskAnalysis2_0_PrivateSeed),
isFreeOfCharge = false,
dailyCalls = 100
)
Expand Down Expand Up @@ -675,7 +675,7 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
consumerId = consumerId,
title = "A title",
description = "A description",
riskAnalysisForm = Some(SpecData.validRiskAnalysis2_0_Private),
riskAnalysisForm = Some(SpecData.validRiskAnalysis2_0_PrivateSeed),
isFreeOfCharge = true,
dailyCalls = 100
)
Expand All @@ -697,7 +697,7 @@ class PurposeApiServiceSpec extends AnyWordSpecLike with SpecHelper with Scalate
Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> consumerId.toString)

val incorrectRiskAnalysis =
RiskAnalysisForm(
RiskAnalysisFormSeed(
version = "1.0",
answers = Map("purpose1" -> List("purpose"), "usesPersonalData" -> List("YES"))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ object SpecData {
)
)

val validRiskAnalysis2_0_PrivateSeed: RiskAnalysisFormSeed =
RiskAnalysisFormSeed(validRiskAnalysis2_0_Private.version, answers = validRiskAnalysis2_0_Private.answers)

val validOnlySchemaRiskAnalysis2_0: RiskAnalysisForm = RiskAnalysisForm(
version = "3.0",
answers = Map(
Expand Down

0 comments on commit 60e6fe7

Please sign in to comment.