Search in sources :

Example 76 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class PhysicalFlowUploadService method getOrCreateLogicalFlow.

private LogicalFlow getOrCreateLogicalFlow(EntityReference source, EntityReference target, EntityReference dataType, String username) {
    LogicalFlow flow = logicalFlowDao.getBySourceAndTarget(source, target);
    if (flow == null) {
        LocalDateTime now = nowUtc();
        LogicalFlow flowToAdd = ImmutableLogicalFlow.builder().source(source).target(target).lastUpdatedBy(username).lastUpdatedAt(now).provenance("waltz").created(UserTimestamp.mkForUser(username, now)).build();
        flow = logicalFlowDao.addFlow(flowToAdd);
    }
    EntityReference logicalFlowEntityRef = EntityReference.mkRef(EntityKind.LOGICAL_DATA_FLOW, flow.id().get());
    DataTypeDecorator existingDecorator = dataTypeDecoratorService.getByEntityRefAndDataTypeId(logicalFlowEntityRef, dataType.id());
    if (existingDecorator == null) {
        dataTypeDecoratorService.addDecorators(username, logicalFlowEntityRef, fromArray(dataType.id()));
    }
    return flow;
}
Also used : LocalDateTime(java.time.LocalDateTime) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(org.finos.waltz.model.logical_flow.ImmutableLogicalFlow) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference)

Example 77 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class PhysicalFlowUploadService method getOrCreatePhysicalSpec.

private PhysicalSpecification getOrCreatePhysicalSpec(PhysicalFlowParsed flow, String username) {
    EntityReference owner = flow.owner();
    DataFormatKind format = flow.format();
    String name = flow.name();
    // check database
    PhysicalSpecification spec = physicalSpecificationDao.getByParsedFlow(flow);
    if (spec == null) {
        // create
        LocalDateTime now = nowUtc();
        PhysicalSpecification specToAdd = ImmutablePhysicalSpecification.builder().owningEntity(owner).format(format).name(name).externalId(Optional.ofNullable(flow.specExternalId()).orElse("")).description(Optional.ofNullable(flow.specDescription()).orElse("")).lastUpdatedBy(username).lastUpdatedAt(now).provenance("waltz").created(UserTimestamp.mkForUser(username, now)).build();
        Long id = physicalSpecificationDao.create(specToAdd);
        spec = ImmutablePhysicalSpecification.copyOf(specToAdd).withId(id);
    }
    long dataTypeId = flow.dataType().id();
    EntityReference specificationEntityRef = EntityReference.mkRef(EntityKind.PHYSICAL_SPECIFICATION, spec.id().get());
    DataTypeDecorator existingDataType = dataTypeDecoratorService.getByEntityRefAndDataTypeId(specificationEntityRef, dataTypeId);
    if (existingDataType == null) {
        dataTypeDecoratorService.addDecorators(username, specificationEntityRef, fromArray(dataTypeId));
    }
    return spec;
}
Also used : LocalDateTime(java.time.LocalDateTime) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) DataFormatKind(org.finos.waltz.model.physical_specification.DataFormatKind) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference)

Example 78 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class SurveyInstanceIdSelectorFactory method apply.

@Override
public Select<Record1<Long>> apply(IdSelectionOptions options) {
    checkNotNull(options, "options cannot be null");
    EntityReference ref = options.entityReference();
    switch(ref.kind()) {
        case APP_GROUP:
        case APPLICATION:
        case CHANGE_INITIATIVE:
            return mkForNonHierarchicalEntity(ref, options.scope());
        case ORG_UNIT:
            return mkForOrgUnit(ref, options.scope());
        default:
            throw new IllegalArgumentException("Cannot create selector for entity kind: " + ref.kind());
    }
}
Also used : EntityReference(org.finos.waltz.model.EntityReference)

Example 79 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class ChangeReporter method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ApplicationIdSelectorFactory selectorFactory = new ApplicationIdSelectorFactory();
    LocalDateTime exerciseStart = LocalDateTime.of(2018, 06, 04, 0, 1).truncatedTo(ChronoUnit.DAYS);
    LocalDateTime dayBeforeYesterday = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(1);
    LocalDateTime yesterday = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
    // BCBS239
    EntityReference appGroupRef = EntityReference.mkRef(EntityKind.APP_GROUP, 10862);
    Select<Record1<Long>> appSelector = mkSelector(selectorFactory, appGroupRef);
    Tuple3<String, LocalDateTime, LocalDateTime> dayPeriod = Tuple.tuple("day", dayBeforeYesterday, yesterday);
    Tuple3<String, LocalDateTime, LocalDateTime> cumulativePeriod = Tuple.tuple("cumulative", exerciseStart, yesterday);
    dumpReport(dsl, dayPeriod, appGroupRef, appSelector);
    dumpReport(dsl, cumulativePeriod, appGroupRef, appSelector);
}
Also used : LocalDateTime(java.time.LocalDateTime) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) EntityReference(org.finos.waltz.model.EntityReference)

Example 80 with EntityReference

use of org.finos.waltz.model.EntityReference in project waltz by khartec.

the class LogicalFlowServiceTest method cleanupOrphans.

@Test
public void cleanupOrphans() {
    helper.clearAllFlows();
    EntityReference a = appHelper.createNewApp("a", ouIds.a);
    EntityReference b = appHelper.createNewApp("b", ouIds.a1);
    EntityReference c = appHelper.createNewApp("c", ouIds.b);
    LogicalFlow ab = helper.createLogicalFlow(a, b);
    LogicalFlow ac = helper.createLogicalFlow(a, c);
    LogicalFlow ca = helper.createLogicalFlow(c, a);
    int flowsRemoved = lfSvc.cleanupOrphans();
    assertEquals(0, flowsRemoved, "No flows removed if all apps are active");
    appHelper.removeApp(c.id());
    int flowsRemovedAfterAppRemoved = lfSvc.cleanupOrphans();
    assertEquals(2, flowsRemovedAfterAppRemoved, "Flows removed where either source or target is retired");
    LogicalFlow flowWhereTargetRemoved = lfSvc.getById(ac.id().get());
    assertEquals(EntityLifecycleStatus.REMOVED, flowWhereTargetRemoved.entityLifecycleStatus(), "If target removed, flow still exists but has entity lifecycle status of 'REMOVED'");
}
Also used : LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

EntityReference (org.finos.waltz.model.EntityReference)114 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)55 Test (org.junit.jupiter.api.Test)55 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)40 EntityKind (org.finos.waltz.model.EntityKind)23 List (java.util.List)21 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)19 Autowired (org.springframework.beans.factory.annotation.Autowired)17 DataTypeDecorator (org.finos.waltz.model.datatype.DataTypeDecorator)16 Set (java.util.Set)14 Collection (java.util.Collection)13 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)13 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)9 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)8 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)8 Bookmark (org.finos.waltz.model.bookmark.Bookmark)8 Collections.emptyList (java.util.Collections.emptyList)7 Collectors (java.util.stream.Collectors)7 CollectionUtilities.first (org.finos.waltz.common.CollectionUtilities.first)7