Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksiybozhykntt committed Jan 17, 2025
1 parent 516dee8 commit c437416
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 126 deletions.
48 changes: 19 additions & 29 deletions openapi/p4pa-pu-bff.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/CollectionModelTaxonomyOrganizationTypeDTO'
type: array
items:
$ref: '#/components/schemas/TaxonomyOrganizationTypeDTO'
'401':
description: Unauthorized - Missing or invalid token
'403':
Expand All @@ -107,9 +109,11 @@ paths:
'200':
description: OK
content:
application/hal+json:
application/json:
schema:
$ref: '#/components/schemas/CollectionModelTaxonomyMacroAreaCodeDTO'
type: array
items:
$ref: '#/components/schemas/TaxonomyMacroAreaCodeDTO'
'401':
description: Unauthorized - Missing or invalid token
'403':
Expand All @@ -134,9 +138,11 @@ paths:
'200':
description: OK
content:
application/hal+json:
application/json:
schema:
$ref: '#/components/schemas/CollectionModelTaxonomyServiceTypeCodeDTO'
type: array
items:
$ref: '#/components/schemas/TaxonomyServiceTypeCodeDTO'
'401':
description: Unauthorized - Missing or invalid token
'403':
Expand Down Expand Up @@ -165,9 +171,11 @@ paths:
'200':
description: OK
content:
application/hal+json:
application/json:
schema:
$ref: '#/components/schemas/CollectionModelTaxonomyCollectionReasonDTO'
type: array
items:
$ref: '#/components/schemas/TaxonomyCollectionReasonDTO'
'401':
description: Unauthorized - Missing or invalid token
'403':
Expand Down Expand Up @@ -200,9 +208,11 @@ paths:
'200':
description: OK
content:
application/hal+json:
application/json:
schema:
$ref: '#/components/schemas/CollectionModelTaxonomyCodeDTO'
type: array
items:
$ref: '#/components/schemas/TaxonomyCodeDTO'
security:
- bearerAuth: [ ]
components:
Expand All @@ -212,10 +222,6 @@ components:
scheme: bearer
bearerFormat: JWT
schemas:
CollectionModelTaxonomyCodeDTO:
type: array
items:
$ref: '#/components/schemas/TaxonomyCodeDTO'
TaxonomyCodeDTO:
type: object
properties:
Expand All @@ -239,10 +245,6 @@ components:
type: string
taxonomyCode:
type: string
CollectionModelTaxonomyCollectionReasonDTO:
type: array
items:
$ref: '#/components/schemas/TaxonomyCollectionReasonDTO'
TaxonomyCollectionReasonDTO:
type: object
properties:
Expand All @@ -264,10 +266,6 @@ components:
type: string
collectionReason:
type: string
CollectionModelTaxonomyServiceTypeCodeDTO:
type: array
items:
$ref: '#/components/schemas/TaxonomyServiceTypeCodeDTO'
TaxonomyServiceTypeCodeDTO:
type: object
properties:
Expand All @@ -287,10 +285,6 @@ components:
type: string
serviceTypeDescription:
type: string
CollectionModelTaxonomyMacroAreaCodeDTO:
type: array
items:
$ref: '#/components/schemas/TaxonomyMacroAreaCodeDTO'
TaxonomyMacroAreaCodeDTO:
type: object
properties:
Expand All @@ -304,10 +298,6 @@ components:
type: string
macroAreaDescription:
type: string
CollectionModelTaxonomyOrganizationTypeDTO:
type: array
items:
$ref: '#/components/schemas/TaxonomyOrganizationTypeDTO'
TaxonomyOrganizationTypeDTO:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,5 @@ public ResponseEntity<ErrorDTO> handleInvalidOperatorRoleException(InvalidOperat
return new ResponseEntity<>(errorDTO, HttpStatus.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(UnparsableEntityException.class)
public ResponseEntity<ErrorDTO> handleUnparsableEntityException(UnparsableEntityException e){
ErrorDTO errorDTO = new ErrorDTO("GENERIC_ERROR", e.getMessage());
return new ResponseEntity<>(errorDTO, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

This file was deleted.

31 changes: 14 additions & 17 deletions src/main/java/it/gov/pagopa/pu/bff/mapper/TaxonomyCodeMapper.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
package it.gov.pagopa.pu.bff.mapper;

import it.gov.pagopa.pu.bff.dto.generated.TaxonomyCodeDTO;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyCodeDTOEmbedded;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class TaxonomyCodeMapper {

public List<TaxonomyCodeDTO> map(CollectionModelTaxonomyCodeDTOEmbedded input) {
return input.getTaxonomyCodeDTOes().stream().map(taxonomyCodeDTO -> {
TaxonomyCodeDTO element = new TaxonomyCodeDTO();
element.setOrganizationTypeDescription(taxonomyCodeDTO.getOrganizationTypeDescription());
element.setOrganizationType(taxonomyCodeDTO.getOrganizationType());
element.setMacroAreaCode(taxonomyCodeDTO.getMacroAreaCode());
element.setMacroAreaName(taxonomyCodeDTO.getMacroAreaName());
element.setMacroAreaDescription(taxonomyCodeDTO.getMacroAreaDescription());
element.setServiceTypeCode(taxonomyCodeDTO.getServiceTypeCode());
element.setServiceType(taxonomyCodeDTO.getServiceType());
element.setServiceTypeDescription(taxonomyCodeDTO.getServiceTypeDescription());
element.setCollectionReason(taxonomyCodeDTO.getCollectionReason());
element.setTaxonomyCode(taxonomyCodeDTO.getTaxonomyCode());
return element;
}).toList();
public TaxonomyCodeDTO map(
it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyCodeDTO input) {
TaxonomyCodeDTO dto = new TaxonomyCodeDTO();
dto.setOrganizationTypeDescription(input.getOrganizationType()+". "+input.getOrganizationTypeDescription());
dto.setOrganizationType(input.getOrganizationType());
dto.setMacroAreaCode(input.getMacroAreaCode());
dto.setMacroAreaName(input.getMacroAreaCode()+". "+input.getMacroAreaName());
dto.setMacroAreaDescription(input.getMacroAreaDescription());
dto.setServiceTypeCode(input.getServiceTypeCode());
dto.setServiceType(input.getServiceTypeCode()+". "+input.getServiceType());
dto.setServiceTypeDescription(input.getServiceTypeDescription());
dto.setCollectionReason(input.getCollectionReason());
dto.setTaxonomyCode(input.getTaxonomyCode());
return dto;
}

}
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
package it.gov.pagopa.pu.bff.mapper;

import it.gov.pagopa.pu.bff.dto.generated.TaxonomyCollectionReasonDTO;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyCollectionReasonDTOEmbedded;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class TaxonomyCollectionReasonMapper {
public List<TaxonomyCollectionReasonDTO> map(CollectionModelTaxonomyCollectionReasonDTOEmbedded input) {
return input.getTaxonomyCollectionReasonDTOes().stream()
.map(taxonomyCodeDTO -> {
TaxonomyCollectionReasonDTO dto = new TaxonomyCollectionReasonDTO();
dto.setOrganizationTypeDescription(taxonomyCodeDTO.getOrganizationTypeDescription());
dto.setOrganizationType(taxonomyCodeDTO.getOrganizationType());
dto.setMacroAreaCode(taxonomyCodeDTO.getMacroAreaCode());
dto.setMacroAreaName(taxonomyCodeDTO.getMacroAreaName());
dto.setMacroAreaDescription(taxonomyCodeDTO.getMacroAreaDescription());
dto.setServiceTypeCode(taxonomyCodeDTO.getServiceTypeCode());
dto.setServiceType(taxonomyCodeDTO.getServiceType());
dto.setServiceTypeDescription(taxonomyCodeDTO.getServiceTypeDescription());
dto.setCollectionReason(taxonomyCodeDTO.getCollectionReason());
return dto;
})
.toList();
public TaxonomyCollectionReasonDTO map(
it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyCollectionReasonDTO input) {
TaxonomyCollectionReasonDTO dto = new TaxonomyCollectionReasonDTO();
dto.setOrganizationTypeDescription(input.getOrganizationType()+". "+input.getOrganizationTypeDescription());
dto.setOrganizationType(input.getOrganizationType());
dto.setMacroAreaCode(input.getMacroAreaCode());
dto.setMacroAreaName(input.getMacroAreaCode()+". "+input.getMacroAreaName());
dto.setMacroAreaDescription(input.getMacroAreaDescription());
dto.setServiceTypeCode(input.getServiceTypeCode());
dto.setServiceType(input.getServiceTypeCode()+". "+input.getServiceType());
dto.setServiceTypeDescription(input.getServiceTypeDescription());
dto.setCollectionReason(input.getCollectionReason());
return dto;
}

}
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package it.gov.pagopa.pu.bff.mapper;

import it.gov.pagopa.pu.bff.dto.generated.TaxonomyMacroAreaCodeDTO;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyMacroAreaCodeDTOEmbedded;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class TaxonomyMacroAreaCodeMapper {
public List<TaxonomyMacroAreaCodeDTO> map(CollectionModelTaxonomyMacroAreaCodeDTOEmbedded input) {
return input.getTaxonomyMacroAreaCodeDTOes().stream()
.map(taxonomyCodeDTO -> {
TaxonomyMacroAreaCodeDTO dto = new TaxonomyMacroAreaCodeDTO();
dto.setOrganizationTypeDescription(taxonomyCodeDTO.getOrganizationTypeDescription());
dto.setOrganizationType(taxonomyCodeDTO.getOrganizationType());
dto.setMacroAreaCode(taxonomyCodeDTO.getMacroAreaCode());
dto.setMacroAreaName(taxonomyCodeDTO.getMacroAreaName());
dto.setMacroAreaDescription(taxonomyCodeDTO.getMacroAreaDescription());
return dto;
})
.toList();
public TaxonomyMacroAreaCodeDTO map(
it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyMacroAreaCodeDTO input) {
TaxonomyMacroAreaCodeDTO dto = new TaxonomyMacroAreaCodeDTO();
dto.setOrganizationTypeDescription(input.getOrganizationType()+". "+input.getOrganizationTypeDescription());
dto.setOrganizationType(input.getOrganizationType());
dto.setMacroAreaCode(input.getMacroAreaCode());
dto.setMacroAreaName(input.getMacroAreaCode()+". "+input.getMacroAreaName());
dto.setMacroAreaDescription(input.getMacroAreaDescription());
return dto;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package it.gov.pagopa.pu.bff.mapper;

import it.gov.pagopa.pu.bff.dto.generated.TaxonomyOrganizationTypeDTO;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyOrganizationTypeDTOEmbedded;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class TaxonomyOrganizationTypeMapper {
public List<TaxonomyOrganizationTypeDTO> map(CollectionModelTaxonomyOrganizationTypeDTOEmbedded input) {
return input.getTaxonomyOrganizationTypeDTOes().stream()
.map(taxonomyCodeDTO -> {
TaxonomyOrganizationTypeDTO dto = new TaxonomyOrganizationTypeDTO();
dto.setOrganizationTypeDescription(taxonomyCodeDTO.getOrganizationTypeDescription());
dto.setOrganizationType(taxonomyCodeDTO.getOrganizationType());
return dto;
})
.toList();
public TaxonomyOrganizationTypeDTO map(
it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyOrganizationTypeDTO input) {
TaxonomyOrganizationTypeDTO dto = new TaxonomyOrganizationTypeDTO();
dto.setOrganizationTypeDescription(input.getOrganizationType()+". "+input.getOrganizationTypeDescription());
dto.setOrganizationType(input.getOrganizationType());
return dto;
}

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package it.gov.pagopa.pu.bff.mapper;

import it.gov.pagopa.pu.bff.dto.generated.TaxonomyServiceTypeCodeDTO;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyServiceTypeCodeDTOEmbedded;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class TaxonomyServiceTypeCodeMapper {
public List<TaxonomyServiceTypeCodeDTO> map(CollectionModelTaxonomyServiceTypeCodeDTOEmbedded input) {
return input.getTaxonomyServiceTypeCodeDTOes().stream()
.map(taxonomyCodeDTO -> {
TaxonomyServiceTypeCodeDTO dto = new TaxonomyServiceTypeCodeDTO();
dto.setOrganizationTypeDescription(taxonomyCodeDTO.getOrganizationType()+". "+taxonomyCodeDTO.getOrganizationTypeDescription());
dto.setOrganizationType(taxonomyCodeDTO.getOrganizationType());
dto.setMacroAreaCode(taxonomyCodeDTO.getMacroAreaCode());
dto.setMacroAreaName(taxonomyCodeDTO.getMacroAreaName());
dto.setMacroAreaDescription(taxonomyCodeDTO.getMacroAreaDescription());
dto.setServiceTypeCode(taxonomyCodeDTO.getServiceTypeCode());
dto.setServiceType(taxonomyCodeDTO.getServiceType());
dto.setServiceTypeDescription(taxonomyCodeDTO.getServiceTypeDescription());
return dto;
})
.toList();
public TaxonomyServiceTypeCodeDTO map(
it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyServiceTypeCodeDTO input) {
TaxonomyServiceTypeCodeDTO dto = new TaxonomyServiceTypeCodeDTO();
dto.setOrganizationTypeDescription(input.getOrganizationType()+". "+input.getOrganizationTypeDescription());
dto.setOrganizationType(input.getOrganizationType());
dto.setMacroAreaCode(input.getMacroAreaCode());
dto.setMacroAreaName(input.getMacroAreaCode()+". "+input.getMacroAreaName());
dto.setMacroAreaDescription(input.getMacroAreaDescription());
dto.setServiceTypeCode(input.getServiceTypeCode());
dto.setServiceType(input.getServiceTypeCode()+". "+input.getServiceType());
dto.setServiceTypeDescription(input.getServiceTypeDescription());
return dto;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,54 @@ public TaxonomyServiceImpl(TaxonomyClient taxonomyClient,
public List<TaxonomyCollectionReasonDTO> getCollectionReason (
String organizationType,
String macroAreaCode, String serviceTypeCode, String accessToken){
return taxonomyCollectionReasonMapper.map(taxonomyClient.getCollectionReason(organizationType,macroAreaCode,serviceTypeCode,accessToken).getEmbedded());
return taxonomyClient.getCollectionReason(organizationType, macroAreaCode, serviceTypeCode, accessToken)
.getEmbedded().getTaxonomyCollectionReasonDTOes()
.stream()
.map(taxonomyCollectionReasonMapper::map)
.toList();
}

@Override
public List<TaxonomyMacroAreaCodeDTO> getMacroArea (
String organizationType,
String accessToken) {
return taxonomyMacroAreaCodeMapper.map(taxonomyClient.getMacroArea(organizationType,accessToken).getEmbedded());
return taxonomyClient.getMacroArea(organizationType,accessToken).getEmbedded()
.getTaxonomyMacroAreaCodeDTOes()
.stream()
.map(taxonomyMacroAreaCodeMapper::map)
.toList();
}

@Override
public List<TaxonomyOrganizationTypeDTO> getOrganizationTypes (
String accessToken) {
return taxonomyOrganizationTypeMapper
.map(taxonomyClient.getOrganizationType(accessToken).getEmbedded());
return taxonomyClient.getOrganizationType(accessToken).getEmbedded()
.getTaxonomyOrganizationTypeDTOes()
.stream()
.map(taxonomyOrganizationTypeMapper::map)
.toList();
}

@Override
public List<TaxonomyServiceTypeCodeDTO> getServiceType (
String organizationType,
String macroAreaCode, String accessToken) {
return taxonomyServiceTypeCodeMapper.map(taxonomyClient.getServiceType(organizationType,macroAreaCode,accessToken).getEmbedded());
return taxonomyClient.getServiceType(organizationType,macroAreaCode,accessToken).getEmbedded()
.getTaxonomyServiceTypeCodeDTOes()
.stream()
.map(taxonomyServiceTypeCodeMapper::map)
.toList();
}

@Override
public List<TaxonomyCodeDTO> getTaxonomyCode (
String organizationType,
String macroAreaCode, String serviceTypeCode, String collectionReason,
String accessToken) {
return taxonomyCodeMapper.map(taxonomyClient.getTaxonomyCode(organizationType,macroAreaCode,serviceTypeCode,collectionReason,accessToken).getEmbedded());
return taxonomyClient.getTaxonomyCode(organizationType,macroAreaCode,serviceTypeCode,collectionReason,accessToken).getEmbedded()
.getTaxonomyCodeDTOes()
.stream()
.map(taxonomyCodeMapper::map)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void testMapToOrganizationDTO_ValidRoles() {
organization.setOrganizationId(123L);
organization.setIpaCode("testIpaCode");
organization.setOrgName("Test Organization");
organization.setOrgLogoDesc("base64LogoString");
organization.setOrgLogo("base64LogoString");
List<String> roles = Collections.singletonList("ROLE_ADMIN");

OrganizationDTO result = mapper.mapToOrganizationDTO(organization, roles);
Expand Down

0 comments on commit c437416

Please sign in to comment.