Skip to content

Commit

Permalink
Merge pull request #166 from pagopa/adding-new-state
Browse files Browse the repository at this point in the history
feat: Create new Institution without party registry [SELC-1661]
  • Loading branch information
andrea-putzu authored Nov 8, 2022
2 parents 466f54c + 52b49f8 commit 1fd297a
Show file tree
Hide file tree
Showing 8 changed files with 364 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ project/target
target
.idea
.openapi-generator
.bloop
.metals
metals.sbt
.vscode
generated/target
generated/src
client/target
Expand Down
119 changes: 118 additions & 1 deletion src/main/resources/interface-specification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,45 @@ paths:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'/institutions/insert/{externalId}':
post:
tags:
- process
summary: Create an institution using external institution id without fetching data from party-registry
description: Create an institution using external institution id without fetching data from party-registry
operationId: createInstitutionRaw
parameters:
- name: externalId
in: path
description: The externalId of the institution
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/InstitutionSeed'
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Institution'
'404':
description: Invalid externalId supplied
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'409':
description: institution having externalId already exists
content:
application/problem+json:
schema:
$ref: '#/components/schemas/Problem'
'/external/institutions/{externalId}':
get:
security: [{}]
Expand Down Expand Up @@ -1175,7 +1214,7 @@ components:
$ref: '#/components/schemas/OnboardingData'
additionalProperties: false
required:
- person
- userId
- institutions
Product:
type: object
Expand Down Expand Up @@ -1237,12 +1276,50 @@ components:
- SUSPENDED
- DELETED
- REJECTED
- TOBEVALIDATED
ProductState:
type: string
description: Represents the product state
enum:
- PENDING
- ACTIVE
InstitutionSeed:
type: object
properties:
description:
type: string
example: AGENCY X
digitalAddress:
example: [email protected]
format: email
type: string
address:
example: via del campo
type: string
zipCode:
example: 20100
type: string
taxCode:
description: institution tax code
type: string
institutionType:
type: string
description: institution type
example: PA
attributes:
$ref: '#/components/schemas/Attributes'
paymentServiceProvider:
$ref: '#/components/schemas/PaymentServiceProvider'
dataProtectionOfficer:
$ref: '#/components/schemas/DataProtectionOfficer'
required:
- description
- digitalAddress
- address
- zipCode
- taxCode
- attributes
additionalProperties: false
Institution:
type: object
properties:
Expand Down Expand Up @@ -1284,6 +1361,10 @@ components:
example: PA
attributes:
$ref: '#/components/schemas/Attributes'
paymentServiceProvider:
$ref: '#/components/schemas/PaymentServiceProvider'
dataProtectionOfficer:
$ref: '#/components/schemas/DataProtectionOfficer'
required:
- id
- externalId
Expand Down Expand Up @@ -1373,6 +1454,10 @@ components:
taxCode:
description: institution tax code
type: string
paymentServiceProvider:
$ref: '#/components/schemas/PaymentServiceProvider'
dataProtectionOfficer:
$ref: '#/components/schemas/DataProtectionOfficer'
Billing:
type: object
properties:
Expand Down Expand Up @@ -1444,6 +1529,38 @@ components:
additionalProperties: false
required:
- id
PaymentServiceProvider:
type: object
additionalProperties: false
properties:
abiCode:
type: string
description: 'ABI Code'
businessRegisterNumber:
type: string
description: 'ID Registration Number on Business Register'
legalRegisterName:
type: string
description: 'Chairman name on Business Register'
legalRegisterNumber:
type: string
description: 'Chairman ID on Business Register'
vatNumberGroup:
type: boolean
description: 'true when vat number identify a group'
DataProtectionOfficer:
type: object
additionalProperties: false
properties:
address:
type: string
description: 'Data protection officer address'
email:
type: string
description: 'Data protection officer email'
pec:
type: string
description: 'Data protection officer digital address'
securitySchemes:
bearerAuth:
type: http
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ object InstitutionConverter {
taxCode = institution.taxCode,
institutionType = institution.institutionType,
origin = institution.origin,
attributes = institution.attributes.map(AttributeConverter.dependencyToApi)
attributes = institution.attributes.map(AttributeConverter.dependencyToApi),
paymentServiceProvider = None,
dataProtectionOfficer = None
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ object Conversions {

def relationshipStateToApi(status: PartyManagementDependency.RelationshipState): RelationshipState =
status match {
case PartyManagementDependency.RelationshipState.PENDING => RelationshipState.PENDING
case PartyManagementDependency.RelationshipState.ACTIVE => RelationshipState.ACTIVE
case PartyManagementDependency.RelationshipState.SUSPENDED => RelationshipState.SUSPENDED
case PartyManagementDependency.RelationshipState.DELETED => RelationshipState.DELETED
case PartyManagementDependency.RelationshipState.REJECTED => RelationshipState.REJECTED
case PartyManagementDependency.RelationshipState.PENDING => RelationshipState.PENDING
case PartyManagementDependency.RelationshipState.ACTIVE => RelationshipState.ACTIVE
case PartyManagementDependency.RelationshipState.SUSPENDED => RelationshipState.SUSPENDED
case PartyManagementDependency.RelationshipState.DELETED => RelationshipState.DELETED
case PartyManagementDependency.RelationshipState.REJECTED => RelationshipState.REJECTED
case PartyManagementDependency.RelationshipState.TOBEVALIDATED => RelationshipState.TOBEVALIDATED
}

def relationshipProductToApi(product: RelationshipProduct): ProductInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ object ProcessApiMarshallerImpl extends ProcessApiMarshaller with SprayJsonSuppo
override implicit def toEntityMarshallerInstitution: ToEntityMarshaller[Institution] =
sprayJsonMarshaller[Institution]

// override implicit def toEntityMarshallerInstitutionSeed: ToEntityMarshaller[InstitutionSeed] = sprayJsonMarshaller[InstitutionSeed]

override implicit def toEntityMarshallerOnboardingInfo: ToEntityMarshaller[OnboardingInfo] =
sprayJsonMarshaller[OnboardingInfo]

Expand All @@ -39,6 +41,9 @@ object ProcessApiMarshallerImpl extends ProcessApiMarshaller with SprayJsonSuppo
override implicit def fromEntityUnmarshallerOnboardingUsersRequest: FromEntityUnmarshaller[OnboardingUsersRequest] =
sprayJsonUnmarshaller[OnboardingUsersRequest]

override implicit def fromEntityUnmarshallerInstitutionSeed: FromEntityUnmarshaller[InstitutionSeed] =
sprayJsonUnmarshaller[InstitutionSeed]

override implicit def toEntityMarshallerProblem: ToEntityMarshaller[Problem] = sprayJsonMarshaller[Problem]

override implicit def toEntityMarshallerRelationshipInfoarray: ToEntityMarshaller[Seq[RelationshipInfo]] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import it.pagopa.interop.partyprocess.api.converters.partymanagement.Institution
import it.pagopa.interop.partyprocess.api.impl.Conversions._
import it.pagopa.interop.partyprocess.common.system.ApplicationConfiguration
import it.pagopa.interop.partyprocess.error.PartyProcessErrors._
import it.pagopa.interop.partyprocess.model._
import it.pagopa.interop.partyprocess.model.{InstitutionSeed, _}
import it.pagopa.interop.partyprocess.service._
import it.pagopa.userreg.client.model.UserId

Expand Down Expand Up @@ -59,7 +59,7 @@ class ProcessApiServiceImpl(
productName: String,
onboardingMailParameters: Map[String, String]
)(implicit contexts: Seq[(String, String)]): Future[Unit] = {
mailer.sendMail(mailTemplate.copy(subject = s"${productName}: Accordo di Adesione"))(
mailer.sendMail(mailTemplate.copy(subject = s"$productName: Accordo di Adesione"))(
addresses,
s"${productName}_accordo_adesione.pdf",
file,
Expand Down Expand Up @@ -140,7 +140,7 @@ class ProcessApiServiceImpl(
productRoles = Seq.empty
)(bearer)
onboardingData <- Future.traverse(relationships.items)(getOnboardingDataDetails(bearer))
} yield OnboardingInfo(Option(userId), onboardingData)
} yield OnboardingInfo(userId, onboardingData)

onComplete(result) {
case Success(res) => getOnboardingInfo200(res)
Expand Down Expand Up @@ -746,6 +746,30 @@ class ProcessApiServiceImpl(
_ = logger.info("institution created {}", institution.externalId)
} yield institution

private def createInstitutionInnerRaw(externalId: String, institutionSeed: InstitutionSeed)(implicit
bearer: String,
contexts: Seq[(String, String)]
): Future[PartyManagementDependency.Institution] = {
val seed = PartyManagementDependency.InstitutionSeed(
externalId = externalId,
originId = "SELC",
description = institutionSeed.description,
digitalAddress = institutionSeed.digitalAddress,
taxCode = institutionSeed.taxCode,
attributes =
institutionSeed.attributes.map(a => PartyManagementDependency.Attribute(a.origin, a.code, a.description)),
address = institutionSeed.address,
zipCode = institutionSeed.zipCode,
institutionType = institutionSeed.institutionType,
origin = s"${institutionSeed.institutionType.getOrElse("SELC")}_${externalId}"
)

for {
institution <- partyManagementService.createInstitution(seed)(bearer)
_ = logger.info("institution created {}", institution.externalId)
} yield institution
}

/** Code: 204, Message: Successful operation
* Code: 400, Message: Invalid id supplied, DataType: Problem
* Code: 404, Message: Not found, DataType: Problem
Expand Down Expand Up @@ -992,6 +1016,39 @@ class ProcessApiServiceImpl(
}
}

/**
* Code: 201, Message: successful operation, DataType: Institution
* Code: 404, Message: Invalid externalId supplied, DataType: Problem
* Code: 409, Message: institution having externalId already exists, DataType: Problem
*/
override def createInstitutionRaw(externalId: String, institutionSeed: InstitutionSeed)(implicit
toEntityMarshallerInstitution: ToEntityMarshaller[Institution],
toEntityMarshallerProblem: ToEntityMarshaller[Problem],
contexts: Seq[(String, String)]
): Route = {
logger.info(s"Creating institution having external id $externalId")
val result = for {
bearer <- getFutureBearer(contexts)
institution <- createInstitutionInnerRaw(externalId, institutionSeed)(bearer, contexts)
} yield institution

onComplete(result) {
case Success(institution) => createInstitutionRaw200(InstitutionConverter.dependencyToApi(institution))
case Failure(ex: ResourceNotFoundError) =>
logger.error(s"Institution having externalId $externalId not exists in registry", ex)
val errorResponse: Problem = problemOf(StatusCodes.NotFound, CreateInstitutionNotFound)
complete(errorResponse.status, errorResponse)
case Failure(ex: ResourceConflictError) =>
logger.error(s"Institution having externalId $externalId already exists", ex)
val errorResponse: Problem = problemOf(StatusCodes.Conflict, CreateInstitutionConflict)
complete(errorResponse.status, errorResponse)
case Failure(ex) =>
logger.error(s"Error while creating institution having external id $externalId", ex)
val errorResponse: Problem = problemOf(StatusCodes.InternalServerError, CreateInstitutionError)
complete(errorResponse.status, errorResponse)
}
}

/**
* Code: 200, Message: successful operation, DataType: Seq[RelationshipInfo]
* Code: 400, Message: Invalid institution id supplied, DataType: Problem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import spray.json.{DefaultJsonProtocol, RootJsonFormat}

package object impl extends DefaultJsonProtocol {

implicit val institutionUpdateFormat: RootJsonFormat[InstitutionUpdate] = jsonFormat6(InstitutionUpdate)
implicit val billingFormat: RootJsonFormat[Billing] = jsonFormat3(Billing)
implicit val tokenChecksumFormat: RootJsonFormat[TokenChecksum] = jsonFormat1(TokenChecksum)
implicit val problemErrorFormat: RootJsonFormat[ProblemError] = jsonFormat2(ProblemError)
implicit val problemFormat: RootJsonFormat[Problem] = jsonFormat5(Problem)
implicit val userFormat: RootJsonFormat[User] = jsonFormat7(User)
implicit val paymentServiceProviderDataFormat: RootJsonFormat[PaymentServiceProvider] = jsonFormat5(
PaymentServiceProvider
)
implicit val dataProtectionOfficerDataFormat: RootJsonFormat[DataProtectionOfficer] = jsonFormat3(
DataProtectionOfficer
)
implicit val institutionUpdateFormat: RootJsonFormat[InstitutionUpdate] = jsonFormat8(InstitutionUpdate)
implicit val billingFormat: RootJsonFormat[Billing] = jsonFormat3(Billing)
implicit val tokenChecksumFormat: RootJsonFormat[TokenChecksum] = jsonFormat1(TokenChecksum)
implicit val problemErrorFormat: RootJsonFormat[ProblemError] = jsonFormat2(ProblemError)
implicit val problemFormat: RootJsonFormat[Problem] = jsonFormat5(Problem)
implicit val userFormat: RootJsonFormat[User] = jsonFormat7(User)
implicit val onboardingContractFormat: RootJsonFormat[OnboardingContract] = jsonFormat2(OnboardingContract)

implicit val onboardingInstitutionRequestFormat: RootJsonFormat[OnboardingInstitutionRequest] =
Expand All @@ -28,7 +34,8 @@ package object impl extends DefaultJsonProtocol {
jsonFormat3(OnboardingUsersRequest)

implicit val attributeDataFormat: RootJsonFormat[Attribute] = jsonFormat3(Attribute)
implicit val institutionFormat: RootJsonFormat[Institution] = jsonFormat11(Institution)
implicit val institutionFormat: RootJsonFormat[Institution] = jsonFormat13(Institution)
implicit val institutionSeedFormat: RootJsonFormat[InstitutionSeed] = jsonFormat9(InstitutionSeed)
implicit val productInfoDataFormat: RootJsonFormat[ProductInfo] = jsonFormat3(ProductInfo)
implicit val onboardingDataFormat: RootJsonFormat[OnboardingData] = jsonFormat16(OnboardingData)
implicit val onboardingInfoFormat: RootJsonFormat[OnboardingInfo] = jsonFormat2(OnboardingInfo)
Expand Down
Loading

0 comments on commit 1fd297a

Please sign in to comment.