Skip to content
New issue

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

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

Already on GitHub? # to your account

SO-4916: Add language to suggest API parameters #882

Merged
merged 5 commits into from
Aug 25, 2021
Merged
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 @@ -34,6 +34,9 @@ public class SuggestRestParameters {

@Parameter(description = "The preferred term display in case of SNOMED CT", example = "PT", schema = @Schema(allowableValues = {"FSN", "PT", "ID_ONLY"}, defaultValue = "PT"))
private String preferredDisplay = "PT";

@Parameter(description = "Accepted language tags, in order of preference")
private String acceptLanguage;

public String getCodeSystemPath() {
return codeSystemPath;
Expand Down Expand Up @@ -67,4 +70,11 @@ public void setPreferredDisplay(String preferredDisplay) {
this.preferredDisplay = preferredDisplay;
}

public String getAcceptLanguage() {
return acceptLanguage;
}

public void setAcceptLanguage(String acceptLanguage) {
this.acceptLanguage = acceptLanguage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.util.List;
import java.util.stream.Collectors;

import org.elasticsearch.common.Strings;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import com.b2international.snowowl.core.codesystem.CodeSystemRequests;
Expand All @@ -29,6 +31,7 @@
import com.b2international.snowowl.core.rest.AbstractRestService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -51,9 +54,16 @@ public class SuggestRestService extends AbstractRestService {
@ApiResponse(responseCode = "400", description = "Bad Request")
})
@GetMapping
public Promise<Suggestions> getSuggest(@ParameterObject final SuggestRestParameters params) {
public Promise<Suggestions> getSuggest(
@ParameterObject
final SuggestRestParameters params,

@Parameter(description = "Accepted language tags, in order of preference", example = "en-US;q=0.8,en-GB;q=0.6")
@RequestHeader(value=HttpHeaders.ACCEPT_LANGUAGE, defaultValue="en-US;q=0.8,en-GB;q=0.6", required=false)
final String acceptLanguage) {
return CodeSystemRequests.prepareSuggestConcepts()
.setLimit(params.getLimit())
.setLocales(Strings.isNullOrEmpty(params.getAcceptLanguage()) ? acceptLanguage : params.getAcceptLanguage())
.setPreferredDisplay(params.getPreferredDisplay())
.filterByTerm(params.getTerm())
.sortBy(SORT_BY)
Expand All @@ -69,9 +79,16 @@ public Promise<Suggestions> getSuggest(@ParameterObject final SuggestRestParamet
@ApiResponse(responseCode = "400", description = "Bad Request")
})
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
public Promise<Suggestions> postSuggest(@RequestBody final SuggestRestParameters body) {
public Promise<Suggestions> postSuggest(
@RequestBody
final SuggestRestParameters body,

@Parameter(description = "Accepted language tags, in order of preference", example = "en-US;q=0.8,en-GB;q=0.6")
@RequestHeader(value=HttpHeaders.ACCEPT_LANGUAGE, defaultValue="en-US;q=0.8,en-GB;q=0.6", required=false)
final String acceptLanguage) {
return CodeSystemRequests.prepareSuggestConcepts()
.setLimit(body.getLimit())
.setLocales(Strings.isNullOrEmpty(body.getAcceptLanguage()) ? acceptLanguage : body.getAcceptLanguage())
.setPreferredDisplay(body.getPreferredDisplay())
.filterByTerm(body.getTerm())
.sortBy(SORT_BY)
Expand All @@ -87,10 +104,17 @@ public Promise<Suggestions> postSuggest(@RequestBody final SuggestRestParameters
@ApiResponse(responseCode = "400", description = "Bad Request")
})
@PostMapping(value = "/bulk", consumes = { AbstractRestService.JSON_MEDIA_TYPE })
public Promise<List<Object>> postBulkSuggest(@RequestBody final List<SuggestRestParameters> body) {
public Promise<List<Object>> postBulkSuggest(
@RequestBody
final List<SuggestRestParameters> body,

@Parameter(description = "Accepted language tags, in order of preference", example = "en-US;q=0.8,en-GB;q=0.6")
@RequestHeader(value=HttpHeaders.ACCEPT_LANGUAGE, defaultValue="en-US;q=0.8,en-GB;q=0.6", required=false)
final String acceptLanguage) {
final List<Promise<Suggestions>> promises = body.stream().map(params -> {
return CodeSystemRequests.prepareSuggestConcepts()
.setLimit(params.getLimit())
.setLocales(Strings.isNullOrEmpty(params.getAcceptLanguage()) ? acceptLanguage : params.getAcceptLanguage())
.setPreferredDisplay(params.getPreferredDisplay())
.filterByTerm(params.getTerm())
.sortBy(SORT_BY)
Expand Down