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

Introduce new generic concept search endpoints #1172

Draft
wants to merge 1 commit into
base: 8.x
Choose a base branch
from
Draft
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
@@ -0,0 +1,64 @@
/*
* Copyright 2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.snowowl.core.rest.concepts;

import java.util.List;

import com.b2international.snowowl.core.rest.domain.ObjectRestSearch;

/**
* @since 8.11.0
*/
public class ConceptRestSearch extends ObjectRestSearch {

Check warning on line 25 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L25

Added line #L25 was not covered by tests

private Boolean active;
private List<String> codeSystem;
private String term;
private String query;

public Boolean getActive() {
return active;

Check warning on line 33 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L33

Added line #L33 was not covered by tests
}

public List<String> getCodeSystem() {
return codeSystem;

Check warning on line 37 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L37

Added line #L37 was not covered by tests
}

public String getQuery() {
return query;

Check warning on line 41 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L41

Added line #L41 was not covered by tests
}

public String getTerm() {
return term;

Check warning on line 45 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L45

Added line #L45 was not covered by tests
}

public void setActive(Boolean active) {
this.active = active;
}

Check warning on line 50 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L49-L50

Added lines #L49 - L50 were not covered by tests

public void setCodeSystem(List<String> codeSystem) {
this.codeSystem = codeSystem;
}

Check warning on line 54 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L53-L54

Added lines #L53 - L54 were not covered by tests

public void setQuery(String query) {
this.query = query;
}

Check warning on line 58 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L57-L58

Added lines #L57 - L58 were not covered by tests

public void setTerm(String term) {
this.term = term;
}

Check warning on line 62 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptRestSearch.java#L61-L62

Added lines #L61 - L62 were not covered by tests

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.snowowl.core.rest.concepts;

import org.elasticsearch.core.Set;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.b2international.snowowl.core.codesystem.CodeSystemRequests;
import com.b2international.snowowl.core.domain.Concepts;
import com.b2international.snowowl.core.events.util.Promise;
import com.b2international.snowowl.core.rest.AbstractRestService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
* @since 8.11.0
*/
@Tag(description = "Concepts", name = "concepts")
@RestController
@RequestMapping(value = "/concepts", produces = { AbstractRestService.JSON_MEDIA_TYPE })
public class ConceptSearchRestService extends AbstractRestService {

public ConceptSearchRestService() {
super(Set.of("id", "active"));
}

@Operation(
summary = "Search concepts",
description = "Returns a list of concepts matching the given search criteria."
)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "Invalid search config"),
})
@GetMapping
public Promise<Concepts> searchConcepts(@ParameterObject ConceptRestSearch params) {
return CodeSystemRequests.prepareSearchConcepts()
.filterByActive(params.getActive())
.filterByTerm(params.getTerm())
.filterByCodeSystems(params.getCodeSystem())
.filterByQuery(params.getQuery())
.setFields(params.getField())
.setExpand(params.getExpand())
.setLimit(params.getLimit())
.setSearchAfter(params.getSearchAfter())
.sortBy(extractSortFields(params.getSort()))
.buildAsync()
.execute(getBus());

Check warning on line 69 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptSearchRestService.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptSearchRestService.java#L58-L69

Added lines #L58 - L69 were not covered by tests
}

@Operation(
summary = "Search concepts",
description = "Returns a list of concepts matching the given search criteria."
)
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "Invalid search config"),
})
@PostMapping(value = "/search", consumes = { AbstractRestService.JSON_MEDIA_TYPE })
public Promise<Concepts> searchConceptsByPost(@RequestBody ConceptRestSearch params) {
return searchConcepts(params);

Check warning on line 82 in core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptSearchRestService.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core.rest/src/com/b2international/snowowl/core/rest/concepts/ConceptSearchRestService.java#L82

Added line #L82 was not covered by tests
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2020-2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@

import com.b2international.commons.exceptions.BadRequestException;
import com.b2international.commons.options.Options;
import com.b2international.snowowl.core.Repository;
import com.b2international.snowowl.core.RepositoryManager;
import com.b2international.snowowl.core.ResourceURI;
import com.b2international.snowowl.core.ServiceProvider;
Expand Down Expand Up @@ -94,7 +95,13 @@
.stream()
.map(codeSystem -> {
final ResourceURI uriToEvaluateOn = codeSystemResourceFiltersByResource.getOrDefault(codeSystem.getResourceURI(), codeSystem.getResourceURI());
return context.service(RepositoryManager.class).get(codeSystem.getToolingId()).service(ConceptSearchRequestEvaluator.class).evaluate(uriToEvaluateOn, context, conceptSearchOptions);
final Repository repository = context.service(RepositoryManager.class).get(codeSystem.getToolingId());
if (repository == null) {
context.log().warn("Tooling module '{}' is missing from this deployment.", codeSystem.getToolingId());
return new Concepts(0, 0);

Check warning on line 101 in core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/ConceptSearchRequest.java

View check run for this annotation

Codecov / codecov/patch

core/com.b2international.snowowl.core/src/com/b2international/snowowl/core/request/ConceptSearchRequest.java#L100-L101

Added lines #L100 - L101 were not covered by tests
} else {
return repository.service(ConceptSearchRequestEvaluator.class).evaluate(uriToEvaluateOn, context, conceptSearchOptions);
}
})
// .sorted(comparator) // TODO perform Java SORT on Concept fields
// .limit(limit)
Expand Down