-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOLR functionalty was moved to sparate location (#2196)
- Loading branch information
1 parent
8adbdd3
commit f17a1b7
Showing
10 changed files
with
101 additions
and
94 deletions.
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