Search in sources :

Example 1 with PhysicalSpecificationRecord

use of com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord in project waltz by khartec.

the class PhysicalSpecificationDao method create.

public Long create(PhysicalSpecification specification) {
    checkNotNull(specification, "specification cannot be null");
    checkFalse(specification.id().isPresent(), "specification must not have an id");
    PhysicalSpecificationRecord record = dsl.newRecord(PHYSICAL_SPECIFICATION);
    record.setOwningEntityKind(specification.owningEntity().kind().name());
    record.setOwningEntityId(specification.owningEntity().id());
    record.setName(specification.name());
    record.setExternalId(specification.externalId().orElse(""));
    record.setDescription(specification.description());
    record.setFormat(specification.format().name());
    record.setLastUpdatedAt(Timestamp.valueOf(specification.lastUpdatedAt()));
    record.setLastUpdatedBy(specification.lastUpdatedBy());
    record.setIsRemoved(specification.isRemoved());
    record.setProvenance("waltz");
    record.store();
    return record.getId();
}
Also used : PhysicalSpecificationRecord(com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord)

Example 2 with PhysicalSpecificationRecord

use of com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord 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)

Aggregations

PhysicalSpecificationRecord (com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord)2 ArrayUtilities.randomPick (com.khartec.waltz.common.ArrayUtilities.randomPick)1 EntityKind (com.khartec.waltz.model.EntityKind)1 DataFormatKind (com.khartec.waltz.model.physical_specification.DataFormatKind)1 APPLICATION (com.khartec.waltz.schema.tables.Application.APPLICATION)1 PHYSICAL_SPECIFICATION (com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION)1 DIConfiguration (com.khartec.waltz.service.DIConfiguration)1 List (java.util.List)1 Random (java.util.Random)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 DSLContext (org.jooq.DSLContext)1 Tuple.tuple (org.jooq.lambda.tuple.Tuple.tuple)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1