-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7040 from davidwatkins73/waltz-7039-licence-search
Licences - search for licences from navbar
- Loading branch information
Showing
7 changed files
with
137 additions
and
5 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
20 changes: 20 additions & 0 deletions
20
waltz-common/src/test/java/org/finos/waltz/common/ListUtilities_distinct.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.finos.waltz.common; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.finos.waltz.common.ListUtilities.asList; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ListUtilities_distinct { | ||
|
||
@Test | ||
public void distinctDedupesListsButPreservesInitialOrder() { | ||
List<String> xs = asList("a", "b", "c", "c", "b", "c", "d"); | ||
List<String> uniq = ListUtilities.distinct(xs); | ||
assertEquals(asList("a", "b", "c", "d"), uniq); | ||
} | ||
|
||
|
||
} |
70 changes: 70 additions & 0 deletions
70
waltz-data/src/main/java/org/finos/waltz/data/licence/search/LicenceSearchDao.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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.finos.waltz.data.licence.search; | ||
|
||
import org.finos.waltz.common.ListUtilities; | ||
import org.finos.waltz.data.SearchDao; | ||
import org.finos.waltz.data.legal_entity.LegalEntityDao; | ||
import org.finos.waltz.data.licence.LicenceDao; | ||
import org.finos.waltz.model.entity_search.EntitySearchOptions; | ||
import org.finos.waltz.model.legal_entity.LegalEntity; | ||
import org.finos.waltz.model.licence.Licence; | ||
import org.jooq.Condition; | ||
import org.jooq.DSLContext; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.TreeSet; | ||
|
||
import static java.util.Collections.emptyList; | ||
import static org.finos.waltz.common.ListUtilities.concat; | ||
import static org.finos.waltz.data.JooqUtilities.mkBasicTermSearch; | ||
import static org.finos.waltz.data.JooqUtilities.mkStartsWithTermSearch; | ||
import static org.finos.waltz.data.SearchUtilities.mkTerms; | ||
import static org.finos.waltz.schema.Tables.LICENCE; | ||
|
||
@Service | ||
public class LicenceSearchDao implements SearchDao<Licence> { | ||
|
||
private final DSLContext dsl; | ||
|
||
|
||
@Autowired | ||
public LicenceSearchDao(DSLContext dsl) { | ||
this.dsl = dsl; | ||
} | ||
|
||
|
||
/** | ||
* Searches by <code>name</code> and <code>external_id</code> | ||
* @param options | ||
* @return List of matching legal entities, | ||
* matches on name are given precedence over external_id matches | ||
*/ | ||
@Override | ||
public List<Licence> search(EntitySearchOptions options) { | ||
List<String> terms = mkTerms(options.searchQuery()); | ||
if (terms.isEmpty()) { | ||
return emptyList(); | ||
} | ||
|
||
Condition nameCondition = mkBasicTermSearch(LICENCE.NAME, terms); | ||
Condition externalIdCondition = mkStartsWithTermSearch(LICENCE.EXTERNAL_ID, terms); | ||
|
||
return ListUtilities.distinct(concat( | ||
mkQuery(nameCondition, options), | ||
mkQuery(externalIdCondition, options))); | ||
} | ||
|
||
|
||
private List<Licence> mkQuery(Condition nameCondition, EntitySearchOptions options) { | ||
return dsl | ||
.select(LICENCE.fields()) | ||
.from(LICENCE) | ||
.where(nameCondition) | ||
.orderBy(LICENCE.NAME) | ||
.limit(options.limit()) | ||
.fetch(LicenceDao.TO_DOMAIN_MAPPER); | ||
} | ||
|
||
} |
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
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