Search in sources :

Example 1 with PhysicalFlowRecord

use of org.finos.waltz.schema.tables.records.PhysicalFlowRecord in project waltz by khartec.

the class PhysicalFlowDao method create.

public long create(PhysicalFlow flow) {
    checkNotNull(flow, "flow cannot be null");
    checkFalse(flow.id().isPresent(), "flow must not have an id");
    PhysicalFlowRecord record = dsl.newRecord(PHYSICAL_FLOW);
    record.setLogicalFlowId(flow.logicalFlowId());
    record.setFrequency(flow.frequency().name());
    record.setTransport(flow.transport().value());
    record.setBasisOffset(flow.basisOffset());
    record.setCriticality(flow.criticality().name());
    record.setSpecificationId(flow.specificationId());
    record.setDescription(flow.description());
    record.setLastUpdatedBy(flow.lastUpdatedBy());
    record.setLastUpdatedAt(Timestamp.valueOf(flow.lastUpdatedAt()));
    record.setLastAttestedBy(flow.lastAttestedBy().orElse(null));
    record.setLastAttestedAt(flow.lastAttestedAt().map(Timestamp::valueOf).orElse(null));
    record.setIsRemoved(flow.isRemoved());
    record.setProvenance("waltz");
    record.setExternalId(flow.externalId().orElse(null));
    record.setCreatedAt(flow.created().map(UserTimestamp::atTimestamp).orElse(Timestamp.valueOf(flow.lastUpdatedAt())));
    record.setCreatedBy(flow.created().map(UserTimestamp::by).orElse(flow.lastUpdatedBy()));
    record.store();
    return record.getId();
}
Also used : PhysicalFlowRecord(org.finos.waltz.schema.tables.records.PhysicalFlowRecord) Timestamp(java.sql.Timestamp) DateTimeUtilities.nowUtcTimestamp(org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp)

Example 2 with PhysicalFlowRecord

use of org.finos.waltz.schema.tables.records.PhysicalFlowRecord in project waltz by khartec.

the class PhysicalFlowGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<PhysicalSpecification> specifications = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).fetch(PhysicalSpecificationDao.TO_DOMAIN_MAPPER);
    List<String> transportKinds = dsl.select(ENUM_VALUE.KEY).from(ENUM_VALUE).where(ENUM_VALUE.TYPE.eq(EnumValueKind.TRANSPORT_KIND.dbValue())).fetch(ENUM_VALUE.KEY);
    List<Tuple3<Long, Long, Long>> allLogicalFLows = dsl.select(LOGICAL_FLOW.ID, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.TARGET_ENTITY_ID).from(LOGICAL_FLOW).fetch(r -> Tuple.tuple(r.getValue(LOGICAL_FLOW.ID), r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_ID), r.getValue(LOGICAL_FLOW.TARGET_ENTITY_ID)));
    Map<Long, Collection<Long>> logicalFlowIdsBySourceApp = groupBy(t -> t.v2(), t -> t.v1(), allLogicalFLows);
    final int flowBatchSize = 100000;
    List<PhysicalFlowRecord> flowBatch = new ArrayList<PhysicalFlowRecord>((int) (flowBatchSize * 1.2));
    for (PhysicalSpecification spec : specifications) {
        Collection<Long> relatedLogicalFlowsIds = logicalFlowIdsBySourceApp.get(spec.owningEntity().id());
        if (!isEmpty(relatedLogicalFlowsIds)) {
            List<PhysicalFlowRecord> physicalFlowRecords = mkPhysicalFlowRecords(spec, new LinkedList<>(relatedLogicalFlowsIds), transportKinds);
            flowBatch.addAll(physicalFlowRecords);
        }
        if (flowBatch.size() >= flowBatchSize) {
            log(String.format("--- saving records: count: %s", flowBatch.size()));
            dsl.batchInsert(flowBatch).execute();
            flowBatch.clear();
        }
    }
    log(String.format("--- saving records: count: %s", flowBatch.size()));
    dsl.batchInsert(flowBatch).execute();
    flowBatch.clear();
    log("---done");
    return null;
}
Also used : PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) PhysicalFlowRecord(org.finos.waltz.schema.tables.records.PhysicalFlowRecord) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) DSLContext(org.jooq.DSLContext) Tuple3(org.jooq.lambda.tuple.Tuple3)

Aggregations

PhysicalFlowRecord (org.finos.waltz.schema.tables.records.PhysicalFlowRecord)2 Timestamp (java.sql.Timestamp)1 DateTimeUtilities.nowUtcTimestamp (org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp)1 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)1 PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)1 DSLContext (org.jooq.DSLContext)1 Tuple3 (org.jooq.lambda.tuple.Tuple3)1