Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksiybozhykntt committed Jan 16, 2025
1 parent 8b1bf65 commit c6786ef
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ public ResponseEntity<ErrorDTO> handleInvalidOperatorRoleException(InvalidOperat
ErrorDTO errorDTO = new ErrorDTO("GENERIC_ERROR", e.getMessage());
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);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package it.gov.pagopa.pu.bff.exception;

public class UnparsableEntityException extends RuntimeException{

public UnparsableEntityException (String message){
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package it.gov.pagopa.pu.bff.mapper;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyCodeDTO;
import it.gov.pagopa.pu.bff.exception.UnparsableEntityException;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyCodeDTOEmbedded;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyCodeDTO;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class CollectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO {

private final ObjectMapper objectMapper;

public CollectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO(ObjectMapper objectMapper){
this.objectMapper = objectMapper;
}

public CollectionModelTaxonomyCodeDTO map(
CollectionModelTaxonomyCodeDTOEmbedded input){
try{
List<TaxonomyCodeDTO> modifiedList = input.getTaxonomyCodeDTOes().stream()
.map(dto -> {
dto.setOrganizationTypeDescription(dto.getOrganizationType() + ". " + dto.getOrganizationTypeDescription());
dto.setMacroAreaDescription(dto.getMacroAreaCode()+". "+dto.getMacroAreaName());
dto.setServiceTypeDescription(dto.getServiceTypeCode()+". "+dto.getServiceType());
return dto;
}).toList();
CollectionModelTaxonomyCodeDTOEmbedded modifiedEmbedded = new CollectionModelTaxonomyCodeDTOEmbedded();
modifiedEmbedded.setTaxonomyCodeDTOes(modifiedList);
String result = objectMapper.writeValueAsString(modifiedEmbedded);
return objectMapper.readValue(result, CollectionModelTaxonomyCodeDTO.class);
} catch (JsonProcessingException e) {
throw new UnparsableEntityException(e.getMessage());
}
}

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

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyCollectionReasonDTO;
import it.gov.pagopa.pu.bff.exception.UnparsableEntityException;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyCollectionReasonDTOEmbedded;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyCollectionReasonDTO;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class CollectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO {

private final ObjectMapper objectMapper;

public CollectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO(ObjectMapper objectMapper){
this.objectMapper = objectMapper;
}

public CollectionModelTaxonomyCollectionReasonDTO map(
CollectionModelTaxonomyCollectionReasonDTOEmbedded input){
try{
List<TaxonomyCollectionReasonDTO> modifiedList = input.getTaxonomyCollectionReasonDTOes().stream()
.map(dto -> {
dto.setOrganizationTypeDescription(dto.getOrganizationType() + ". " + dto.getOrganizationTypeDescription());
dto.setMacroAreaDescription(dto.getMacroAreaCode()+". "+dto.getMacroAreaName());
dto.setServiceTypeDescription(dto.getServiceTypeCode()+". "+dto.getServiceType());
return dto;
}).toList();
CollectionModelTaxonomyCollectionReasonDTOEmbedded modifiedEmbedded = new CollectionModelTaxonomyCollectionReasonDTOEmbedded();
modifiedEmbedded.setTaxonomyCollectionReasonDTOes(modifiedList);
String result = objectMapper.writeValueAsString(modifiedEmbedded);
return objectMapper.readValue(result, CollectionModelTaxonomyCollectionReasonDTO.class);
} catch (JsonProcessingException e) {
throw new UnparsableEntityException(e.getMessage());
}
}

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

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyMacroAreaCodeDTO;
import it.gov.pagopa.pu.bff.exception.UnparsableEntityException;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyMacroAreaCodeDTOEmbedded;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyMacroAreaCodeDTO;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class CollectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO {
private final ObjectMapper objectMapper;

public CollectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO(ObjectMapper objectMapper){
this.objectMapper = objectMapper;
}

public CollectionModelTaxonomyMacroAreaCodeDTO map(
CollectionModelTaxonomyMacroAreaCodeDTOEmbedded input){
try{
List<TaxonomyMacroAreaCodeDTO> modifiedList = input.getTaxonomyMacroAreaCodeDTOes().stream()
.map(dto -> {
dto.setOrganizationTypeDescription(dto.getOrganizationType() + ". " + dto.getOrganizationTypeDescription());
dto.setMacroAreaDescription(dto.getMacroAreaCode()+". "+dto.getMacroAreaName());
return dto;
}).toList();
CollectionModelTaxonomyMacroAreaCodeDTOEmbedded modifiedEmbedded = new CollectionModelTaxonomyMacroAreaCodeDTOEmbedded();
modifiedEmbedded.setTaxonomyMacroAreaCodeDTOes(modifiedList);
String macroAreaCode = objectMapper.writeValueAsString(modifiedEmbedded);
return objectMapper.readValue(macroAreaCode, CollectionModelTaxonomyMacroAreaCodeDTO.class);
} catch (JsonProcessingException e) {
throw new UnparsableEntityException(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package it.gov.pagopa.pu.bff.mapper;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyOrganizationTypeDTO;
import it.gov.pagopa.pu.bff.exception.UnparsableEntityException;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyOrganizationTypeDTOEmbedded;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyOrganizationTypeDTO;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class CollectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO {

private final ObjectMapper objectMapper;

public CollectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}

public CollectionModelTaxonomyOrganizationTypeDTO map(
CollectionModelTaxonomyOrganizationTypeDTOEmbedded input) {
try {
// Modify the list of DTOs
List<TaxonomyOrganizationTypeDTO> modifiedList = input.getTaxonomyOrganizationTypeDTOes().stream()
.map(dto -> {
dto.setOrganizationTypeDescription(dto.getOrganizationType() + ". " + dto.getOrganizationTypeDescription());
return dto;
})
.toList();

// Create a new embedded object with the modified list
CollectionModelTaxonomyOrganizationTypeDTOEmbedded modifiedEmbedded = new CollectionModelTaxonomyOrganizationTypeDTOEmbedded();
modifiedEmbedded.setTaxonomyOrganizationTypeDTOes(modifiedList);

// Convert the modified embedded object to JSON and back to CollectionModel
String orgTypesJson = objectMapper.writeValueAsString(modifiedEmbedded);
return objectMapper.readValue(orgTypesJson, CollectionModelTaxonomyOrganizationTypeDTO.class);
} catch (JsonProcessingException e) {
throw new UnparsableEntityException(e.getMessage());
}
}

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

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyServiceTypeCodeDTO;
import it.gov.pagopa.pu.bff.exception.UnparsableEntityException;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyServiceTypeCodeDTOEmbedded;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.TaxonomyServiceTypeCodeDTO;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class CollectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO {

private final ObjectMapper objectMapper;

public CollectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO(ObjectMapper objectMapper){
this.objectMapper = objectMapper;
}

public CollectionModelTaxonomyServiceTypeCodeDTO map(
CollectionModelTaxonomyServiceTypeCodeDTOEmbedded input){
try{
List<TaxonomyServiceTypeCodeDTO> modifiedList = input.getTaxonomyServiceTypeCodeDTOes().stream()
.map(dto -> {
dto.setOrganizationTypeDescription(dto.getOrganizationType() + ". " + dto.getOrganizationTypeDescription());
dto.setMacroAreaDescription(dto.getMacroAreaCode()+". "+dto.getMacroAreaName());
dto.setServiceTypeDescription(dto.getServiceTypeCode()+". "+dto.getServiceType());
return dto;
}).toList();
CollectionModelTaxonomyServiceTypeCodeDTOEmbedded modifiedEmbedded = new CollectionModelTaxonomyServiceTypeCodeDTOEmbedded();
modifiedEmbedded.setTaxonomyServiceTypeCodeDTOes(modifiedList);
String result = objectMapper.writeValueAsString(modifiedEmbedded);
return objectMapper.readValue(result, CollectionModelTaxonomyServiceTypeCodeDTO.class);
} catch (JsonProcessingException e) {
throw new UnparsableEntityException(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -1,85 +1,68 @@
package it.gov.pagopa.pu.bff.service.taxonomy;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.gov.pagopa.pu.bff.connector.organization.client.TaxonomyClient;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyCodeDTO;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyCollectionReasonDTO;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyMacroAreaCodeDTO;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyOrganizationTypeDTO;
import it.gov.pagopa.pu.bff.dto.generated.CollectionModelTaxonomyServiceTypeCodeDTO;
import it.gov.pagopa.pu.p4pa_organization.dto.generated.CollectionModelTaxonomyOrganizationTypeDTOEmbedded;
import lombok.Setter;
import it.gov.pagopa.pu.bff.mapper.CollectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO;
import it.gov.pagopa.pu.bff.mapper.CollectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO;
import it.gov.pagopa.pu.bff.mapper.CollectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO;
import it.gov.pagopa.pu.bff.mapper.CollectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO;
import it.gov.pagopa.pu.bff.mapper.CollectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO;
import org.springframework.stereotype.Service;

@Service
public class TaxonomyServiceImpl implements TaxonomyService{

private final TaxonomyClient taxonomyClient;
private final ObjectMapper objectMapper;

public TaxonomyServiceImpl(TaxonomyClient taxonomyClient,ObjectMapper objectMapper){
private final CollectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO collectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO;
private final CollectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO collectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO;
private final CollectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO collectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO;
private final CollectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO collectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO;
private final CollectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO collectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO;
public TaxonomyServiceImpl(TaxonomyClient taxonomyClient,CollectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO collectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO,CollectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO collectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO,CollectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO collectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO,CollectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO collectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO,CollectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO collectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO){
this.taxonomyClient = taxonomyClient;
this.objectMapper = objectMapper;
this.collectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO = collectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO;
this.collectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO = collectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO;
this.collectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO = collectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO;
this.collectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO = collectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO;
this.collectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO = collectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO;
}
@Override
public CollectionModelTaxonomyCollectionReasonDTO getCollectionReason (
String organizationType,
String macroAreaCode, String serviceTypeCode, String accessToken)
{
try {
String collectionReason = objectMapper.writeValueAsString(taxonomyClient.getCollectionReason(organizationType,macroAreaCode,serviceTypeCode,accessToken).getEmbedded());
return objectMapper.readValue(collectionReason,CollectionModelTaxonomyCollectionReasonDTO.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
String macroAreaCode, String serviceTypeCode, String accessToken){
return collectionModelTaxonomyCollectionReasonDTOEmbeddedToCollectionModelTaxonomyCollectionReasonDTO.map(taxonomyClient.getCollectionReason(organizationType,macroAreaCode,serviceTypeCode,accessToken).getEmbedded());
}

@Override
public CollectionModelTaxonomyMacroAreaCodeDTO getMacroArea (
String organizationType,
String accessToken) {
try {
String macroArea = objectMapper.writeValueAsString(taxonomyClient.getMacroArea(organizationType,accessToken).getEmbedded());
return objectMapper.readValue(macroArea,CollectionModelTaxonomyMacroAreaCodeDTO.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return collectionModelTaxonomyMacroAreaCodeDTOEmbeddedToCollectionModelTaxonomyMacroAreaCodeDTO.map(taxonomyClient.getMacroArea(organizationType,accessToken).getEmbedded());
}

@Override
public CollectionModelTaxonomyOrganizationTypeDTO getOrganizationTypes (
String accessToken) {
try {
String orgTypes = objectMapper.writeValueAsString(taxonomyClient.getOrganizationType(accessToken).getEmbedded());
return objectMapper.readValue(orgTypes,CollectionModelTaxonomyOrganizationTypeDTO.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return collectionModelTaxonomyOrganizationTypeDTOEmbeddedToCollectionModelTaxonomyOrganizationTypeDTO
.map(taxonomyClient.getOrganizationType(accessToken).getEmbedded());
}

@Override
public CollectionModelTaxonomyServiceTypeCodeDTO getServiceType (
String organizationType,
String macroAreaCode, String accessToken) {
try {
String serviceType = objectMapper.writeValueAsString(taxonomyClient.getServiceType(organizationType,macroAreaCode,accessToken).getEmbedded());
return objectMapper.readValue(serviceType,CollectionModelTaxonomyServiceTypeCodeDTO.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return collectionModelTaxonomyServiceTypeCodeDTOEmbeddedToCollectionModelTaxonomyServiceTypeCodeDTO.map(taxonomyClient.getServiceType(organizationType,macroAreaCode,accessToken).getEmbedded());
}

@Override
public CollectionModelTaxonomyCodeDTO getTaxonomyCode (
String organizationType,
String macroAreaCode, String serviceTypeCode, String collectionReason,
String accessToken) {
try {
String taxonomyCode = objectMapper.writeValueAsString(taxonomyClient.getTaxonomyCode(organizationType,macroAreaCode,serviceTypeCode,collectionReason,accessToken).getEmbedded());
return objectMapper.readValue(taxonomyCode,CollectionModelTaxonomyCodeDTO.class);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return collectionModelTaxonomyCodeDTOEmbeddedToCollectionModelTaxonomyCodeDTO.map(taxonomyClient.getTaxonomyCode(organizationType,macroAreaCode,serviceTypeCode,collectionReason,accessToken).getEmbedded());
}
}

0 comments on commit c6786ef

Please sign in to comment.