Commit 28cf49b7 authored by Siiri's avatar Siiri
Browse files

TEIS-2109: refactored PersonProcessingService.

parent 29e3c60a
package ee.sm.ti.teis.commongateway.person;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.gatewaycommon.rabbit.RequestProcessingService;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
@Service
@RequiredArgsConstructor
public class PersonProcessingService {
private final RabbitTemplate gwRabbitTemplate;
PersonDto getPerson(PersonRequest requestDTO) {
PersonResponse response = (PersonResponse) gwRabbitTemplate.convertSendAndReceive(requestDTO.routingKey(), requestDTO);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(requestDTO.getRequestMetaDTO().getRequestId());
}
PersonDto updatePerson(UpdatePersonRequest request) {
UpdatePersonResponse response = (UpdatePersonResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
private final RequestProcessingService service;
public void updatePersonName(RequestMetaDTO requestMetaDTO, String id, String firstName, String lastName) {
PersonRequest personRequest = new PersonRequest();
personRequest.setPayload(new PersonRequest.Parameters(id), requestMetaDTO);
PersonDto person = getPerson(personRequest);
PersonDto person = (PersonDto) service.sendAndReceive(personRequest);
IndividualPersonDto individualPerson = person.getIndividualPerson();
individualPerson.setFirstName(firstName);
individualPerson.setLastName(lastName);
UpdatePersonRequest updatePersonRequest = new UpdatePersonRequest();
updatePersonRequest.setPayload(new UpdatePersonRequest.Parameters(person), requestMetaDTO);
updatePerson(updatePersonRequest);
service.sendAndReceive(updatePersonRequest);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment