use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.
the class PhysicalSpecificationSearchDao method search.
@Override
public List<PhysicalSpecification> search(EntitySearchOptions options) {
List<String> terms = SearchUtilities.mkTerms(options.searchQuery());
if (terms.isEmpty()) {
return newArrayList();
}
Condition likeName = JooqUtilities.mkBasicTermSearch(PHYSICAL_SPECIFICATION.NAME, terms);
Condition likeDesc = JooqUtilities.mkBasicTermSearch(PHYSICAL_SPECIFICATION.DESCRIPTION, terms);
Condition likeExternalIdentifier = JooqUtilities.mkStartsWithTermSearch(PHYSICAL_SPECIFICATION.EXTERNAL_ID, terms).or(JooqUtilities.mkStartsWithTermSearch(EXTERNAL_IDENTIFIER.EXTERNAL_ID, terms));
Condition searchFilter = likeName.or(likeDesc).or(likeExternalIdentifier);
SelectQuery<Record> query = dsl.selectDistinct(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).leftOuterJoin(PHYSICAL_FLOW).on(PHYSICAL_FLOW.SPECIFICATION_ID.eq(PHYSICAL_SPECIFICATION.ID)).leftOuterJoin(EXTERNAL_IDENTIFIER).on(EXTERNAL_IDENTIFIER.ENTITY_KIND.eq(EntityKind.PHYSICAL_FLOW.name()).and(EXTERNAL_IDENTIFIER.ENTITY_ID.eq(PHYSICAL_FLOW.ID))).where(PHYSICAL_SPECIFICATION.IS_REMOVED.eq(false)).and(searchFilter).orderBy(PHYSICAL_SPECIFICATION.NAME).limit(options.limit()).getQuery();
List<PhysicalSpecification> results = query.fetch(r -> {
PhysicalSpecification spec = PhysicalSpecificationDao.TO_DOMAIN_MAPPER.map(r);
String updatedDesc = String.format("%s %s", Optional.ofNullable(r.getValue(owningEntityNameField)).map(owner -> String.format("(%s)", owner)).orElse(""), spec.description());
return ImmutablePhysicalSpecification.copyOf(spec).withDescription(updatedDesc);
});
results.sort(SearchUtilities.mkRelevancyComparator(NameProvider::name, terms.get(0)));
return results;
}
Aggregations