Search in sources :

Example 1 with MEASURABLE

use of org.finos.waltz.schema.tables.Measurable.MEASURABLE in project waltz by khartec.

the class MeasurableStressGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    LOG.info("Ensuring category exists");
    Long categoryId = WaltzUtilities.getOrCreateMeasurableCategory(dsl, "STRESS", "Stress Test");
    LOG.info("Deleting existing records");
    dsl.deleteFrom(MEASURABLE).where(MEASURABLE.MEASURABLE_CATEGORY_ID.eq(categoryId)).execute();
    LOG.info("Generating records");
    List<MeasurableRecord> records = mkNodes(1, "").stream().map(t -> {
        MeasurableRecord mr = new MeasurableRecord();
        mr.setExternalId(t.v1);
        mr.setExternalParentId(t.v2);
        mr.setDescription(t.v1);
        mr.setName(t.v1);
        mr.setConcrete(true);
        mr.setLastUpdatedBy("admin");
        mr.setProvenance("stress");
        mr.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        mr.setMeasurableCategoryId(categoryId);
        return mr;
    }).collect(Collectors.toList());
    LOG.info("Inserting {} records into category {}", records.size(), categoryId);
    dsl.batchInsert(records).execute();
    LOG.info("Done");
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) DIConfiguration(org.finos.waltz.service.DIConfiguration) Random(java.util.Random) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ArrayList(java.util.ArrayList) WaltzUtilities(org.finos.waltz.jobs.WaltzUtilities) RandomUtilities(org.finos.waltz.common.RandomUtilities) Tuple2(org.jooq.lambda.tuple.Tuple2) List(java.util.List) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) DSLContext(org.jooq.DSLContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) DSLContext(org.jooq.DSLContext)

Example 2 with MEASURABLE

use of org.finos.waltz.schema.tables.Measurable.MEASURABLE in project waltz by khartec.

the class BookmarkGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<EntityReference> appRefs = dsl.select(APPLICATION.NAME, APPLICATION.ID).from(APPLICATION).fetch(r -> EntityReference.mkRef(EntityKind.APPLICATION, r.value2(), r.value1()));
    List<EntityReference> measurableRefs = dsl.select(MEASURABLE.NAME, MEASURABLE.ID).from(MEASURABLE).fetch(r -> EntityReference.mkRef(EntityKind.MEASURABLE, r.value2(), r.value1()));
    List<EntityReference> ouRefs = dsl.select(ORGANISATIONAL_UNIT.NAME, ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(r -> EntityReference.mkRef(EntityKind.ORG_UNIT, r.value2(), r.value1()));
    List<EntityReference> appGroupRefs = dsl.select(APPLICATION_GROUP.NAME, APPLICATION_GROUP.ID).from(APPLICATION_GROUP).fetch(r -> EntityReference.mkRef(EntityKind.APP_GROUP, r.value2(), r.value1()));
    List<EntityReference> refs = ListUtilities.concat(appRefs, measurableRefs, ouRefs, appGroupRefs);
    List<BookmarkRecord> bookmarks = refs.stream().flatMap(r -> RandomUtilities.randomlySizedIntStream(2, 15).mapToObj(idx -> {
        BookmarkRecord record = dsl.newRecord(BOOKMARK);
        record.setParentKind(r.kind().name());
        record.setParentId(r.id());
        record.setTitle(mkText(r.name().get()));
        record.setDescription(mkText(r.name().get()));
        record.setKind(randomPick(bookmarkKinds));
        record.setUrl(mkUrl(r.name().get()));
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setLastUpdatedBy("admin");
        record.setUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
        record.setCreatedAt(DateTimeUtilities.nowUtcTimestamp());
        return record;
    })).collect(Collectors.toList());
    dsl.batchStore(bookmarks).execute();
    return null;
}
Also used : APPLICATION(org.finos.waltz.schema.tables.Application.APPLICATION) EntityKind(org.finos.waltz.model.EntityKind) Random(java.util.Random) BookmarkRecord(org.finos.waltz.schema.tables.records.BookmarkRecord) BOOKMARK(org.finos.waltz.schema.tables.Bookmark.BOOKMARK) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) ORGANISATIONAL_UNIT(org.finos.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) ListUtilities(org.finos.waltz.common.ListUtilities) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) APPLICATION_GROUP(org.finos.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) EntityReference(org.finos.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) BookmarkRecord(org.finos.waltz.schema.tables.records.BookmarkRecord)

Example 3 with MEASURABLE

use of org.finos.waltz.schema.tables.Measurable.MEASURABLE in project waltz by khartec.

the class MeasurableGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    System.out.println("Importing data for category: " + category);
    Supplier<List<String>> lineSupplier = Unchecked.supplier(() -> readLines(getClass().getResourceAsStream("/" + category + ".tsv")));
    long categoryId = getCategory(dsl);
    List<String> lines = lineSupplier.get();
    List<String[]> sheet = lineSupplier.get().stream().skip(1).map(line -> line.split("\\t")).filter(cells -> cells.length > 3).collect(Collectors.toList());
    List<MeasurableRecord> records = sheet.stream().map(cells -> {
        MeasurableRecord record = dsl.newRecord(MEASURABLE);
        record.setName(cells[2]);
        record.setDescription(cells[3]);
        record.setMeasurableCategoryId(categoryId);
        record.setLastUpdatedBy("admin");
        record.setProvenance(SAMPLE_DATA_PROVENANCE);
        record.setConcrete(!StringUtilities.isEmpty(cells[1]));
        record.setExternalId(category + " _ " + cells[0]);
        return record;
    }).collect(Collectors.toList());
    dsl.batchStore(records).execute();
    sheet.stream().filter(cells -> !StringUtilities.isEmpty(cells[1])).forEach(cells -> {
        String pExtId = cells[1];
        System.out.println(Arrays.toString(cells));
        long pId = dsl.select(MEASURABLE.ID).from(MEASURABLE).where(MEASURABLE.EXTERNAL_ID.eq(category + " _ " + pExtId)).fetchOne(MEASURABLE.ID);
        dsl.update(MEASURABLE).set(MEASURABLE.PARENT_ID, pId).where(MEASURABLE.EXTERNAL_ID.equal(category + " _ " + cells[0])).execute();
    });
    EntityHierarchyService ehSvc = ctx.getBean(EntityHierarchyService.class);
    ehSvc.buildFor(EntityKind.MEASURABLE);
    return null;
}
Also used : Arrays(java.util.Arrays) Checks.checkNotEmpty(org.finos.waltz.common.Checks.checkNotEmpty) Unchecked(org.jooq.lambda.Unchecked) IOUtilities.readLines(org.finos.waltz.common.IOUtilities.readLines) EntityKind(org.finos.waltz.model.EntityKind) MeasurableCategoryRecord(org.finos.waltz.schema.tables.records.MeasurableCategoryRecord) MEASURABLE_CATEGORY(org.finos.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY) ApplicationContext(org.springframework.context.ApplicationContext) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SelectConditionStep(org.jooq.SelectConditionStep) List(java.util.List) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) Map(java.util.Map) DSLContext(org.jooq.DSLContext) StringUtilities(org.finos.waltz.common.StringUtilities) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) MeasurableRecord(org.finos.waltz.schema.tables.records.MeasurableRecord) EntityHierarchyService(org.finos.waltz.service.entity_hierarchy.EntityHierarchyService) DSLContext(org.jooq.DSLContext) List(java.util.List)

Example 4 with MEASURABLE

use of org.finos.waltz.schema.tables.Measurable.MEASURABLE in project waltz by khartec.

the class MariaMeasurableSearch method searchFullText.

@Override
public List<Measurable> searchFullText(DSLContext dsl, EntitySearchOptions options) {
    List<String> terms = mkTerms(options.searchQuery());
    if (terms.isEmpty()) {
        return emptyList();
    }
    Condition externalIdCondition = terms.stream().map(term -> MEASURABLE.EXTERNAL_ID.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    Condition entityLifecycleCondition = MEASURABLE.ENTITY_LIFECYCLE_STATUS.in(options.entityLifecycleStatuses());
    List<Measurable> measurablesViaExternalId = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(externalIdCondition).and(entityLifecycleCondition).orderBy(MEASURABLE.EXTERNAL_ID).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    Condition nameCondition = terms.stream().map(term -> MEASURABLE.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<Measurable> measurablesViaName = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(nameCondition).and(entityLifecycleCondition).orderBy(MEASURABLE.NAME).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    List<Measurable> measurablesViaFullText = dsl.fetch(FULL_TEXT_QUERY, options.searchQuery(), entityLifecycleCondition, options.limit()).map(MeasurableDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(measurablesViaExternalId, measurablesViaName, measurablesViaFullText));
}
Also used : Condition(org.jooq.Condition) DSL(org.jooq.impl.DSL) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) Collections.emptyList(java.util.Collections.emptyList) DatabaseVendorSpecific(org.finos.waltz.data.DatabaseVendorSpecific) Collectors(java.util.stream.Collectors) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) Measurable(org.finos.waltz.model.measurable.Measurable) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) FullTextSearch(org.finos.waltz.data.FullTextSearch) DSLContext(org.jooq.DSLContext) SetUtilities.orderedUnion(org.finos.waltz.common.SetUtilities.orderedUnion) SearchUtilities.mkTerms(org.finos.waltz.data.SearchUtilities.mkTerms) Measurable(org.finos.waltz.model.measurable.Measurable) ArrayList(java.util.ArrayList)

Aggregations

List (java.util.List)4 Collectors (java.util.stream.Collectors)4 MEASURABLE (org.finos.waltz.schema.tables.Measurable.MEASURABLE)4 DSLContext (org.jooq.DSLContext)4 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Random (java.util.Random)2 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)2 RandomUtilities (org.finos.waltz.common.RandomUtilities)2 EntityKind (org.finos.waltz.model.EntityKind)2 MeasurableRecord (org.finos.waltz.schema.tables.records.MeasurableRecord)2 ApplicationContext (org.springframework.context.ApplicationContext)2 Arrays (java.util.Arrays)1 Collections.emptyList (java.util.Collections.emptyList)1 Supplier (java.util.function.Supplier)1 Checks.checkNotEmpty (org.finos.waltz.common.Checks.checkNotEmpty)1 IOUtilities.readLines (org.finos.waltz.common.IOUtilities.readLines)1 ListUtilities (org.finos.waltz.common.ListUtilities)1 RandomUtilities.randomPick (org.finos.waltz.common.RandomUtilities.randomPick)1 SetUtilities.orderedUnion (org.finos.waltz.common.SetUtilities.orderedUnion)1