Search in sources :

Example 1 with PHYSICAL_SPECIFICATION

use of com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION in project waltz by khartec.

the class PhysicalFlowSearchDao method searchReports.

/**
 * A report is a physical flow which goes to an
 * external actor
 * @param query
 * @return
 */
public List<EntityReference> searchReports(String query) {
    if (isEmpty(query)) {
        return emptyList();
    }
    Field<String> nameField = DSL.concat(PHYSICAL_SPECIFICATION.NAME, DSL.value(" - "), ACTOR.NAME);
    Condition termMatcher = mkTerms(query).stream().reduce(DSL.trueCondition(), (acc, t) -> nameField.like("%" + t + "%"), (acc, t) -> acc.and(t));
    return dsl.select(PHYSICAL_FLOW.ID, nameField).from(PHYSICAL_FLOW).innerJoin(PHYSICAL_SPECIFICATION).on(PHYSICAL_FLOW.SPECIFICATION_ID.eq(PHYSICAL_SPECIFICATION.ID)).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(PHYSICAL_FLOW.LOGICAL_FLOW_ID)).innerJoin(ACTOR).on(LOGICAL_FLOW.TARGET_ENTITY_ID.eq(ACTOR.ID).and(ACTOR.IS_EXTERNAL.eq(true))).where(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.ACTOR.name())).and(termMatcher).fetch().stream().map(r -> mkRef(EntityKind.PHYSICAL_FLOW, r.value1(), r.value2())).collect(Collectors.toList());
}
Also used : Condition(org.jooq.Condition) PHYSICAL_SPECIFICATION(com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION) DSL(org.jooq.impl.DSL) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) Collections.emptyList(java.util.Collections.emptyList) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityReference(com.khartec.waltz.model.EntityReference) Field(org.jooq.Field) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) PHYSICAL_FLOW(com.khartec.waltz.schema.tables.PhysicalFlow.PHYSICAL_FLOW) EntityKind(com.khartec.waltz.model.EntityKind) List(java.util.List) ACTOR(com.khartec.waltz.schema.tables.Actor.ACTOR) DSLContext(org.jooq.DSLContext) StringUtilities.isEmpty(com.khartec.waltz.common.StringUtilities.isEmpty) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) Repository(org.springframework.stereotype.Repository) EntityReference.mkRef(com.khartec.waltz.model.EntityReference.mkRef) LOGICAL_FLOW(com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW)

Example 2 with PHYSICAL_SPECIFICATION

use of com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION in project waltz by khartec.

the class PhysicalSpecificationGenerator method main.

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> appIds = dsl.select(APPLICATION.ID).from(APPLICATION).fetch(APPLICATION.ID);
    List<PhysicalSpecificationRecord> records = appIds.stream().flatMap(appId -> IntStream.range(0, rnd.nextInt(4)).mapToObj(i -> tuple(appId, i))).map(t -> {
        String name = mkName(t.v2);
        PhysicalSpecificationRecord record = dsl.newRecord(PHYSICAL_SPECIFICATION);
        record.setOwningEntityId(t.v1);
        record.setOwningEntityKind(EntityKind.APPLICATION.name());
        record.setFormat(randomPick(DataFormatKind.values()).name());
        record.setProvenance("DEMO");
        record.setDescription("Desc " + name + " " + t.v2);
        record.setName(name);
        record.setExternalId("ext-" + t.v1 + "." + t.v2);
        record.setLastUpdatedBy("admin");
        return record;
    }).collect(Collectors.toList());
    System.out.println("---deleting old demo records");
    dsl.deleteFrom(PHYSICAL_SPECIFICATION).where(PHYSICAL_SPECIFICATION.PROVENANCE.eq("DEMO")).execute();
    System.out.println("---saving: " + records.size());
    dsl.batchInsert(records).execute();
    System.out.println("---done");
}
Also used : IntStream(java.util.stream.IntStream) PHYSICAL_SPECIFICATION(com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION) ArrayUtilities.randomPick(com.khartec.waltz.common.ArrayUtilities.randomPick) Random(java.util.Random) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) List(java.util.List) DIConfiguration(com.khartec.waltz.service.DIConfiguration) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) PhysicalSpecificationRecord(com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord) DataFormatKind(com.khartec.waltz.model.physical_specification.DataFormatKind) DSLContext(org.jooq.DSLContext) APPLICATION(com.khartec.waltz.schema.tables.Application.APPLICATION) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PhysicalSpecificationRecord(com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord) DSLContext(org.jooq.DSLContext)

Example 3 with PHYSICAL_SPECIFICATION

use of com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION in project waltz by khartec.

the class PhysicalSpecificationSearchDao method search.

public List<PhysicalSpecification> search(String termsStr, EntitySearchOptions options) {
    List<String> terms = mkTerms(termsStr);
    if (terms.isEmpty()) {
        return newArrayList();
    }
    Condition likeName = mkBasicTermSearch(PHYSICAL_SPECIFICATION.NAME, terms);
    Condition likeDesc = mkBasicTermSearch(PHYSICAL_SPECIFICATION.DESCRIPTION, terms);
    SelectQuery<Record> query = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).where(likeName).or(likeDesc).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(mkRelevancyComparator(ps -> ps.name(), terms.get(0)));
    return results;
}
Also used : Condition(org.jooq.Condition) Record(org.jooq.Record) PHYSICAL_SPECIFICATION(com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION) PhysicalSpecificationDao.owningEntityNameField(com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao.owningEntityNameField) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) ListUtilities(com.khartec.waltz.common.ListUtilities) Autowired(org.springframework.beans.factory.annotation.Autowired) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) Condition(org.jooq.Condition) SearchUtilities.mkRelevancyComparator(com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator) List(java.util.List) PhysicalSpecificationDao(com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao) DSLContext(org.jooq.DSLContext) Optional(java.util.Optional) ImmutablePhysicalSpecification(com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SelectQuery(org.jooq.SelectQuery) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) Repository(org.springframework.stereotype.Repository) JooqUtilities.mkBasicTermSearch(com.khartec.waltz.data.JooqUtilities.mkBasicTermSearch) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) ImmutablePhysicalSpecification(com.khartec.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) Record(org.jooq.Record)

Aggregations

PHYSICAL_SPECIFICATION (com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION)3 List (java.util.List)3 DSLContext (org.jooq.DSLContext)3 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)2 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)2 EntityKind (com.khartec.waltz.model.EntityKind)2 Collectors (java.util.stream.Collectors)2 Condition (org.jooq.Condition)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Repository (org.springframework.stereotype.Repository)2 ArrayUtilities.randomPick (com.khartec.waltz.common.ArrayUtilities.randomPick)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1 ListUtilities.newArrayList (com.khartec.waltz.common.ListUtilities.newArrayList)1 StringUtilities.isEmpty (com.khartec.waltz.common.StringUtilities.isEmpty)1 JooqUtilities.mkBasicTermSearch (com.khartec.waltz.data.JooqUtilities.mkBasicTermSearch)1 SearchUtilities.mkRelevancyComparator (com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator)1 PhysicalSpecificationDao (com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao)1 PhysicalSpecificationDao.owningEntityNameField (com.khartec.waltz.data.physical_specification.PhysicalSpecificationDao.owningEntityNameField)1 EntityReference (com.khartec.waltz.model.EntityReference)1 EntityReference.mkRef (com.khartec.waltz.model.EntityReference.mkRef)1