use of com.khartec.waltz.model.EntityReference in project waltz by khartec.
the class EntityRefHarness method main.
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
EntityReferenceNameResolver resolver = ctx.getBean(EntityReferenceNameResolver.class);
List<EntityReference> refs = ListUtilities.newArrayList(EntityReference.mkRef(EntityKind.MEASURABLE, 136), EntityReference.mkRef(EntityKind.MEASURABLE, 138), EntityReference.mkRef(EntityKind.MEASURABLE, -138), EntityReference.mkRef(EntityKind.CHANGE_INITIATIVE, 12));
List<EntityReference> refs1 = ListUtilities.newArrayList(EntityReference.mkRef(EntityKind.MEASURABLE, 136));
dump(resolver.resolve(refs));
dump(resolver.resolve(refs1));
System.out.println("-- done");
}
use of com.khartec.waltz.model.EntityReference in project waltz by khartec.
the class AdditiveFlowGenerator method main.
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
AuthoritativeSourceDao authSourceDao = ctx.getBean(AuthoritativeSourceDao.class);
ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
LogicalFlowService dataFlowDao = ctx.getBean(LogicalFlowService.class);
OrganisationalUnitService orgUnitDao = ctx.getBean(OrganisationalUnitService.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
List<AuthoritativeSource> authSources = authSourceDao.findByEntityKind(EntityKind.ORG_UNIT);
List<Application> apps = applicationDao.findAll();
Application referenceApplication = applicationDao.getById(APPLICATION_ID);
List<OrganisationalUnit> orgUnits = orgUnitDao.findAll();
Set<LogicalFlow> expectedFlows = authSources.stream().map(a -> {
long orgUnitId = a.parentReference().id();
if (referenceApplication.organisationalUnitId().equals(orgUnitId)) {
return Optional.of(ImmutableLogicalFlow.builder().source(a.applicationReference()).target(referenceApplication.entityReference()).build());
} else {
return Optional.<LogicalFlow>empty();
}
}).filter(o -> o.isPresent()).map(o -> o.get()).collect(toSet());
Set<LogicalFlow> randomTargetFlows = IntStream.range(0, rnd.nextInt(APPROX_FLOW_GENERATION_COUNT / 2)).mapToObj(i -> {
EntityReference target = randomAppPick(apps, randomPick(orgUnits).id().get());
return ImmutableLogicalFlow.builder().source(referenceApplication.entityReference()).target(target).build();
}).collect(toSet());
Set<LogicalFlow> randomSourceFlows = IntStream.range(0, rnd.nextInt(APPROX_FLOW_GENERATION_COUNT / 2)).mapToObj(i -> {
EntityReference source = randomAppPick(apps, randomPick(orgUnits).id().get());
return ImmutableLogicalFlow.builder().source(source).target(referenceApplication.entityReference()).build();
}).collect(toSet());
dsl.delete(LOGICAL_FLOW).where(LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(APPLICATION_ID)).or(LOGICAL_FLOW.TARGET_ENTITY_ID.eq(APPLICATION_ID)).execute();
Set<LogicalFlow> all = new HashSet<>();
all.addAll(randomTargetFlows);
all.addAll(randomSourceFlows);
all.addAll(expectedFlows);
System.out.println("--- saving: " + all.size());
Set<LogicalFlowRecord> records = SetUtilities.map(all, df -> LogicalFlowDao.TO_RECORD_MAPPER.apply(df, dsl));
dsl.batchStore(records).execute();
System.out.println("--- done");
}
use of com.khartec.waltz.model.EntityReference in project waltz by khartec.
the class EntityIdSelectorFactory method apply.
@Override
public final Select<Record1<Long>> apply(EntityIdSelectionOptions options) {
checkNotNull(options, "options cannot be null");
EntityKind desiredKind = options.desiredKind();
EntityReference ref = options.entityReference();
switch(ref.kind()) {
case APP_GROUP:
return mkForAppGroup(ref, options.scope());
case PERSON:
return mkForPerson(desiredKind, 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 com.khartec.waltz.model.EntityReference in project waltz by khartec.
the class ApplicationIdSelectorFactory method apply.
@Override
public Select<Record1<Long>> apply(IdSelectionOptions options) {
checkNotNull(options, "options cannot be null");
EntityReference ref = options.entityReference();
switch(ref.kind()) {
case ACTOR:
return mkForActor(options);
case APP_GROUP:
return mkForAppGroup(options);
case APPLICATION:
return mkForApplication(options);
case CHANGE_INITIATIVE:
return mkForChangeInitiative(options);
case DATA_TYPE:
return mkForDataType(options);
case FLOW_DIAGRAM:
return mkForFlowDiagram(options);
case MEASURABLE:
return mkForMeasurable(options);
case ORG_UNIT:
return mkForOrgUnit(options);
case PERSON:
return mkForPerson(options);
default:
throw new IllegalArgumentException("Cannot create selector for entity kind: " + ref.kind());
}
}
use of com.khartec.waltz.model.EntityReference in project waltz by khartec.
the class LogicalFlowDecoratorDao method summarizeForCondition.
private List<DecoratorRatingSummary> summarizeForCondition(Condition condition) {
// this is intentionally TARGET only as we use to calculate auth source stats
Condition dataFlowJoinCondition = LOGICAL_FLOW.ID.eq(LOGICAL_FLOW_DECORATOR.LOGICAL_FLOW_ID);
Collection<Field<?>> groupingFields = newArrayList(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_KIND, LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_ID, LOGICAL_FLOW_DECORATOR.RATING);
Field<Integer> countField = DSL.count(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_ID).as("count");
return dsl.select(groupingFields).select(countField).from(LOGICAL_FLOW_DECORATOR).innerJoin(LOGICAL_FLOW).on(dsl.renderInlined(dataFlowJoinCondition)).where(dsl.renderInlined(condition)).groupBy(groupingFields).fetch(r -> {
EntityKind decoratorEntityKind = EntityKind.valueOf(r.getValue(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_KIND));
long decoratorEntityId = r.getValue(LOGICAL_FLOW_DECORATOR.DECORATOR_ENTITY_ID);
EntityReference decoratorRef = EntityReference.mkRef(decoratorEntityKind, decoratorEntityId);
AuthoritativenessRating rating = AuthoritativenessRating.valueOf(r.getValue(LOGICAL_FLOW_DECORATOR.RATING));
Integer count = r.getValue(countField);
return ImmutableDecoratorRatingSummary.builder().decoratorEntityReference(decoratorRef).rating(rating).count(count).build();
});
}
Aggregations