Skip to content

Commit

Permalink
[SELC-5824] Added parent description for AOO and UO aggregate
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed Oct 24, 2024
1 parent dce29d7 commit 9635995
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 23 deletions.
6 changes: 6 additions & 0 deletions apps/onboarding-ms/src/main/docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,9 @@
"description" : {
"type" : "string"
},
"parentDescription" : {
"type" : "string"
},
"recipientCode" : {
"type" : "string"
},
Expand Down Expand Up @@ -1651,6 +1654,9 @@
"vatNumber" : {
"type" : "string"
},
"parentDescription" : {
"type" : "string"
},
"geographicTaxonomies" : {
"type" : "array",
"items" : {
Expand Down
4 changes: 4 additions & 0 deletions apps/onboarding-ms/src/main/docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,8 @@ components:
type: string
description:
type: string
parentDescription:
type: string
recipientCode:
type: string
users:
Expand Down Expand Up @@ -1207,6 +1209,8 @@ components:
type: string
vatNumber:
type: string
parentDescription:
type: string
geographicTaxonomies:
type: array
items:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class AggregateInstitutionRequest {
private String subunitCode;
private String subunitType;
private String vatNumber;
private String parentDescription;
private List<GeographicTaxonomy> geographicTaxonomies;
private String address;
private String zipCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class AggregateInstitution {
private String description;
private String subunitCode;
private String subunitType;
private String parentDescription;
private List<GeographicTaxonomy> geographicTaxonomies;
private String address;
private String zipCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Aggregate {
private String subunitCode;
private String subunitType;
private String description;
private String parentDescription;
private String recipientCode;
private List<AggregateUser> users;
private String digitalAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,42 +247,46 @@ private Uni<Aggregate> retrieveDataFromIpa(Aggregate aggregate) {
}

private Uni<Aggregate> retrieveCityCountyAndMapIpaFieldForUO(UOResource uoResource, Aggregate aggregateAppIo) {
return retrieveGeographicTaxonomies(uoResource.getCodiceComuneISTAT())
.onItem().transformToUni(geographicTaxonomyResource -> {
mapIpaField(uoResource.getDescrizioneUo(), uoResource.getIndirizzo(), uoResource.getCap(), null, aggregateAppIo, geographicTaxonomyResource);
return retrieveDigitalAddress(uoResource.getTipoMail1(), uoResource.getMail1(), uoResource.getCodiceFiscaleEnte(), aggregateAppIo);
});
return institutionApi.findInstitutionUsingGET(uoResource.getCodiceFiscaleEnte(), null, null)
.onItem().transformToUni(institutionResource ->
retrieveGeographicTaxonomies(uoResource.getCodiceComuneISTAT())
.onItem().transformToUni(geographicTaxonomyResource -> {
mapIpaField(uoResource.getDescrizioneUo(), uoResource.getIndirizzo(), uoResource.getCap(), null, aggregateAppIo, institutionResource.getDescription(), geographicTaxonomyResource);
return retrieveDigitalAddress(uoResource.getTipoMail1(), uoResource.getMail1(), institutionResource, aggregateAppIo);
})
);
}

private Uni<Aggregate> retrieveCityCountyAndMapIpaFieldForAOO(AOOResource aooResource, Aggregate aggregateAppIo) {
return retrieveGeographicTaxonomies(aooResource.getCodiceComuneISTAT())
.onItem().transformToUni(geographicTaxonomyResource -> {
mapIpaField(aooResource.getDenominazioneAoo(), aooResource.getIndirizzo(), aooResource.getCap(), null, aggregateAppIo, geographicTaxonomyResource);
return retrieveDigitalAddress(aooResource.getTipoMail1(), aooResource.getMail1(), aooResource.getCodiceFiscaleEnte(), aggregateAppIo);
});
return institutionApi.findInstitutionUsingGET(aooResource.getCodiceFiscaleEnte(), null, null)
.onItem().transformToUni(institutionResource ->
retrieveGeographicTaxonomies(aooResource.getCodiceComuneISTAT())
.onItem().transformToUni(geographicTaxonomyResource -> {
mapIpaField(aooResource.getDenominazioneAoo(), aooResource.getIndirizzo(), aooResource.getCap(), null, aggregateAppIo, institutionResource.getDescription(),geographicTaxonomyResource);
return retrieveDigitalAddress(aooResource.getTipoMail1(), aooResource.getMail1(), institutionResource, aggregateAppIo);
})
);
}

private Uni<Aggregate> retrieveCityCountyAndMapIpaFieldForPA(InstitutionResource institutionResource, Aggregate aggregateAppIo) {
return retrieveGeographicTaxonomies(institutionResource.getIstatCode())
.onItem().transform(geographicTaxonomyResource -> {
mapIpaField(institutionResource.getDescription(), institutionResource.getAddress(), institutionResource.getZipCode(), institutionResource.getOriginId(), aggregateAppIo, geographicTaxonomyResource);
mapIpaField(institutionResource.getDescription(), institutionResource.getAddress(), institutionResource.getZipCode(), institutionResource.getOriginId(), aggregateAppIo, null, geographicTaxonomyResource);
aggregateAppIo.setDigitalAddress(institutionResource.getDigitalAddress());
return aggregateAppIo;
});
}

private Uni<Aggregate> retrieveDigitalAddress(String mailType, String mail, String taxCode, Aggregate aggregateAppIo) {
private Uni<Aggregate> retrieveDigitalAddress(String mailType, String mail, InstitutionResource institutionResource, Aggregate aggregateAppIo) {
if (Objects.equals(mailType, PEC)) {
aggregateAppIo.setDigitalAddress(mail);
return Uni.createFrom().item(aggregateAppIo);
} else {
return institutionApi.findInstitutionUsingGET(taxCode, null, null)
.onItem().invoke(institutionResource -> aggregateAppIo.setDigitalAddress(institutionResource.getDigitalAddress()))
.replaceWith(aggregateAppIo);
aggregateAppIo.setDigitalAddress(institutionResource.getDigitalAddress());
}
return Uni.createFrom().item(aggregateAppIo);
}

private static void mapIpaField(String description, String address, String zipCode, String originId, Aggregate aggregateAppIo, GeographicTaxonomyFromIstatCode geographicTaxonomyFromIstatCode) {
private static void mapIpaField(String description, String address, String zipCode, String originId, Aggregate aggregateAppIo, String parentDescription ,GeographicTaxonomyFromIstatCode geographicTaxonomyFromIstatCode) {
if(Objects.nonNull(geographicTaxonomyFromIstatCode)) {
aggregateAppIo.setCounty(geographicTaxonomyFromIstatCode.getCounty());
aggregateAppIo.setCity(geographicTaxonomyFromIstatCode.getCity());
Expand All @@ -291,6 +295,7 @@ private static void mapIpaField(String description, String address, String zipCo
aggregateAppIo.setAddress(address);
aggregateAppIo.setZipCode(zipCode);
aggregateAppIo.setOriginId(originId);
aggregateAppIo.setParentDescription(parentDescription);
}

private Uni<GeographicTaxonomyFromIstatCode> retrieveGeographicTaxonomies(String codiceIstat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void onboardingPa() {

@Test
@TestSecurity(user = "userJwt")
void onboardingPaAggregator_withoutVatNumber() {
void onboardingPaAggregator_withoutVatNumberAndParentDescription() {
OnboardingPaRequest onboardingPaValid = dummyOnboardingPa();
onboardingPaValid.setIsAggregator(Boolean.TRUE);
List<AggregateInstitutionRequest> aggregateInstitutions = new ArrayList<>();
Expand All @@ -199,17 +199,19 @@ void onboardingPaAggregator_withoutVatNumber() {
assertEquals(captor.getValue().getBilling().getRecipientCode(), onboardingPaValid.getBilling().getRecipientCode().toUpperCase());
assertTrue(captor.getValue().getIsAggregator());
assertNull(captor.getValue().getAggregates().get(0).getVatNumber());
assertNull(captor.getValue().getAggregates().get(0).getParentDescription());
assertFalse(captor.getValue().getAggregates().isEmpty());
}

@Test
@TestSecurity(user = "userJwt")
void onboardingPaAggregator_WithVatNumber() {
void onboardingPaAggregator_WithVatNumberAndParentDescription() {
OnboardingPaRequest onboardingPaValid = dummyOnboardingPa();
onboardingPaValid.setIsAggregator(Boolean.TRUE);
List<AggregateInstitutionRequest> aggregateInstitutions = new ArrayList<>();
AggregateInstitutionRequest aggregateInstitutionRequest = new AggregateInstitutionRequest();
aggregateInstitutionRequest.setVatNumber("vatNumber");
aggregateInstitutionRequest.setParentDescription("parentDescription");
aggregateInstitutions.add(aggregateInstitutionRequest);
onboardingPaValid.setAggregates(aggregateInstitutions);

Expand All @@ -230,6 +232,7 @@ void onboardingPaAggregator_WithVatNumber() {
assertEquals(captor.getValue().getBilling().getRecipientCode(), onboardingPaValid.getBilling().getRecipientCode().toUpperCase());
assertTrue(captor.getValue().getIsAggregator());
assertNotNull(captor.getValue().getAggregates().get(0).getVatNumber());
assertNotNull(captor.getValue().getAggregates().get(0).getParentDescription());
assertFalse(captor.getValue().getAggregates().isEmpty());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ void testValidateAppIoAggregatesCsv() {
uoResource.setDescrizioneUo("denominazione");
uoResource.setIndirizzo("Palazzo Vecchio Piazza Della Signoria");
uoResource.setCodiceComuneISTAT("123");
uoResource.setCodiceFiscaleEnte("1307110484");

AOOResource aooResource = new AOOResource();
aooResource.setTipoMail1("Altro");
Expand All @@ -91,11 +92,13 @@ void testValidateAppIoAggregatesCsv() {
aooResource.setCodiceFiscaleEnte("1307110484");
aooResource.setIndirizzo("Palazzo Vecchio Piazza Della Signoria");
aooResource.setCodiceComuneISTAT("123");
aooResource.setCodiceFiscaleEnte("1307110484");

InstitutionResource institutionResource = mock(InstitutionResource.class);
when(institutionResource.getIstatCode()).thenReturn("123");
when(institutionResource.getOriginId()).thenReturn("test");
when(institutionResource.getDigitalAddress()).thenReturn("pec@Pec");
when(institutionResource.getDescription()).thenReturn("descrizione ente");

GeographicTaxonomyResource geographicTaxonomyResource = new GeographicTaxonomyResource();
geographicTaxonomyResource.setCode("123");
Expand Down Expand Up @@ -131,7 +134,7 @@ void testValidateAppIoAggregatesCsv() {
verify(geographicTaxonomiesApi, times(1)).retrieveGeoTaxonomiesByCodeUsingGET("123");
verify(aooApi, times(1)).findByUnicodeUsingGET("18SU3R", null);
verify(aooApi, times(1)).findByUnicodeUsingGET("18SU3S", null);
verify(institutionApi, times(2)).findInstitutionUsingGET("1307110484", null, null);
verify(institutionApi, times(3)).findInstitutionUsingGET("1307110484", null, null);

}

Expand Down Expand Up @@ -190,6 +193,7 @@ void validateSendAggregates() {
uoResource.setDescrizioneUo("denominazione");
uoResource.setIndirizzo("Palazzo Vecchio Piazza Della Signoria");
uoResource.setCodiceComuneISTAT("456");
uoResource.setCodiceFiscaleEnte("1307110484");

AOOResource aooResource = new AOOResource();
aooResource.setTipoMail1("Pec");
Expand All @@ -199,10 +203,12 @@ void validateSendAggregates() {
aooResource.setCap("00100");
aooResource.setIndirizzo("Palazzo Vecchio Piazza Della Signoria");
aooResource.setCodiceComuneISTAT("456");
aooResource.setCodiceFiscaleEnte("1307110484");

InstitutionResource institutionResource = mock(InstitutionResource.class);
when(institutionResource.getIstatCode()).thenReturn("456");
when(institutionResource.getOriginId()).thenReturn("test");
when(institutionResource.getDescription()).thenReturn("testDenominazioneEnte");

GeographicTaxonomyResource geographicTaxonomyResource = new GeographicTaxonomyResource();
geographicTaxonomyResource.setCode("456");
Expand Down Expand Up @@ -238,7 +244,7 @@ void validateSendAggregates() {
verify(geographicTaxonomiesApi, times(1)).retrieveGeoTaxonomiesByCodeUsingGET("456");
verify(aooApi, times(1)).findByUnicodeUsingGET("18SU3R", null);
verify(aooApi, times(1)).findByUnicodeUsingGET("18SU3S", null);
verify(institutionApi, times(0)).findInstitutionUsingGET("00297110389", null, null);
verify(institutionApi, times(3)).findInstitutionUsingGET("1307110484", null, null);
}

private static VerifyAggregateResponse mockResponseForIO() {
Expand All @@ -256,6 +262,7 @@ private static VerifyAggregateResponse mockResponseForIO() {
aggregateUO.setZipCode("00100");
aggregateUO.setOrigin("IPA");
aggregateUO.setRowNumber(1);
aggregateUO.setParentDescription("descrizione ente");

Aggregate aggregateAOO = new Aggregate();
aggregateAOO.setSubunitCode("18SU3S");
Expand All @@ -270,11 +277,12 @@ private static VerifyAggregateResponse mockResponseForIO() {
aggregateAOO.setZipCode("00100");
aggregateAOO.setOrigin("IPA");
aggregateAOO.setRowNumber(5);
aggregateAOO.setParentDescription("descrizione ente");

Aggregate aggregate = new Aggregate();
aggregate.setSubunitCode(null);
aggregate.setSubunitType(null);
aggregate.setDescription(null);
aggregate.setDescription("descrizione ente");
aggregate.setDigitalAddress("pec@Pec");
aggregate.setTaxCode("1307110484");
aggregate.setVatNumber("1307110484");
Expand Down Expand Up @@ -356,6 +364,7 @@ private static VerifyAggregateResponse mockResponseForSEND() {
aggregateUO.setRecipientCode("NYJTPK");
aggregateUO.setRowNumber(1);
aggregateUO.setUsers(List.of(aggregateUser));
aggregateUO.setParentDescription("testDenominazioneEnte");

Aggregate aggregateAOO = new Aggregate();
aggregateAOO.setSubunitCode("18SU3S");
Expand All @@ -372,11 +381,12 @@ private static VerifyAggregateResponse mockResponseForSEND() {
aggregateAOO.setOrigin("IPA");
aggregateAOO.setRowNumber(9);
aggregateAOO.setUsers(List.of(aggregateUser));
aggregateAOO.setParentDescription("testDenominazioneEnte");

Aggregate aggregate = new Aggregate();
aggregate.setSubunitCode(null);
aggregate.setSubunitType(null);
aggregate.setDescription(null);
aggregate.setDescription("testDenominazioneEnte");
aggregate.setDigitalAddress(null);
aggregate.setTaxCode("1307110484");
aggregate.setVatNumber("1864440019");
Expand Down

0 comments on commit 9635995

Please sign in to comment.