use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.
the class EntityStatisticHarness method main.
public static void main(String[] args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
EntityStatisticValueDao dao = ctx.getBean(EntityStatisticValueDao.class);
EntityStatisticService service = ctx.getBean(EntityStatisticService.class);
IdSelectionOptions selectionOptions = IdSelectionOptions.mkOpts(EntityReference.mkRef(EntityKind.MEASURABLE, 49263), HierarchyQueryScope.CHILDREN);
}
use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.
the class PhysicalSpecificationServiceTest method findBySelector.
@Test
public void findBySelector() {
assertThrows(IllegalArgumentException.class, () -> psSvc.findBySelector(null), "Options cannot be null");
EntityReference a = appHelper.createNewApp("a", ouIds.a);
Long specId = psHelper.createPhysicalSpec(a, "findByEntityReference");
IdSelectionOptions specOpts = mkOpts(mkRef(EntityKind.PHYSICAL_SPECIFICATION, specId));
Collection<PhysicalSpecification> specs = psSvc.findBySelector(specOpts);
assertEquals(1, specs.size(), "When selector is a spec only returns one result");
assertEquals(specId, first(specs).id().get(), "Returns spec when using spec selector");
EntityReference b = appHelper.createNewApp("b", ouIds.a1);
LogicalFlow flow = lfHelper.createLogicalFlow(a, b);
Long specId2 = psHelper.createPhysicalSpec(b, "findByEntityReference");
PhysicalFlowCreateCommandResponse physFlow = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId, mkName("findBySelector"));
PhysicalFlowCreateCommandResponse physFlow2 = pfHelper.createPhysicalFlow(flow.entityReference().id(), specId2, mkName("findBySelector"));
IdSelectionOptions appOpts = mkOpts(mkRef(EntityKind.APPLICATION, b.id()));
assertThrows(UnsupportedOperationException.class, () -> psSvc.findBySelector(appOpts), "Throws exception for unsupported entity kinds");
IdSelectionOptions flowOpts = mkOpts(mkRef(EntityKind.LOGICAL_DATA_FLOW, flow.entityReference().id()));
Collection<PhysicalSpecification> specsForFlow = psSvc.findBySelector(flowOpts);
assertEquals(2, specsForFlow.size(), "Returns all specs linked to a flow");
assertEquals(asSet(specId, specId2), map(specsForFlow, d -> d.entityReference().id()), "Returns all specs linked to a flow");
pfHelper.deletePhysicalFlow(physFlow2.entityReference().id());
psHelper.removeSpec(specId2);
Collection<PhysicalSpecification> activeSpecsForFlow = psSvc.findBySelector(flowOpts);
assertEquals(1, activeSpecsForFlow.size(), "Returns all specs linked to a flow");
assertEquals(asSet(specId), map(activeSpecsForFlow, d -> d.entityReference().id()), "Returns only active specs linked to a flow");
}
use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.
the class ChangeUnitViewService method findPhysicalFlowChangeUnitsByChangeSetId.
public Set<PhysicalFlowChangeUnitViewItem> findPhysicalFlowChangeUnitsByChangeSetId(long changeSetId) {
IdSelectionOptions idSelectionOptions = mkOptsForAllLifecycleStates(mkRef(EntityKind.CHANGE_SET, changeSetId), HierarchyQueryScope.EXACT);
Collection<PhysicalFlow> physicalFlows = physicalFlowService.findBySelector(idSelectionOptions);
Collection<PhysicalSpecification> physicalSpecs = physicalSpecificationService.findByIds(map(physicalFlows, PhysicalFlow::specificationId));
// TODO: Move to a logical flow selector based upon change set #5626
Collection<LogicalFlow> logicalFlows = logicalFlowService.findAllByFlowIds(map(physicalFlows, PhysicalFlow::logicalFlowId));
List<AssessmentRating> assessmentRatings = assessmentRatingService.findByTargetKindForRelatedSelector(EntityKind.CHANGE_UNIT, idSelectionOptions);
Map<Long, RatingSchemeItem> ratingSchemeItemsById = indexBy(ratingSchemeService.getAllRatingSchemeItems(), item -> item.id().get());
Map<Long, PhysicalFlow> physicalFlowsById = indexBy(physicalFlows, flow -> flow.id().get());
Map<Long, LogicalFlow> logicalFlowsById = indexBy(logicalFlows, flow -> flow.id().get());
Map<Long, PhysicalSpecification> specsById = indexBy(physicalSpecs, spec -> spec.id().get());
Map<Long, Collection<AssessmentRating>> assessmentRatingsByEntityId = groupBy(rating -> rating.entityReference().id(), assessmentRatings);
List<ChangeUnit> changeUnits = changeUnitService.findByChangeSetId(changeSetId);
return changeUnits.stream().filter(cu -> cu.subjectEntity().kind().equals(EntityKind.PHYSICAL_FLOW)).map(cu -> {
PhysicalFlow physicalFlow = physicalFlowsById.get(cu.subjectEntity().id());
PhysicalSpecification spec = specsById.get(physicalFlow.specificationId());
LogicalFlow logicalFlow = logicalFlowsById.get(physicalFlow.logicalFlowId());
Long changeUnitId = cu.id().get();
Collection<AssessmentRating> assessmentRatingsForChangeUnit = assessmentRatingsByEntityId.getOrDefault(changeUnitId, emptySet());
Set<AssessmentRatingDetail> assessmentRatingDetailForChangeUnit = map(assessmentRatingsForChangeUnit, rating -> mkAssessmentDefinitionDetail(rating, ratingSchemeItemsById.get(rating.ratingId())));
return ImmutablePhysicalFlowChangeUnitViewItem.builder().changeUnit(cu).physicalSpecification(spec).logicalFlow(logicalFlow).assessments(assessmentRatingDetailForChangeUnit).build();
}).collect(toSet());
}
use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.
the class ScenarioPopulator method main.
public static void main(String[] args) {
LoggingUtilities.configureLogging();
// these two parameters specify which roadmap to use and what set of applications to use in the population.
long roadmapId = 62L;
IdSelectionOptions appSelectionOptions = IdSelectionOptions.mkOpts(mkRef(EntityKind.APP_GROUP, 11261L));
Select<Record1<Long>> appSelector = new ApplicationIdSelectorFactory().apply(appSelectionOptions);
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
DSLContext dsl = ctx.getBean(DSLContext.class);
dsl.transaction(context -> {
DSLContext tx = context.dsl();
Timestamp now = DateTimeUtilities.nowUtcTimestamp();
scrub(tx, roadmapId);
SelectConditionStep<Record> qry = tx.select(road.NAME).select(mc.NAME).select(s.NAME, s.ID, s.EFFECTIVE_DATE).select(cai.DOMAIN_ITEM_ID, cai.DOMAIN_ITEM_KIND).select(rai.DOMAIN_ITEM_ID, rai.DOMAIN_ITEM_KIND).select(mr.ENTITY_ID, mr.ENTITY_KIND, mr.RATING).select(pd.PLANNED_DECOMMISSION_DATE).select(repl.ENTITY_ID, repl.ENTITY_KIND, repl.PLANNED_COMMISSION_DATE).select(inclCurrent).select(inclReplacement).from(road).innerJoin(mc).on(mc.ID.eq(road.ROW_TYPE_ID)).innerJoin(s).on(s.ROADMAP_ID.eq(road.ID)).innerJoin(cai).on(cai.SCENARIO_ID.eq(s.ID)).and(cai.ORIENTATION.eq(AxisOrientation.COLUMN.name())).innerJoin(rai).on(rai.SCENARIO_ID.eq(s.ID)).and(rai.ORIENTATION.eq(AxisOrientation.ROW.name())).innerJoin(mr).on(mr.MEASURABLE_ID.eq(rai.DOMAIN_ITEM_ID)).leftJoin(pd).on(pd.ENTITY_ID.eq(mr.ENTITY_ID)).and(pd.ENTITY_KIND.eq(mr.ENTITY_KIND)).and(mr.MEASURABLE_ID.eq(pd.MEASURABLE_ID)).leftJoin(repl).on(pd.ID.eq(repl.DECOMMISSION_ID)).where(road.ID.eq(roadmapId)).and(mr.ENTITY_ID.in(appSelector)).and(mr.ENTITY_KIND.eq(EntityKind.APPLICATION.name()));
int[] insertResult = qry.fetch().stream().flatMap(r -> mkRecordsFromRow(tx, r, now)).collect(collectingAndThen(Collectors.toSet(), tx::batchInsert)).execute();
});
}
use of org.finos.waltz.model.IdSelectionOptions in project waltz by khartec.
the class LicencesExtractor method register.
@Override
public void register() {
String path = WebUtilities.mkPath("data-extract", "licences", ":kind", ":id");
get(path, (request, response) -> {
EntityReference entityRef = WebUtilities.getEntityReference(request);
IdSelectionOptions selectionOptions = mkOpts(entityRef);
Select<Record1<Long>> appIdSelector = applicationIdSelectorFactory.apply(selectionOptions);
SelectConditionStep<Record8<Long, String, String, String, String, Timestamp, String, String>> qry = dsl.selectDistinct(LICENCE.ID.as("Licence Id"), LICENCE.NAME.as("Licence Name"), LICENCE.DESCRIPTION.as("Description"), LICENCE.EXTERNAL_ID.as("External Id"), LICENCE.APPROVAL_STATUS.as("Approval Status"), LICENCE.LAST_UPDATED_AT.as("Last Updated At"), LICENCE.LAST_UPDATED_BY.as("Last Updated By"), LICENCE.PROVENANCE.as("Provenance")).from(SOFTWARE_USAGE).innerJoin(SOFTWARE_VERSION_LICENCE).on(SOFTWARE_VERSION_LICENCE.SOFTWARE_VERSION_ID.eq(SOFTWARE_USAGE.SOFTWARE_VERSION_ID)).innerJoin(LICENCE).on(LICENCE.ID.eq(SOFTWARE_VERSION_LICENCE.LICENCE_ID)).where(dsl.renderInlined(SOFTWARE_USAGE.APPLICATION_ID.in(appIdSelector)));
String filename = format("licences-%s/%s", entityRef.kind(), entityRef.id());
return writeExtract(filename, qry, request, response);
});
}
Aggregations