Skip to content

Commit

Permalink
Merge pull request #186 from Open-MBEE/release/4.0.7
Browse files Browse the repository at this point in the history
Release/4.0.7
  • Loading branch information
HuiJun authored Feb 25, 2022
2 parents 0b73243 + d3db5c5 commit 415a597
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 156 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:11.0.8-jdk
FROM openjdk:11-jdk-slim
COPY . /mms
WORKDIR /mms
RUN ./gradlew --no-daemon bootJar
Expand Down
6 changes: 0 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ subprojects {
maven { url 'https://repo.spring.io/plugins-release' }
}

plugins.withType(JavaPlugin) {
project.sourceCompatibility = '10'
project.targetCompatibility = '10'
}

apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'io.spring.dependency-management'
Expand Down Expand Up @@ -162,5 +157,4 @@ subprojects {
sign publishing.publications.mavenJava
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ public ElementsSearchResponse recursiveSearch(String projectId, String refId, Ma
showDeletedAsRejected = true;
}

performRecursiveSearch(allNodeDocIds, params, recurse, elementJsonMap,0);
Map<String, List<String>> normalizedParams = new HashMap<>();
params.forEach((k, v) -> {
List<String> values = new ArrayList<>();
values.add(v);
normalizedParams.put(k, values);
});

performRecursiveSearch(allNodeDocIds, normalizedParams, recurse, elementJsonMap,0);
Collection<OrderedResult<ElementJson>> filteredElementJson = filterIndexedElementsUsingDatabaseNodes(allNodes, elementJsonMap, deletedElements, showDeletedAsRejected);
return prepareResponse(filteredElementJson, deletedElements, from, size);
} catch (IOException e) {
Expand All @@ -114,23 +121,25 @@ public ElementsSearchResponse recursiveSearch(String projectId, String refId, Ma

}

private void performRecursiveSearch(Set<String> allNodeDocIds, Map<String, String> params, Map<String, String> recurse,
private void performRecursiveSearch(Set<String> allNodeDocIds, Map<String, List<String>> params, Map<String, String> recurse,
Map<String, OrderedResult<ElementJson>> elementJsonMap, Integer count) throws IOException {
Set<String> fields = new HashSet<>(params.keySet());
if(recurse != null) {
fields.addAll(recurse.keySet());
}
SearchConfiguration searchConfiguration = getSearchConfiguration(fields);
List<ElementJson> elementJsonList = doSearch(searchConfiguration, allNodeDocIds, params);
List<ElementJson> obList = new ArrayList<>();
for(ElementJson ob : elementJsonList) {
if(!elementJsonMap.containsKey(ob.getId())) {
elementJsonMap.put(ob.getId(), new OrderedResult<>(ob, count++));
Map<String, String> recursiveParams = buildRecursiveParams(ob, recurse);
if(!recursiveParams.isEmpty()) {
performRecursiveSearch(allNodeDocIds, recursiveParams, recurse, elementJsonMap, count);
}
obList.add(ob);
}
}
Map<String, List<String>> recursiveParams = buildRecursiveParams(obList, recurse);
if(!recursiveParams.isEmpty()) {
performRecursiveSearch(allNodeDocIds, recursiveParams, recurse, elementJsonMap, count);
}
}

private SearchConfiguration getSearchConfiguration(Set<String> fields) {
Expand Down Expand Up @@ -159,30 +168,36 @@ private SearchConfiguration getSearchConfiguration(Set<String> fields) {
}
}

private Map<String, String> buildRecursiveParams(ElementJson ob, Map<String, String> recurse) {
Map<String, String> recursiveParams = new HashMap<>();
private Map<String, List<String>> buildRecursiveParams(List<ElementJson> obList, Map<String, String> recurse) {
Map<String, List<String>> recursiveParams = new HashMap<>();

if(recurse == null || recurse.isEmpty()) {
return recursiveParams;
}

for(Map.Entry<String, String> e : recurse.entrySet()) {
Object o = ob.get(e.getKey());
if(o == null) {
continue;
List<String> oList = new ArrayList<>();
for (ElementJson ob : obList) {
Object o = ob.get(e.getKey());
if (o == null) {
continue;
}
oList.add(o.toString());
}
if (!oList.isEmpty()) {
recursiveParams.put(e.getValue(), oList);
}
recursiveParams.put(e.getValue(), o.toString());
}
return recursiveParams;
}


private List<ElementJson> doSearch(SearchConfiguration searchConfiguration, Set<String> allNodeDocIds, Map<String, String> params) throws IOException {
private List<ElementJson> doSearch(SearchConfiguration searchConfiguration, Set<String> allNodeDocIds, Map<String, List<String>> params) throws IOException {
SearchRequest searchRequest = new SearchRequest(Index.NODE.get());
BoolQueryBuilder query = QueryBuilders.boolQuery();

for(Map.Entry<String, String> e : params.entrySet()) {
searchConfiguration.addQueryForField(query, e.getKey(), e.getValue());
for(Map.Entry<String, List<String>> e : params.entrySet()) {
searchConfiguration.addQueryForField(query, e.getKey(), e.getValue());
}

return performElasticQuery(allNodeDocIds, searchRequest, query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SearchConfiguration {
Expand Down Expand Up @@ -35,9 +36,9 @@ public void addField(String field, String type, boolean searchable) {
}
}

public BoolQueryBuilder addQueryForField(BoolQueryBuilder query, String field, String value) {
public BoolQueryBuilder addQueryForField(BoolQueryBuilder query, String field, Object value) {
if("*".equals(field)) {
query.must(QueryBuilders.multiMatchQuery(value, "*"));
query.must(QueryBuilders.multiMatchQuery(value.toString(), "*"));
} else {
EnumSearchType searchType = config.get(field);
if(searchType == null) {
Expand All @@ -46,7 +47,11 @@ public BoolQueryBuilder addQueryForField(BoolQueryBuilder query, String field, S
}
switch (searchType){
case TERM:
query.must(QueryBuilders.termQuery(field, value));
if (value instanceof List) {
query.must(QueryBuilders.termsQuery(field, ((List<?>) value).toArray()));
} else if (value instanceof String) {
query.must(QueryBuilders.termQuery(field, value));
}
break;
case MATCH:
query.must(QueryBuilders.matchQuery(field, value));
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=4.0.6
version=4.0.7
group=org.openmbee.mms

springBootVersion=2.2.6.RELEASE
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 415a597

Please sign in to comment.