Skip to content
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
9 changes: 9 additions & 0 deletions apps/institution-ms/app/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3396,6 +3396,9 @@
"title" : "InstitutionFromIpaPost",
"type" : "object",
"properties" : {
"businessRegisterPlace" : {
"type" : "string"
},
"geographicTaxonomies" : {
"type" : "array",
"items" : {
Expand All @@ -3406,6 +3409,12 @@
"type" : "string",
"enum" : [ "AS", "CON", "GPU", "GSP", "PA", "PG", "PRV", "PRV_PF", "PSP", "PT", "REC", "SA", "SCEC", "SCP" ]
},
"rea" : {
"type" : "string"
},
"shareCapital" : {
"type" : "string"
},
"subunitCode" : {
"type" : "string"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ Feature: Institution
| attributes[0].code | L6 |
| attributes[0].description | Comuni e loro Consorzi e Associazioni |
And The response body contains field "id"
And The response body doesn't contain field "rea"
And The response body doesn't contain field "shareCapital"
And The response body doesn't contain field "businessRegisterPlace"
# UPDATE
Given User login with username "j.doe" and password "test"
And The following request body:
Expand Down Expand Up @@ -292,6 +295,117 @@ Feature: Institution
| attributes[0].code | L6 |
| attributes[0].description | Comuni e loro Consorzi e Associazioni |
And The response body contains field "id"
And The response body doesn't contain field "rea"
And The response body doesn't contain field "shareCapital"
And The response body doesn't contain field "businessRegisterPlace"

@RemoveInstitutionIdAfterScenario
@only
Scenario: Successfully create and update simple institution from IPA with rea, shareCapital and businessRegisterPlace
# CREATE
Given User login with username "j.doe" and password "test"
And The following request body:
"""
{
"taxCode": "00297110389",
"description": "Test description",
"geographicTaxonomies": [
{
"code": "1",
"desc": "first geo"
},
{
"code": "2",
"desc": "second geo"
}
],
"institutionType": "PA",
"supportEmail": "supportmail@test.com",
"supportPhone": "0000000000",
"rea": "RM-12345",
"shareCapital": "9999",
"businessRegisterPlace": "business register place"
}
"""
When I send a POST request to "/institutions/from-ipa"
Then The status code is 201
And The response body contains the list "geographicTaxonomies" of size 2
And The response body contains the list "attributes" of size 1
And The response body contains:
| externalId | 00297110389 |
| taxCode | 00297110389 |
| origin | IPA |
| originId | c_d548 |
| istatCode | 038008 |
| digitalAddress | comune.ferrara@cert.comune.fe.it |
| zipCode | 44121 |
| city | FERRARA |
| county | FE |
| country | IT |
| supportEmail | supportmail@test.com |
| supportPhone | 0000000000 |
| description | Comune di Ferrara |
| rea | RM-12345 |
| shareCapital | 9999 |
| businessRegisterPlace | business register place |
| geographicTaxonomies[0].code | 1 |
| geographicTaxonomies[0].desc | first geo |
| geographicTaxonomies[1].code | 2 |
| geographicTaxonomies[1].desc | second geo |
| attributes[0].origin | IPA |
| attributes[0].code | L6 |
| attributes[0].description | Comuni e loro Consorzi e Associazioni |
And The response body contains field "id"
# UPDATE
Given User login with username "j.doe" and password "test"
And The following request body:
"""
{
"taxCode": "00297110389",
"description": "Test description",
"geographicTaxonomies": [
{
"code": "2",
"desc": "second geo"
}
],
"institutionType": "PA",
"supportEmail": "updatedsupportmail@test.com",
"supportPhone": "1111111111",
"rea": "RM-12346",
"shareCapital": "1000",
"businessRegisterPlace": "business register place 1"
}
"""
When I send a POST request to "/institutions/from-ipa"
Then The status code is 201
And The response body contains the list "geographicTaxonomies" of size 2
And The response body contains the list "attributes" of size 1
And The response body contains:
| externalId | 00297110389 |
| taxCode | 00297110389 |
| origin | IPA |
| originId | c_d548 |
| istatCode | 038008 |
| digitalAddress | comune.ferrara@cert.comune.fe.it |
| zipCode | 44121 |
| city | FERRARA |
| county | FE |
| country | IT |
| supportEmail | updatedsupportmail@test.com |
| supportPhone | 1111111111 |
| description | Comune di Ferrara |
| rea | RM-12346 |
| shareCapital | 1000 |
| businessRegisterPlace | business register place 1 |
| geographicTaxonomies[0].code | 1 |
| geographicTaxonomies[0].desc | first geo |
| geographicTaxonomies[1].code | 2 |
| geographicTaxonomies[1].desc | second geo |
| attributes[0].origin | IPA |
| attributes[0].code | L6 |
| attributes[0].description | Comuni e loro Consorzi e Associazioni |
And The response body contains field "id"

@RemoveSubunitAndParentInstitutionAfterScenario
Scenario: Successfully create and update AOO institution from IPA
Expand Down Expand Up @@ -349,6 +463,9 @@ Feature: Institution
| rootParent.description | Comune di Ferrara |
And The response body contains field "id"
And The response body contains field "rootParent.id"
And The response body doesn't contain field "rea"
And The response body doesn't contain field "shareCapital"
And The response body doesn't contain field "businessRegisterPlace"
# UPDATE
Given User login with username "j.doe" and password "test"
And The following request body:
Expand Down Expand Up @@ -398,6 +515,9 @@ Feature: Institution
| rootParent.description | Comune di Ferrara |
And The response body contains field "id"
And The response body contains field "rootParent.id"
And The response body doesn't contain field "rea"
And The response body doesn't contain field "shareCapital"
And The response body doesn't contain field "businessRegisterPlace"

@RemoveSubunitAndParentInstitutionAfterScenario
Scenario: Successfully create and update UO institution from IPA
Expand Down Expand Up @@ -454,6 +574,9 @@ Feature: Institution
| rootParent.description | Comune di Ferrara |
And The response body contains field "id"
And The response body contains field "rootParent.id"
And The response body doesn't contain field "rea"
And The response body doesn't contain field "shareCapital"
And The response body doesn't contain field "businessRegisterPlace"
# UPDATE
Given User login with username "j.doe" and password "test"
And The following request body:
Expand Down Expand Up @@ -504,6 +627,9 @@ Feature: Institution
| rootParent.description | Comune di Ferrara |
And The response body contains field "id"
And The response body contains field "rootParent.id"
And The response body doesn't contain field "rea"
And The response body doesn't contain field "shareCapital"
And The response body doesn't contain field "businessRegisterPlace"

Scenario: Bad request with null taxCode creating institution from IPA
Given User login with username "j.doe" and password "test"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.pagopa.selfcare.mscore.model.institution;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class InstitutionAdditionalInfoForIpa {
private String rea;
private String shareCapital;
private String businessRegisterPlace;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface InstitutionService {

List<Institution> getInstitutions(String taxCode, String subunitCode);

Institution createInstitutionFromIpa(String taxCode, InstitutionPaSubunitType subunitType, String subunitCode, List<InstitutionGeographicTaxonomies> geographicTaxonomies, String supportEmail, String supportPhone);
Institution createInstitutionFromIpa(String taxCode, InstitutionPaSubunitType subunitType, String subunitCode, List<InstitutionGeographicTaxonomies> geographicTaxonomies, String supportEmail, String supportPhone, InstitutionAdditionalInfoForIpa additionalInfoForIpa);

Institution createInstitutionFromPda(Institution institution, String injectionInstitutionType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public List<Institution> getInstitutions(String taxCode, String subunitCode, Str
}

@Override
public Institution createInstitutionFromIpa(String taxCode, InstitutionPaSubunitType subunitType, String subunitCode, List<InstitutionGeographicTaxonomies> geographicTaxonomies, String supportEmail, String supportPhone) {
public Institution createInstitutionFromIpa(String taxCode, InstitutionPaSubunitType subunitType, String subunitCode, List<InstitutionGeographicTaxonomies> geographicTaxonomies, String supportEmail, String supportPhone, InstitutionAdditionalInfoForIpa additionalInfoForIpa) {
CreateInstitutionStrategy institutionStrategy = createInstitutionStrategyFactory.createInstitutionStrategyIpa();
return institutionStrategy.createInstitution(CreateInstitutionStrategyInput.builder()
.taxCode(taxCode)
Expand All @@ -122,6 +122,9 @@ public Institution createInstitutionFromIpa(String taxCode, InstitutionPaSubunit
.geographicTaxonomies(geographicTaxonomies)
.supportEmail(supportEmail)
.supportPhone(supportPhone)
.rea(additionalInfoForIpa.getRea())
.shareCapital(additionalInfoForIpa.getShareCapital())
.businessRegisterPlace(additionalInfoForIpa.getBusinessRegisterPlace())
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ protected static void setContacts(CreateInstitutionStrategyInput strategyInput,
}
}

protected static void setAdditionalDataForIpa(CreateInstitutionStrategyInput strategyInput, Institution toSavedOrUpdate) {
if (strategyInput.getRea() != null) {
toSavedOrUpdate.setRea(strategyInput.getRea());
}

if (strategyInput.getShareCapital() != null) {
toSavedOrUpdate.setShareCapital(strategyInput.getShareCapital());
}

if (strategyInput.getBusinessRegisterPlace() != null) {
toSavedOrUpdate.setBusinessRegisterPlace(strategyInput.getBusinessRegisterPlace());
}
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ public Institution createInstitution(CreateInstitutionStrategyInput strategyInpu
}
toSavedOrUpdate.setGeographicTaxonomies(strategyInput.getGeographicTaxonomies());
setContacts(strategyInput, toSavedOrUpdate);

setAdditionalDataForIpa(strategyInput, toSavedOrUpdate);
} else {
//Institution exists but other fields could be updated
toSavedOrUpdate = institutions.get(0);
setUpdatedFields(strategyInput, institutions.get(0));
setAdditionalDataForIpa(strategyInput, toSavedOrUpdate);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ public class CreateInstitutionStrategyInput {
private String supportPhone;
private String istatCode;
private String legalForm;
private String rea;
private String shareCapital;
private String businessRegisterPlace;
}
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,13 @@ void testGetInstitutionsFails() {
}

/**
* Method under test: {@link InstitutionServiceImpl#createInstitutionFromIpa(String, InstitutionPaSubunitType, String, List, String, String)}
* Method under test: {@link InstitutionServiceImpl#createInstitutionFromIpa(String, InstitutionPaSubunitType, String, List, String, String, InstitutionAdditionalInfoForIpa)}
*/
@Test
void testCreateInstitutionFromIpa() {
when(createInstitutionStrategyFactory.createInstitutionStrategyIpa()).thenReturn(createInstitutionStrategy);
when(createInstitutionStrategy.createInstitution(any())).thenReturn(new Institution());
Institution institution = institutionServiceImpl.createInstitutionFromIpa("id", InstitutionPaSubunitType.AOO,"id", List.of(), "email", "phone");
Institution institution = institutionServiceImpl.createInstitutionFromIpa("id", InstitutionPaSubunitType.AOO,"id", List.of(), "email", "phone", new InstitutionAdditionalInfoForIpa());
assertNotNull(institution);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,15 @@ public ResponseEntity<InstitutionResponse> createInstitutionFromIpa(@RequestBody
.map(geoTaxonomies -> geoTaxonomies.stream().map(institutionResourceMapper::toInstitutionGeographicTaxonomies).toList())
.orElse(List.of());

InstitutionAdditionalInfoForIpa additionalInfoForIpa = InstitutionAdditionalInfoForIpa.builder()
.rea(institutionFromIpaPost.getRea())
.shareCapital(institutionFromIpaPost.getShareCapital())
.businessRegisterPlace(institutionFromIpaPost.getBusinessRegisterPlace())
.build();

Institution saved = institutionService.createInstitutionFromIpa(institutionFromIpaPost.getTaxCode(),
institutionFromIpaPost.getSubunitType(), institutionFromIpaPost.getSubunitCode(), geographicTaxonomies,
institutionFromIpaPost.getSupportEmail(), institutionFromIpaPost.getSupportPhone());
institutionFromIpaPost.getSupportEmail(), institutionFromIpaPost.getSupportPhone(), additionalInfoForIpa);
return ResponseEntity.status(HttpStatus.CREATED).body(institutionResourceMapper.toInstitutionResponse(saved));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public class InstitutionFromIpaPost {
private InstitutionType institutionType;
private String supportEmail;
private String supportPhone;
private String rea;
private String shareCapital;
private String businessRegisterPlace;
}
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void shouldCreateInstitutionFromIpa() throws Exception {
institution.setParentDescription("parentDescription");
institution.setRootParentId("rootParentId");

when(institutionService.createInstitutionFromIpa(any(), any(), any(), any(), any(), any())).thenReturn(institution);
when(institutionService.createInstitutionFromIpa(any(), any(), any(), any(), any(), any(), any())).thenReturn(institution);

//Then
MockHttpServletRequestBuilder requestBuilder = post("/institutions/from-ipa/")
Expand All @@ -398,7 +398,7 @@ void shouldCreateInstitutionFromIpa() throws Exception {

ArgumentCaptor<List<InstitutionGeographicTaxonomies>> captorGeo = ArgumentCaptor.forClass(List.class);
verify(institutionService, times(1))
.createInstitutionFromIpa(any(),any(),any(),captorGeo.capture(), any(), any());
.createInstitutionFromIpa(any(),any(),any(),captorGeo.capture(), any(), any(), any());
assertEquals(institutionFromIpaPost.getGeographicTaxonomies().size(), captorGeo.getValue().size());
assertEquals(geoTaxonomies.getCode(), captorGeo.getValue().get(0).getCode());
assertEquals(geoTaxonomies.getDesc(), captorGeo.getValue().get(0).getDesc());
Expand Down
Loading