-
Notifications
You must be signed in to change notification settings - Fork 170
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
solr functionalty was moved to sparate location #2196
Merged
+101
−94
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ohdsi/webapi/security/SecurityConfigurationInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 20 additions & 6 deletions
26
src/main/java/org/ohdsi/webapi/vocabulary/DatabaseSearchProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,39 @@ | ||
package org.ohdsi.webapi.vocabulary; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
import org.ohdsi.webapi.service.VocabularyService; | ||
import org.ohdsi.webapi.source.Source; | ||
import org.ohdsi.webapi.source.SourceRepository; | ||
import org.ohdsi.webapi.util.PreparedStatementRenderer; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class DatabaseSearchProvider implements SearchProvider { | ||
@Autowired | ||
private SourceRepository sourceRepository; | ||
|
||
private final static int VOCABULARY_PRIORITY = Integer.MAX_VALUE; | ||
|
||
@Autowired | ||
VocabularyService vocabService; | ||
|
||
@Override | ||
public boolean supports(VocabularySearchProviderType type) { | ||
return Objects.equals(type, VocabularySearchProviderType.DATABASE); | ||
public boolean supports(String vocabularyVersionKey) { | ||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public int getPriority() { | ||
return VOCABULARY_PRIORITY; | ||
} | ||
|
||
@Override | ||
public Collection<Concept> executeSearch(SearchProviderConfig config, String query, String rows) throws Exception { | ||
PreparedStatementRenderer psr = vocabService.prepareExecuteSearchWithQuery(query, config.getSource()); | ||
return vocabService.getSourceJdbcTemplate(config.getSource()).query(psr.getSql(), psr.getSetter(), vocabService.getRowMapper()); | ||
Source source = sourceRepository.findBySourceKey(config.getSourceKey()); | ||
|
||
PreparedStatementRenderer psr = vocabService.prepareExecuteSearchWithQuery(query, source); | ||
return vocabService.getSourceJdbcTemplate(source).query(psr.getSql(), psr.getSetter(), vocabService.getRowMapper()); | ||
} | ||
} |
8 changes: 6 additions & 2 deletions
8
src/main/java/org/ohdsi/webapi/vocabulary/SearchProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package org.ohdsi.webapi.vocabulary; | ||
|
||
import org.ohdsi.webapi.vocabulary.Concept; | ||
import org.ohdsi.webapi.vocabulary.SearchProviderConfig; | ||
|
||
import java.util.Collection; | ||
|
||
public interface SearchProvider { | ||
public abstract boolean supports(VocabularySearchProviderType type); | ||
public abstract Collection<Concept> executeSearch(SearchProviderConfig config, String query, String rows) throws Exception; | ||
boolean supports(String vocabularyVersionKey); | ||
int getPriority(); | ||
Collection<Concept> executeSearch(SearchProviderConfig config, String query, String rows) throws Exception; | ||
} |
18 changes: 7 additions & 11 deletions
18
src/main/java/org/ohdsi/webapi/vocabulary/SearchProviderConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
package org.ohdsi.webapi.vocabulary; | ||
|
||
import org.ohdsi.webapi.source.Source; | ||
|
||
public class SearchProviderConfig { | ||
protected Source source; | ||
protected VocabularyInfo vocabularyInfo; | ||
protected String versionKey; | ||
private String sourceKey; | ||
private String versionKey; | ||
|
||
public SearchProviderConfig(Source source, VocabularyInfo vocabularyInfo) { | ||
this.source = source; | ||
this.vocabularyInfo = vocabularyInfo; | ||
this.versionKey = vocabularyInfo.version.replace(' ', '_'); | ||
public SearchProviderConfig(String sourceKey, String versionKey) { | ||
this.sourceKey = sourceKey; | ||
this.versionKey = versionKey; | ||
} | ||
|
||
public String getVersionKey() { | ||
return versionKey; | ||
} | ||
|
||
public Source getSource() { | ||
return source; | ||
public String getSourceKey() { | ||
return sourceKey; | ||
} | ||
} |
53 changes: 13 additions & 40 deletions
53
src/main/java/org/ohdsi/webapi/vocabulary/VocabularySearchServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,30 @@ | ||
package org.ohdsi.webapi.vocabulary; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import javax.annotation.PostConstruct; | ||
import org.ohdsi.webapi.service.VocabularyService; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class VocabularySearchServiceImpl implements VocabularySearchService { | ||
protected final Logger log = LoggerFactory.getLogger(getClass()); | ||
private static HashSet<String> availableVocabularyFullTextIndices = new HashSet<>(); | ||
private final List<SearchProvider> searchProviderList; | ||
|
||
private static final String NO_PROVIDER_ERROR = "There is no vocabulary search provider which for sourceKey: %s"; | ||
|
||
@Autowired | ||
VocabularyService vocabService; | ||
|
||
@Autowired | ||
SolrSearchClient solrSearchClient; | ||
|
||
@PostConstruct | ||
protected void init() { | ||
// Get the SOLR cores list if enabled | ||
if (solrSearchClient.enabled()) { | ||
try { | ||
availableVocabularyFullTextIndices = solrSearchClient.getCores(); | ||
} catch (Exception ex) { | ||
log.error("SOLR Core Initialization Error: WebAPI was unable to obtain the list of available cores.", ex); | ||
} | ||
} | ||
} | ||
|
||
public VocabularySearchServiceImpl(List<SearchProvider> searchProviderList) { | ||
this.searchProviderList = searchProviderList; | ||
|
||
private final SearchProvider[] searchProviders; | ||
|
||
public VocabularySearchServiceImpl(SearchProvider[] searchProviders) { | ||
this.searchProviders = searchProviders; | ||
} | ||
|
||
@Override | ||
public SearchProvider getSearchProvider(SearchProviderConfig config) { | ||
VocabularySearchProviderType type = VocabularySearchProviderType.DATABASE; | ||
if (availableVocabularyFullTextIndices.contains(config.getVersionKey())) { | ||
type = VocabularySearchProviderType.SOLR; | ||
} | ||
return selectSearchProvider(type, config); | ||
} | ||
|
||
private SearchProvider selectSearchProvider(VocabularySearchProviderType type, SearchProviderConfig config) { | ||
return searchProviderList.stream() | ||
.filter(p -> p.supports(type)) | ||
return Arrays.stream(searchProviders) | ||
.sorted(Comparator.comparingInt(SearchProvider::getPriority)) | ||
.filter(p -> p.supports(config.getVersionKey())) | ||
.findFirst() | ||
.orElseThrow(() -> new RuntimeException(String.format(NO_PROVIDER_ERROR, config.getSource().getSourceKey()))); | ||
.orElseThrow(() -> new RuntimeException(String.format(NO_PROVIDER_ERROR, config.getSourceKey()))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...i/webapi/vocabulary/SolrSearchClient.java → ...api/vocabulary/solr/SolrSearchClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, it appears that the original implementation provided an API to 'ask' the instance if it supported a particular Type. Ie: if you ask the SOLRSearchProvider if it supports VocabularySearchProviderType.DATABASE, it would return false, and if you asked the DatabaseProvider if it supports VocabularySearchProviderType.SOLR, it would return false. Now, supports seems to work off of a vocabularyVersionKey. This seems like a big divergance between the semantics of the
supports()
function. If we want something specific for vocabulary version support, shouldn't we have a function that indicates that we're asking something related to the vocabularyVersion?