Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTWS-817: ConceptResource to GET concepts of a given class #583

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class ConceptSearchHandler1_8 implements SearchHandler {
Arrays.asList(
new SearchQuery.Builder("Allows you to find concepts by source and code").withRequiredParameters("source")
.withOptionalParameters("code").build(), new SearchQuery.Builder(
"Allows you to find concepts by name and class").withRequiredParameters("name")
.withOptionalParameters("class", "searchType").build(), new SearchQuery.Builder(
"Allows you to find concepts by name and class")
.withOptionalParameters("name","class", "searchType").build(), new SearchQuery.Builder(
"Allows you to find a list of concepts by passing references")
.withRequiredParameters("references").build()));

Expand Down Expand Up @@ -162,6 +162,25 @@ public PageableResult search(RequestContext context) throws ResponseException {
throw new InvalidSearchException("Invalid searchType: " + searchType
+ ". Allowed values: \"equals\" and \"fuzzy\"");
}

//getting concepts by classUuid and other parameters
if (conceptClass != null) {
List<Locale> locales = new ArrayList<Locale>(LocaleUtility.getLocalesInOrder());
List<ConceptClass> classes = null;
ConceptClass responseConceptClass = conceptService.getConceptClassByUuid(conceptClass);

if (responseConceptClass != null) {
classes = Arrays.asList(responseConceptClass);
}

List<ConceptSearchResult> searchResults = conceptService.getConcepts(name, locales, context.getIncludeAll(),
classes, null, null, null, null, context.getStartIndex(), context.getLimit());
List<Concept> results = new ArrayList<Concept>(searchResults.size());
for (ConceptSearchResult csr : searchResults) {
results.add(csr.getConcept());
}
return new NeedsPaging<Concept>(results, context);
}

ConceptSource conceptSource = conceptService.getConceptSourceByUuid(source);
if (conceptSource == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,37 @@ public void shouldSearchAndReturnConceptsThatContainsNamePartInRequest() throws
assertThat(hits, contains(hasUuid("15f83cd6-64e9-4e06-a5f9-364d3b14a43d")));
}

@Test
public void shouldSearchAndReturnConceptsThatContainsNameAndClassPartInRequest() throws Exception {
service.updateConceptIndex(service.getConceptByUuid("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
MockHttpServletRequest req = request(RequestMethod.GET, getURI());
SimpleObject result;
List<Object> hits;

String conceptClassUuid = "3d065ed4-b0b9-4710-9a17-6d8c4fd259b7"; // DRUG
String name = "Aspirin"; //ASPIRIN

req.addParameter("class", conceptClassUuid);
req.addParameter("name", name);

result = deserialize(handle(req));
hits = result.get("results");

assertThat(hits, contains(hasUuid("15f83cd6-64e9-4e06-a5f9-364d3b14a43d")));
}

@Test
public void shouldSearchAndReturnConceptsByClass() throws Exception {
service.updateConceptIndex(service.getConceptByUuid("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
SimpleObject response = deserialize(handle(newGetRequest(getURI(), new Parameter("class", "3d065ed4-b0b9-4710-9a17-6d8c4fd259b7"))));
List<Object> results = Util.getResultsList(response);

Assert.assertEquals(2, results.size());
Object next = results.iterator().next();
Assert.assertThat((String) PropertyUtils.getProperty(next, "uuid"), is("15f83cd6-64e9-4e06-a5f9-364d3b14a43d"));
System.out.println(results);
}

@Test(expected = IllegalStateException.class)
public void shouldThrowExceptionWhenSearchRequiredParametersAreCalledTwice() throws Exception {
new SearchQuery.Builder("Some search description").withRequiredParameters("source").withRequiredParameters("name") // <- Exception
Expand All @@ -332,7 +363,7 @@ public void shouldThrowExceptionWhenSearchTypeParameterIsInvalid() throws Except
MockHttpServletRequest req = request(RequestMethod.GET, getURI());
SimpleObject result;

String conceptClassUuid = "3d065ed4-b0b9-4710-9a17-6d8c4fd259b7"; // DRUG
String conceptClassUuid = "ggy4657978090809"; // DRUG
String name = "Aspirin"; //ASPIRIN
String searchType = "equalz";

Expand All @@ -342,7 +373,7 @@ public void shouldThrowExceptionWhenSearchTypeParameterIsInvalid() throws Except

result = deserialize(handle(req));
}

@Test
@Ignore("TRUNK-1956: H2 cannot execute the generated SQL because it requires all fetched columns to be included in the group by clause")
public void shouldSearchAndReturnAListOfConceptsMatchingTheQueryString() throws Exception {
Expand Down
Loading