use of org.finos.waltz.schema.tables.Application.APPLICATION in project waltz by khartec.
the class LogicalFlowDecoratorDao method updateDecoratorsForFlowClassificationRule.
public int updateDecoratorsForFlowClassificationRule(FlowClassificationRuleVantagePoint flowClassificationRuleVantagePoint) {
LogicalFlowDecorator lfd = LOGICAL_FLOW_DECORATOR.as("lfd");
EntityReference vantagePoint = flowClassificationRuleVantagePoint.vantagePoint();
Long appId = flowClassificationRuleVantagePoint.applicationId();
EntityReference dataType = flowClassificationRuleVantagePoint.dataType();
String classificationCode = flowClassificationRuleVantagePoint.classificationCode();
SelectConditionStep<Record1<Long>> orgUnitSubselect = DSL.select(ENTITY_HIERARCHY.ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.KIND.eq(vantagePoint.kind().name())).and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(vantagePoint.id()));
SelectConditionStep<Record1<Long>> dataTypeSubselect = DSL.select(ENTITY_HIERARCHY.ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.KIND.eq(DATA_TYPE.name())).and(ENTITY_HIERARCHY.ANCESTOR_ID.eq(dataType.id()));
Condition usingFlowClassificationRule = LOGICAL_FLOW.SOURCE_ENTITY_ID.eq(appId);
Condition notUsingFlowClassificationRule = LOGICAL_FLOW.SOURCE_ENTITY_ID.ne(appId);
Function2<Condition, String, Update<LogicalFlowDecoratorRecord>> mkQuery = (appScopingCondition, ratingName) -> dsl.update(LOGICAL_FLOW_DECORATOR).set(LOGICAL_FLOW_DECORATOR.RATING, ratingName).set(LOGICAL_FLOW_DECORATOR.FLOW_CLASSIFICATION_RULE_ID, flowClassificationRuleVantagePoint.ruleId()).where(LOGICAL_FLOW_DECORATOR.ID.in(DSL.select(lfd.ID).from(lfd).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(lfd.LOGICAL_FLOW_ID)).innerJoin(APPLICATION).on(APPLICATION.ID.eq(LOGICAL_FLOW.TARGET_ENTITY_ID).and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()))).where(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()).and(appScopingCondition).and(APPLICATION.ORGANISATIONAL_UNIT_ID.in(orgUnitSubselect)).and(lfd.DECORATOR_ENTITY_KIND.eq(DATA_TYPE.name())).and(lfd.DECORATOR_ENTITY_ID.in(dataTypeSubselect))).and(lfd.RATING.in(AuthoritativenessRatingValue.NO_OPINION.value(), AuthoritativenessRatingValue.DISCOURAGED.value()))));
Update<LogicalFlowDecoratorRecord> updateAuthSources = mkQuery.apply(usingFlowClassificationRule, classificationCode);
Update<LogicalFlowDecoratorRecord> updateNonAuthSources = mkQuery.apply(notUsingFlowClassificationRule, AuthoritativenessRatingValue.DISCOURAGED.value());
int authSourceUpdateCount = updateAuthSources.execute();
int nonAuthSourceUpdateCount = updateNonAuthSources.execute();
return authSourceUpdateCount + nonAuthSourceUpdateCount;
}
use of org.finos.waltz.schema.tables.Application.APPLICATION in project waltz by khartec.
the class ChangeLogGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
DSLContext dsl = ctx.getBean(DSLContext.class);
// get applications and emails
List<Long> appIds = dsl.select(APPLICATION.ID).from(APPLICATION).fetch(APPLICATION.ID);
List<String> emails = dsl.select(PERSON.EMAIL).from(PERSON).fetch(PERSON.EMAIL);
Set<ChangeLogRecord> records = emails.stream().flatMap(email -> {
Long appId = randomPick(appIds);
LocalDateTime when = now().minus(randomIntBetween(0, 365), ChronoUnit.DAYS);
return Stream.of(mkChangeLog(appId, email, when), mkChangeLog(appId, email, when), mkChangeLog(randomPick(appIds), email, when), mkChangeLog(appId, randomPick(emails), when));
}).collect(toSet());
dsl.batchInsert(records).execute();
log("Inserted " + records.size() + " change log entries");
return null;
}
use of org.finos.waltz.schema.tables.Application.APPLICATION in project waltz by khartec.
the class BookmarkGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
DSLContext dsl = getDsl(ctx);
List<EntityReference> appRefs = dsl.select(APPLICATION.NAME, APPLICATION.ID).from(APPLICATION).fetch(r -> EntityReference.mkRef(EntityKind.APPLICATION, r.value2(), r.value1()));
List<EntityReference> measurableRefs = dsl.select(MEASURABLE.NAME, MEASURABLE.ID).from(MEASURABLE).fetch(r -> EntityReference.mkRef(EntityKind.MEASURABLE, r.value2(), r.value1()));
List<EntityReference> ouRefs = dsl.select(ORGANISATIONAL_UNIT.NAME, ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(r -> EntityReference.mkRef(EntityKind.ORG_UNIT, r.value2(), r.value1()));
List<EntityReference> appGroupRefs = dsl.select(APPLICATION_GROUP.NAME, APPLICATION_GROUP.ID).from(APPLICATION_GROUP).fetch(r -> EntityReference.mkRef(EntityKind.APP_GROUP, r.value2(), r.value1()));
List<EntityReference> refs = ListUtilities.concat(appRefs, measurableRefs, ouRefs, appGroupRefs);
List<BookmarkRecord> bookmarks = refs.stream().flatMap(r -> RandomUtilities.randomlySizedIntStream(2, 15).mapToObj(idx -> {
BookmarkRecord record = dsl.newRecord(BOOKMARK);
record.setParentKind(r.kind().name());
record.setParentId(r.id());
record.setTitle(mkText(r.name().get()));
record.setDescription(mkText(r.name().get()));
record.setKind(randomPick(bookmarkKinds));
record.setUrl(mkUrl(r.name().get()));
record.setProvenance(SAMPLE_DATA_PROVENANCE);
record.setLastUpdatedBy("admin");
record.setUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
record.setCreatedAt(DateTimeUtilities.nowUtcTimestamp());
return record;
})).collect(Collectors.toList());
dsl.batchStore(bookmarks).execute();
return null;
}
use of org.finos.waltz.schema.tables.Application.APPLICATION in project waltz by khartec.
the class ScenarioRatingImporter method mkScenarioRatingRecords.
private List<ScenarioRatingItemRecord> mkScenarioRatingRecords(List<Measurable> measurables, Map<String, RatingSchemeItem> ratingsByName, List<ScenarioRatingRow> rows, Scenario scenario) {
Collection<ScenarioAxisItem> scenarioAxes = scenarioAxisItemDao.findForScenarioId(scenario.id().get());
Map<Long, Measurable> measurablesById = indexBy(m -> m.id().get(), measurables);
Map<String, ScenarioAxisItem> scenarioAxesByName = scenarioAxes.stream().map(sa -> Tuple.tuple(lower(measurablesById.get(sa.domainItem().id()).name()), sa)).collect(toMap(t -> t.v1(), t -> t.v2()));
return rows.stream().map(r -> {
ScenarioAxisItem columnAxis = scenarioAxesByName.get(lower(r.column()));
checkNotNull(columnAxis, "columnAxis cannot be null");
checkTrue(columnAxis.axisOrientation().equals(AxisOrientation.COLUMN), "column does not match a oolumn axis");
ScenarioAxisItem rowAxis = scenarioAxesByName.get(lower(r.row()));
checkNotNull(rowAxis, "rowAxis cannot be null");
checkTrue(rowAxis.axisOrientation().equals(AxisOrientation.ROW), "row does not match a row axis");
Application app = assetCodeToApplicationMap.get(r.assetCode());
checkNotNull(app, String.format("Application with asset code[%s] cannot be null", r.assetCode()));
RatingSchemeItem rating = ratingsByName.get(lower(r.rating()));
checkNotNull(rating, String.format("rating [%s] cannot be null", r.rating()));
ScenarioRatingItemRecord record = new ScenarioRatingItemRecord();
record.setScenarioId(scenario.id().get());
record.setRating(rating.rating().toString());
record.setDomainItemKind(EntityKind.APPLICATION.name());
record.setDomainItemId(app.id().get());
record.setRowKind(rowAxis.domainItem().kind().name());
record.setRowId(rowAxis.domainItem().id());
record.setColumnKind(columnAxis.domainItem().kind().name());
record.setColumnId(columnAxis.domainItem().id());
record.setLastUpdatedAt(DateTimeUtilities.nowUtcTimestamp());
record.setLastUpdatedBy(r.providedBy());
record.setDescription(r.description());
return record;
}).collect(toList());
}
use of org.finos.waltz.schema.tables.Application.APPLICATION in project waltz by khartec.
the class ScenarioRatingImporter method importScenarioRatings.
public void importScenarioRatings(String filename) throws IOException {
List<Application> allApps = dsl.select().from(APPLICATION).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
assetCodeToApplicationMap = indexBy(a -> ExternalIdValue.orElse(a.assetCode(), null), allApps);
List<ScenarioRatingRow> ratingRows = parseData(filename);
Map<String, Map<String, List<ScenarioRatingRow>>> rowsGroupedByRoadmapByScenario = ratingRows.stream().collect(groupingBy(ScenarioRatingRow::roadmap, groupingBy(ScenarioRatingRow::scenario)));
// get roadmap id
Map<String, Roadmap> roadmapNameToIdMap = getNameToRoadmapMap(roadmapDao);
List<Measurable> measurables = measurableDao.findAll();
rowsGroupedByRoadmapByScenario.forEach((String roadmapName, Map<String, List<ScenarioRatingRow>> scenarioAndRows) -> {
// get roadmap
Roadmap roadmap = roadmapNameToIdMap.get(lower(roadmapName));
checkNotNull(roadmap, "roadmap [" + roadmapName + "] cannot be null");
// get rating scheme
RatingScheme ratingScheme = ratingSchemeDao.getById(roadmap.ratingSchemeId());
checkNotNull(ratingScheme, "ratingScheme cannot be null");
Map<String, RatingSchemeItem> ratingsByName = indexBy(r -> lower(r.name()), ratingScheme.ratings());
// index available scenarios
Map<String, Scenario> scenariosByName = indexBy(s -> lower(s.name()), scenarioDao.findForRoadmapId(roadmap.id().get()));
scenarioAndRows.forEach((scenarioName, rows) -> updateRatingsForScenario(measurables, roadmap, ratingsByName, rows, scenariosByName, scenarioName));
});
}
Aggregations