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());
}
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");
}
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;
}
Aggregations