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;
}
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;
}
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());
}
}
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);
}
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'");
}
Aggregations