Commit 949efadc authored by Alexandre Pocinho's avatar Alexandre Pocinho
Browse files

Work on PATREG-199 improve webservices for GitB

parent a41dac46
Pipeline #272817 failed with stages
in 5 minutes and 7 seconds
......@@ -26,59 +26,62 @@ public class PatientFeedProcessingService {
/**
* Constructor for the class with all needed parameters
*
* @param patientFeedService : Application service to feed a patient
*/
@Inject
public PatientFeedProcessingService(PatientFeedService patientFeedService){
public PatientFeedProcessingService(PatientFeedService patientFeedService) {
this.mapper = new MapperAnyContentToObject();
this.patientFeedService = patientFeedService;
}
/**
* Process the Patient Feed request.
*
* @param processRequest : GITB request received.
* @return ProcessResponse corresponding to the received request
*/
public ProcessResponse processPatientFeed(ProcessRequest processRequest) {
String uuidOfFedPatient;
List<AnyContent> patientToFeed = processRequest.getInput();
if (patientToFeed.size() != 1){
if (patientToFeed.size() != 1) {
throw new IllegalArgumentException("ProcessRequest.input shall contain one and only one patient !");
} else if (!PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME.equals(patientToFeed.get(0).getName())){
} else if (!PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME.equals(patientToFeed.get(0).getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.input shall have the name '%s' for a %s operation !",
PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME, PatientProcessingWebserviceConstants.PATIENT_FEED_OPERATION));
}
try {
uuidOfFedPatient = patientFeedService.createPatient(mapper.getObject(patientToFeed.get(0), Patient.class));
return createPatientFeedProcessResponse(uuidOfFedPatient);
} catch (MappingException e){
} catch (MappingException e) {
throw new IllegalArgumentException("Cannot decode Request inputs as Patients !");
} catch (PatientFeedException e){
} catch (PatientFeedException e) {
return ProcessResponseWithReportCreator.createFailedProcessResponse(e, patientToFeed.get(0));
}
}
/**
* Process the Patient Update request.
*
* @param processRequest : GITB request received.
* @return ProcessResponse corresponding to the received request
*/
public ProcessResponse processPatientUpdate(ProcessRequest processRequest) {
Patient updatedPatient;
List<AnyContent> patientToFeed = processRequest.getInput();
if (patientToFeed.size() != 1){
if (patientToFeed.size() != 1) {
throw new IllegalArgumentException("ProcessRequest.input shall contain one and only one patient !");
} else if (!PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME.equals(patientToFeed.get(0).getName())){
} else if (!PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME.equals(patientToFeed.get(0).getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.input shall have the name '%s' for a %s operation !",
PatientProcessingWebserviceConstants.PATIENT_INPUT_NAME, PatientProcessingWebserviceConstants.PATIENT_FEED_OPERATION));
}
try {
// Appel du service
updatedPatient = patientFeedService.updatePatient(mapper.getObject(patientToFeed.get(0), Patient.class));
return createPatientUpdateProcessResponse(updatedPatient);
} catch (MappingException e){
return createProcessResponseWithPatient(updatedPatient);
} catch (MappingException e) {
throw new IllegalArgumentException("Cannot decode Request inputs as Patients !");
} catch (PatientFeedException e){
} catch (PatientFeedException e) {
return ProcessResponseWithReportCreator.createFailedProcessResponse(e, patientToFeed.get(0));
}
}
......@@ -87,46 +90,77 @@ public class PatientFeedProcessingService {
* Create a {@link ProcessResponse} to a {@link ProcessRequest} sent to this service after a successful processing.
* The response will contain a {@link TAR} report containing the result Status for the processing operation,
* as well as a single Output containing the UUID assigned to the merged patient.
*
* @param uuid : UUID assigned to the merged Patient, null can be used if the operation fails. No output will appear in the response.
* @return the process response to return to the WebService
* @throws PatientFeedException when response output cannot be mapped to AnyContent
*/
private ProcessResponse createPatientFeedProcessResponse(String uuid) throws PatientFeedException {
ProcessResponse processResponse = new ProcessResponse();
if (uuid == null){
if (uuid == null) {
throw new IllegalArgumentException("Successful operation shall return a valued UUID as an output !");
}
AnyContent uuidAnyContent;
try {
uuidAnyContent = new MapperObjectToAnyContent().getAnyContent(PatientProcessingWebserviceConstants.UUID_OUTPUT_NAME, uuid);
} catch (MappingException e){
} catch (MappingException e) {
throw new PatientFeedException("Cannot map assigned UUID to AnyContent !");
}
processResponse.getOutput().add(uuidAnyContent);
processResponse.setReport(ProcessResponseWithReportCreator.createReport(TestResultType.SUCCESS));
return processResponse;
}
/**
* Create a {@link ProcessResponse} to a {@link ProcessRequest} sent to this service after a successful processing.
* The response will contain a {@link TAR} report containing the result Status for the processing operation,
* as well as a single Output containing the UUID assigned to the merged patient.
* @param uuid : UUID assigned to the merged Patient, null can be used if the operation fails. No output will appear in the response.
*
* @param patientToReturn : Patient assigned to the original Patient, null can be used if the operation fails. No output will appear in the response.
* @return the process response to return to the WebService
* @throws PatientFeedException when response output cannot be mapped to AnyContent
*/
private ProcessResponse createPatientUpdateProcessResponse(Patient uuid) throws PatientFeedException {
private ProcessResponse createProcessResponseWithPatient(Patient patientToReturn) throws PatientFeedException {
ProcessResponse processResponse = new ProcessResponse();
if (uuid == null){
throw new IllegalArgumentException("Successful operation shall return a valued UUID as an output !");
if (patientToReturn == null) {
throw new IllegalArgumentException("Successful operation shall return an existing Patient as an output !");
}
AnyContent uuidAnyContent;
try {
uuidAnyContent = new MapperObjectToAnyContent().getAnyContent(PatientProcessingWebserviceConstants.UUID_OUTPUT_NAME, uuid);
} catch (MappingException e){
throw new PatientFeedException("Cannot map assigned UUID to AnyContent !");
patientAnyContent = new MapperObjectToAnyContent().getAnyContent(PatientProcessingWebserviceConstants.PATIENT_OUTPUT_NAME, patientToReturn);
} catch (MappingException e) {
throw new PatientFeedException("Cannot map Patient to AnyContent !");
}
processResponse.getOutput().add(uuidAnyContent);
processResponse.setReport(ProcessResponseWithReportCreator.createReport(TestResultType.SUCCESS));
return processResponse;
}
/**
* Create a {@link ProcessResponse} to a {@link ProcessRequest} sent to this service after a successful processing.
* The response will contain a {@link TAR} report containing the result Status for the processing operation,
* as well as a single Output containing the UUID assigned to the merged patient.
*
* @param isDelete : UUID assigned to the merged Patient, null can be used if the operation fails. No output will appear in the response.
* @return the process response to return to the WebService
* @throws PatientFeedException when response output cannot be mapped to AnyContent
*/
private ProcessResponse createPatientDeleteProcessResponse(boolean isDelete) throws PatientFeedException {
ProcessResponse processResponse = new ProcessResponse();
AnyContent deletionStatusAnyContent;
try {
if (isDelete) {
deletionStatusAnyContent = new MapperObjectToAnyContent().getAnyContent(PatientProcessingWebserviceConstants.UUID_OUTPUT_NAME, PatientProcessingWebserviceConstants.DELETE_STATUS_DONE);
} else {
deletionStatusAnyContent = new MapperObjectToAnyContent().getAnyContent(PatientProcessingWebserviceConstants.UUID_OUTPUT_NAME, PatientProcessingWebserviceConstants.DELETE_STATUS_GONE);
}
} catch (MappingException e) {
throw new PatientFeedException("Cannot map to AnyContent !"); //TODO
}
processResponse.getOutput().add(deletionStatusAnyContent);
processResponse.setReport(ProcessResponseWithReportCreator.createReport(TestResultType.SUCCESS));
return processResponse;
}
}
......@@ -60,10 +60,10 @@ public class PatientProcessingService implements ProcessingService {
@Override
public ProcessResponse process(ProcessRequest processRequest) {
if (processRequest != null) {
if (PatientProcessingWebserviceConstants.PATIENT_FEED_OPERATION.equals(processRequest.getOperation())) {
return patientFeedProcessingService.processPatientFeed(processRequest);
if (PatientProcessingWebserviceConstants.PATIENT_CREATE_OPERATION.equals(processRequest.getOperation())) {
return patientFeedProcessingService.processPatientCreate(processRequest);
}else if(PatientProcessingWebserviceConstants.PATIENT_UPDATE_OPERATION.equals(processRequest.getOperation())){
return patientFeedProcessingService.processPatientFeed(processRequest);
return patientFeedProcessingService.processPatientUpdate(processRequest);
}else if (PatientProcessingWebserviceConstants.PATIENT_SEARCH_OPERATION.equals(processRequest.getOperation())) {
return patientSearchProcessingService.processPatientSearch(processRequest);
} else {
......
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