NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

public ResponseEnttty<XlsUploadingRespDto> uploadXls(MultipartFile file, Boolean isCorrection) {
UUID traceld = UUID.randomUUID();
log.info("[TraceID: {}] Received ’{}' request to uploading xls file {}",
traceld, FIXED-PRELIMINARY.getEngName(), file.getOriginalFilename());
try {
List<FixedPreliminaryRateXlsx> fixedRatesXls = xlsParser.parse(file);
List<VerificationResult> errorResults = validator.validate(fixedRatesXls);
if (!errorResults.isEmpty()) {
throw new ValidationException(errorResults);
}
List<FixedPreliminaryRateDto> fixedRatesDto = converter.convertAllBack(fixedRatesXls);
// Call the calculateRates method in the target microservice
Flux<RateDto> calculatedRates = callCalculateRates(fixedRatesDto);
// Add any further processing logic for the calculatedRates here

SaveChangedResult<FixedPreliminaryRateDto> saveResult =
preliminaryRateDao.saveChanged(fixedRatesDto);
if (!saveResult.isChanged()) {
log.info("[TraceID: {}] xls file '{}' was already uploaded before", traceld,
file.getOriginalFilename());
return ResponseEntity.ok()
.body(XlsUploadingRespDto.builder()
.message(format("Файл '%s' уже был загружен ранее",
file.getOriginalFilename()))
.uploadingTimestamp(Instant.now()).build());
}
log.info("[TraceID: {}] xls file '{}' was uploaded", traceld, file.getOriginalFilename());
} catch (Exception e) {
log.error("[TraceID: {}] Occurred error while xls file '{}' uploading", traceld,
file.getOriginalFilename(), e);
throw e;
}
return ResponseEntity.ok()
.body(XlsUploadingRespDto.builder()
.uploadingTimestamp(Instant.now()).build());
}


private Flux<RateDto> callCalculateRates(List<FixedPreliminaryRateDto> fixedRatesDto) {
// Convert the List<FixedPreliminaryRateDto> to List<RateDto> before sending the request
List<RateDto> rateDtoList = convertFixedPreliminaryRateDtoToRateDto(fixedRatesDto);

return webClient.post()
.uri("/calculate")
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(rateDtoList))
.retrieve()
.bodyToFlux(RateDto.class);
}


private List<RateDto> convertFixedPreliminaryRateDtoToRateDto(List<FixedPreliminaryRateDto> fixedRatesDto) {
return fixedRatesDto.stream().map(fixedRate -> {
RateDto rateDto = new RateDto();
rateDto.setCurrency(fixedRate.getCurrency().getIsoCode());
rateDto.setFrequency(fixedRate.getFrequency());
rateDto.setPeriod(fixedRate.getPeriod().getDays());
rateDto.setInterestRate(fixedRate.getInterestRate());
return rateDto;
}).collect(Collectors.toList());
}


@Configuration
public class WebClientConfig {

@Bean
public WebClient.Builder webClientBuilder() {
return WebClient.builder();
}
}

private List<FixedPreliminaryRateDto> convertRateDtoToFixedPreliminaryRateDto(List<RateDto> rateDtoList) {
return rateDtoList.stream().map(rateDto -> {
FixedPreliminaryRateDto fixedRate = new FixedPreliminaryRateDto();

CurrencyDto currencyDto = new CurrencyDto();
currencyDto.setIsoCode(rateDto.getCurrency());
fixedRate.setCurrency(currencyDto);

fixedRate.setFrequency(rateDto.getFrequency());
fixedRate.setPeriod(Period.ofDays(rateDto.getPeriod()));
fixedRate.setInterestRate(rateDto.getInterestRate());

// Set any other required fields in the FixedPreliminaryRateDto object

return fixedRate;
}).collect(Collectors.toList());
}

private List<FixedPreliminaryRateDto> callCalculateRates(List<FixedPreliminaryRateDto> fixedRatesDto) {
List<RateDto> rateDtoList = convertFixedPreliminaryRateDtoToRateDto(fixedRatesDto);

List<RateDto> calculatedRateDtoList = webClient.post()
.uri("/calculate")
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(rateDtoList))
.retrieve()
.bodyToFlux(RateDto.class)
.collectList() // Convert the Flux to a List
.block(); // Block the current thread to retrieve the list

// Convert the List<RateDto> to List<FixedPreliminaryRateDto>
List<FixedPreliminaryRateDto> calculatedFixedRates = convertRateDtoToFixedPreliminaryRateDto(calculatedRateDtoList);

return calculatedFixedRates;
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.