Commit 57c8ffae authored by Franck Desaize's avatar Franck Desaize
Browse files

Fix issues with targetDomain in the case of empty list

parent 94aa6aed
Pipeline #267512 failed with stages
in 7 minutes and 20 seconds
......@@ -16,7 +16,7 @@ public interface PatientCrossReferenceSearch {
* retrieve the patient alias corresponding to the requested
*
* @param sourceIdentifier identifier of the reference patient
* @param targetDomains list of TargetDomains to pro
* @param targetDomains list of TargetDomains, the list cardinality must be [0..*]
* @return a patient aliases that match the patient with sourceIdentifier
* @throws SearchCrossReferenceException if an error happens during the search processing.
*/
......
......@@ -17,7 +17,6 @@ import net.ihe.gazelle.lib.gitbutils.adapter.MappingException;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
......@@ -25,8 +24,8 @@ import java.util.List;
*/
public class CrossReferenceSearchProcessingService {
private MapperAnyContentToObject mapper;
private PatientCrossReferenceSearch crossReferenceSearch;
private final MapperAnyContentToObject mapper;
private final PatientCrossReferenceSearch crossReferenceSearch;
/**
......@@ -51,15 +50,34 @@ public class CrossReferenceSearchProcessingService {
List<AnyContent> searchParameter = processRequest.getInput();
if (searchParameter.size() != 2) {
throw new IllegalArgumentException("ProcessRequest.input shall contain two parameters to retrieve Xref !");
} else if (!CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_NAME.equals(searchParameter.get(0).getName()) || !CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_TARGET_NAME.equals(searchParameter.get(1).getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.inputs shall have the name '%s' and '%s' for a %s operation !",
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_NAME,
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_TARGET_NAME,
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_SEARCH_OPERATION));
}
try {
patientAliases = crossReferenceSearch.search(mapper.getObject(searchParameter.get(0), EntityIdentifier.class),
mapper.getObjectCollection(searchParameter.get(1), ArrayList.class,String.class));
AnyContent sourceIdentifier = searchParameter.get(0);
AnyContent targetDomains = searchParameter.get(1);
if (targetDomains == null) {
if(!CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_NAME.equals(sourceIdentifier.getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.inputs shall have the name '%s' and '%s' for a %s operation !",
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_NAME,
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_TARGET_NAME,
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_SEARCH_OPERATION));
}
patientAliases = crossReferenceSearch.search(mapper.getObject(searchParameter.get(0), EntityIdentifier.class),
new ArrayList<String>());
} else {
if(!CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_NAME.equals(sourceIdentifier.getName()) ||
!CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_TARGET_NAME.equals(targetDomains.getName())) {
throw new IllegalArgumentException(String.format("ProcessRequest.inputs shall have the name '%s' and '%s' for a %s operation !",
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_NAME,
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_TARGET_NAME,
CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_SEARCH_OPERATION));
}
patientAliases = crossReferenceSearch.search(mapper.getObject(searchParameter.get(0), EntityIdentifier.class),
mapper.getObjectCollection(searchParameter.get(1), ArrayList.class, String.class));
}
return createPatientSearchProcessResponse(patientAliases);
} catch (MappingException e) {
throw new IllegalArgumentException("Cannot decode Request inputs as SourceIdentifier !", e);
......
......@@ -43,7 +43,7 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
@Override
public PatientAliases search(EntityIdentifier sourceIdentifier, List<String> targetDomains) throws SearchCrossReferenceException {
checkSourceIdentifier(sourceIdentifier);
checkTargetDomains(targetDomains);
boolean usableTargetList = checkTargetDomains(targetDomains);
PatientDB patientDB = null;
PatientAliases patientAlias = null;
......@@ -69,7 +69,12 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
if (patientAlias == null) {
throw new SearchCrossReferenceException("An error occurred during CrossReference Search and the patient aliases could not have been set");
}
return removePatientFromPatientAliasWithNonMatchingTargetDomain(patientAlias, targetDomains);
if(usableTargetList){
return removePatientFromPatientAliasWithNonMatchingTargetDomain(patientAlias, targetDomains);
}else {
return patientAlias;
}
}
/**
......@@ -98,17 +103,19 @@ public class PatientCrossReferenceSearchImpl implements PatientCrossReferenceSea
* Return true if the list is not empty, false otherwise
*
* @param targetDomains
* @retur usableTargetDomains
* @throws SearchCrossReferenceException
*/
private void checkTargetDomains(List<String> targetDomains) throws SearchCrossReferenceException {
if (targetDomains.isEmpty()) {
throw new SearchCrossReferenceException("The target domains shall not be empty");
private boolean checkTargetDomains(List<String> targetDomains) throws SearchCrossReferenceException {
if (targetDomains == null || targetDomains.isEmpty()) {
return false;
}
for (String targetDomain : targetDomains) {
if (targetDomain.isBlank() || !domainService.exist(targetDomain)) {
throw new SearchCrossReferenceException("One of the target domain does not exist");
}
}
return true;
}
/**
......
......@@ -83,6 +83,27 @@ class CrossReferenceSearchProcessingServiceTest {
processRequest.getInput().add(new MapperObjectToAnyContent().getAnyContent("Bad input name", sourceIdentifier));
processRequest.getInput().add(new MapperObjectToAnyContent().getAnyContent(CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_TARGET_NAME, new ArrayList<String>()));
} catch (MappingException e) {
fail("No exception is supposed to be thrown when transforming test patient to AnyContent !", e);
}
assertThrows(IllegalArgumentException.class, () -> crossReferenceSearchProcessingService.processPatientCrossReferenceSearch(processRequest));
} /**
* Test Processing a X-ref search, error case using a wrong input name in ProcessRequest
*/
@Test
public void process_with_wrong_input_name2() {
ProcessRequest processRequest = new ProcessRequest();
processRequest.setOperation(CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_PATIENT_SEARCH_OPERATION);
EntityIdentifier sourceIdentifier = new EntityIdentifier();
sourceIdentifier.setSystemIdentifier("identifierSystem");
sourceIdentifier.setValue("identifierValue");
List<String> strings =new ArrayList<>();
strings.add("test");
try {
processRequest.getInput().add(new MapperObjectToAnyContent().getAnyContent("Bad input name", sourceIdentifier));
processRequest.getInput().add(new MapperObjectToAnyContent().getAnyContent(CrossReferenceProcessingWebServiceConstants.CROSS_REFERENCE_INPUT_TARGET_NAME, strings));
} catch (MappingException e) {
fail("No exception is supposed to be thrown when transforming test patient to AnyContent !", e);
}
......
......@@ -82,7 +82,7 @@ public class PatientCrossReferenceSearchImplTest {
SearchCrossReferenceException exception = assertThrows(SearchCrossReferenceException.class,
() -> patientCrossReferenceSearch.search(sourceIdentifier, targetDomains));
assertEquals("The target domains shall not be empty", exception.getMessage());
assertEquals("Error in the sourceIdentifier : System does not exit", exception.getMessage());
}
@Test
......
......@@ -17,7 +17,7 @@ public class TestClientWithUrl {
@Test
void test() throws MalformedURLException {
URL patientRegistryUrl = new URL("http://qualification.ihe-europe.net/patient-registry/CrossReferenceService/xref-processing-service?wsdl ");
URL patientRegistryUrl = new URL("http://localhost:8580/patient-registry/CrossReferenceService/xref-processing-service?wsdl ");
XRefSearchClient xRefSearchClient = new XRefSearchClient(patientRegistryUrl);
EntityIdentifier entityIdentifier = new EntityIdentifier();
......@@ -25,10 +25,10 @@ public class TestClientWithUrl {
entityIdentifier.setType(null);
entityIdentifier.setValue("IHEBLUE-998");
List<String> targetDomain = new ArrayList<>();
targetDomain.add("1.3.6.1.4.1.21367.13.20.2000");
try {
PatientAliases patientAliases = xRefSearchClient.search(entityIdentifier,targetDomain);
System.out.println("test");
} catch (SearchCrossReferenceException e) {
e.printStackTrace();
}
......
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