Search in sources :

Example 31 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class EntityStatisticSummaryDao method generateWithNoRollup.

public TallyPack<String> generateWithNoRollup(Long statisticId, EntityReference entityReference) {
    Condition condition = mkNoRollupCondition(newArrayList(statisticId), entityReference, esv.CURRENT.eq(true));
    Result<Record4<Long, String, String, Timestamp>> values = dsl.select(esv.STATISTIC_ID, esv.OUTCOME, esv.VALUE, max(esv.CREATED_AT).as(maxCreatedAtField)).from(esv).where(dsl.renderInlined(condition)).groupBy(esv.STATISTIC_ID, esv.OUTCOME, esv.VALUE).fetch();
    LocalDateTime maxCreatedAt = values.isNotEmpty() ? values.get(0).getValue(maxCreatedAtField).toLocalDateTime() : nowUtc();
    List<Tally<String>> tallies = values.stream().map(r -> ImmutableTally.<String>builder().count(Double.parseDouble(r.getValue(esv.VALUE))).id(r.getValue(esv.OUTCOME)).build()).collect(toList());
    return ImmutableTallyPack.<String>builder().entityReference(EntityReference.mkRef(EntityKind.ENTITY_STATISTIC, statisticId)).tallies(tallies).lastUpdatedAt(maxCreatedAt).build();
}
Also used : LocalDateTime(java.time.LocalDateTime) DSL(org.jooq.impl.DSL) DateTimeUtilities.nowUtc(com.khartec.waltz.common.DateTimeUtilities.nowUtc) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityReference(com.khartec.waltz.model.EntityReference) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) Duration(com.khartec.waltz.model.Duration) Function(java.util.function.Function) EntityKind(com.khartec.waltz.model.EntityKind) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) org.jooq(org.jooq) ImmutableTally(com.khartec.waltz.model.tally.ImmutableTally) ImmutableTallyPack(com.khartec.waltz.model.tally.ImmutableTallyPack) Repository(org.springframework.stereotype.Repository) Unchecked(org.jooq.lambda.Unchecked) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Tally(com.khartec.waltz.model.tally.Tally) Collectors(java.util.stream.Collectors) Date(java.sql.Date) List(java.util.List) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) TallyPack(com.khartec.waltz.model.tally.TallyPack) DBExecutorPoolInterface(com.khartec.waltz.data.DBExecutorPoolInterface) Collections(java.util.Collections) ENTITY_STATISTIC_VALUE(com.khartec.waltz.schema.tables.EntityStatisticValue.ENTITY_STATISTIC_VALUE) ImmutableTally(com.khartec.waltz.model.tally.ImmutableTally) Tally(com.khartec.waltz.model.tally.Tally)

Example 32 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class EntityStatisticSummaryDao method generateSummary.

private <T> TallyPack<String> generateSummary(Long statisticId, Select<Record1<Long>> appIdSelector, Field<T> aggregateField, Function<T, Double> toTally) {
    Condition condition = mkSummaryCondition(newArrayList(statisticId), appIdSelector, esv.CURRENT.eq(true));
    Result<Record3<String, T, Timestamp>> values = dsl.select(esv.OUTCOME, aggregateField, max(esv.CREATED_AT).as(maxCreatedAtField)).from(esv).where(condition).groupBy(esv.OUTCOME).fetch();
    LocalDateTime maxCreatedAt = values.isNotEmpty() ? values.get(0).getValue(maxCreatedAtField).toLocalDateTime() : nowUtc();
    List<Tally<String>> tallies = values.stream().map(r -> ImmutableTally.<String>builder().count(toTally.apply(r.getValue(aggregateField))).id(r.getValue(esv.OUTCOME)).build()).collect(toList());
    return ImmutableTallyPack.<String>builder().entityReference(EntityReference.mkRef(EntityKind.ENTITY_STATISTIC, statisticId)).tallies(tallies).lastUpdatedAt(maxCreatedAt).build();
}
Also used : LocalDateTime(java.time.LocalDateTime) DSL(org.jooq.impl.DSL) DateTimeUtilities.nowUtc(com.khartec.waltz.common.DateTimeUtilities.nowUtc) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) EntityReference(com.khartec.waltz.model.EntityReference) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) Duration(com.khartec.waltz.model.Duration) Function(java.util.function.Function) EntityKind(com.khartec.waltz.model.EntityKind) BigDecimal(java.math.BigDecimal) Future(java.util.concurrent.Future) org.jooq(org.jooq) ImmutableTally(com.khartec.waltz.model.tally.ImmutableTally) ImmutableTallyPack(com.khartec.waltz.model.tally.ImmutableTallyPack) Repository(org.springframework.stereotype.Repository) Unchecked(org.jooq.lambda.Unchecked) Checks.checkNotNull(com.khartec.waltz.common.Checks.checkNotNull) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) Tally(com.khartec.waltz.model.tally.Tally) Collectors(java.util.stream.Collectors) Date(java.sql.Date) List(java.util.List) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) TallyPack(com.khartec.waltz.model.tally.TallyPack) DBExecutorPoolInterface(com.khartec.waltz.data.DBExecutorPoolInterface) Collections(java.util.Collections) ENTITY_STATISTIC_VALUE(com.khartec.waltz.schema.tables.EntityStatisticValue.ENTITY_STATISTIC_VALUE) ImmutableTally(com.khartec.waltz.model.tally.ImmutableTally) Tally(com.khartec.waltz.model.tally.Tally)

Example 33 with EntityReference

use of com.khartec.waltz.model.EntityReference in project waltz by khartec.

the class FlowDiagramIdSelectorFactory method mkForDirectEntity.

private Select<Record1<Long>> mkForDirectEntity(IdSelectionOptions options) {
    ensureScopeIsExact(options);
    EntityReference ref = options.entityReference();
    return DSL.select(FLOW_DIAGRAM_ENTITY.DIAGRAM_ID).from(FLOW_DIAGRAM_ENTITY).where(FLOW_DIAGRAM_ENTITY.ENTITY_ID.eq(ref.id())).and(FLOW_DIAGRAM_ENTITY.ENTITY_KIND.eq(ref.kind().name()));
}
Also used : EntityReference(com.khartec.waltz.model.EntityReference)

Aggregations

EntityReference (com.khartec.waltz.model.EntityReference)33 EntityKind (com.khartec.waltz.model.EntityKind)11 DSLContext (org.jooq.DSLContext)9 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)9 List (java.util.List)8 ListUtilities.newArrayList (com.khartec.waltz.common.ListUtilities.newArrayList)6 Collection (java.util.Collection)6 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)4 SetUtilities (com.khartec.waltz.common.SetUtilities)4 IdSelectionOptions (com.khartec.waltz.model.IdSelectionOptions)4 LogicalFlow (com.khartec.waltz.model.logical_flow.LogicalFlow)4 LOGICAL_FLOW (com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW)4 DIConfiguration (com.khartec.waltz.service.DIConfiguration)4 EntityReference.mkRef (com.khartec.waltz.model.EntityReference.mkRef)3 ImmutableEntityReference (com.khartec.waltz.model.ImmutableEntityReference)3 Application (com.khartec.waltz.model.application.Application)3 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)3 LogicalFlowService (com.khartec.waltz.service.logical_flow.LogicalFlowService)3