Search in sources :

Example 21 with PhysicalSpecification

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;
}
Also used : Condition(org.jooq.Condition) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) Record(org.jooq.Record)

Aggregations

PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)21 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)16 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)13 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)9 Test (org.junit.jupiter.api.Test)9 PhysicalFlow (org.finos.waltz.model.physical_flow.PhysicalFlow)4 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 String.format (java.lang.String.format)2 LocalDateTime (java.time.LocalDateTime)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 DateTimeUtilities.nowUtc (org.finos.waltz.common.DateTimeUtilities.nowUtc)2 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)2 StringUtilities.isEmpty (org.finos.waltz.common.StringUtilities.isEmpty)2 PhysicalFlowDao (org.finos.waltz.data.physical_flow.PhysicalFlowDao)2 org.finos.waltz.model (org.finos.waltz.model)2