Skip to content

Commit

Permalink
Merge pull request #4343 from deutschebank/db-contrib/waltz-4340-impr…
Browse files Browse the repository at this point in the history
…ove-search-app-group

Db contrib/waltz 4340 improve search app group
  • Loading branch information
davidwatkins73 committed Sep 16, 2019
2 parents 32e1a80 + 7d3b6ca commit 5081bb9
Showing 1 changed file with 15 additions and 4 deletions.
Expand Up @@ -32,16 +32,19 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import static com.khartec.waltz.common.Checks.checkNotNull;
import static com.khartec.waltz.common.StringUtilities.mkSafe;
import static com.khartec.waltz.data.SearchUtilities.mkTerms;
import static com.khartec.waltz.schema.Tables.*;
import static com.khartec.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP;
import static com.khartec.waltz.schema.tables.ApplicationGroupMember.APPLICATION_GROUP_MEMBER;
import static com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT;

@Repository
public class AppGroupDao {
Expand Down Expand Up @@ -190,19 +193,27 @@ public List<AppGroup> findPublicGroups() {
}


public List<AppGroup> search(String terms, EntitySearchOptions options) {
checkNotNull(terms, "terms cannot be null");
public List<AppGroup> search(String query, EntitySearchOptions options) {
checkNotNull(query, "query cannot be null");
checkNotNull(options, "options cannot be null");

Condition searchCondition = APPLICATION_GROUP.NAME.like("%" + terms + "%");
List<String> terms = mkTerms(query);
if (terms.isEmpty()) {
return Collections.emptyList();
}

Condition searchCondition = terms.stream()
.map(term -> APPLICATION_GROUP.NAME.like("%" + term + "%"))
.collect(Collectors.reducing(
DSL.trueCondition(),
(acc, frag) -> acc.and(frag)));

Select<Record> publicGroups = dsl.select(APPLICATION_GROUP.fields())
.from(APPLICATION_GROUP)
.where(APPLICATION_GROUP.KIND.eq(AppGroupKind.PUBLIC.name())
.and(searchCondition))
.and(notRemoved);


Select<Record1<Long>> userGroupIds = DSL.select(APPLICATION_GROUP_MEMBER.GROUP_ID)
.from(APPLICATION_GROUP_MEMBER)
.where(APPLICATION_GROUP_MEMBER.USER_ID.eq(options.userId())
Expand Down

0 comments on commit 5081bb9

Please sign in to comment.