Search in sources :

Example 11 with IdSelectionOptions

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityStatisticValueDao(org.finos.waltz.data.entity_statistic.EntityStatisticValueDao) DSLContext(org.jooq.DSLContext) EntityStatisticService(org.finos.waltz.service.entity_statistic.EntityStatisticService) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 12 with IdSelectionOptions

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");
}
Also used : PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) CommandOutcome(org.finos.waltz.model.command.CommandOutcome) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) Autowired(org.springframework.beans.factory.annotation.Autowired) SetUtilities.asSet(org.finos.waltz.common.SetUtilities.asSet) DataTypeDecoratorService(org.finos.waltz.service.data_type.DataTypeDecoratorService) EntitySearchOptions.mkForEntity(org.finos.waltz.model.entity_search.EntitySearchOptions.mkForEntity) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) org.finos.waltz.model.physical_specification(org.finos.waltz.model.physical_specification) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) NameHelper.mkName(org.finos.waltz.integration_test.inmem.helpers.NameHelper.mkName) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) org.finos.waltz.integration_test.inmem.helpers(org.finos.waltz.integration_test.inmem.helpers) CommandResponse(org.finos.waltz.model.command.CommandResponse) PhysicalFlowCreateCommandResponse(org.finos.waltz.model.physical_flow.PhysicalFlowCreateCommandResponse) CollectionUtilities.first(org.finos.waltz.common.CollectionUtilities.first) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) Set(java.util.Set) UserTimestamp(org.finos.waltz.model.UserTimestamp) Test(org.junit.jupiter.api.Test) List(java.util.List) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) PhysicalSpecDefinitionService(org.finos.waltz.service.physical_specification_definition.PhysicalSpecDefinitionService) ListUtilities.asList(org.finos.waltz.common.ListUtilities.asList) Assertions(org.junit.jupiter.api.Assertions) EntityReference(org.finos.waltz.model.EntityReference) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) EntityReference(org.finos.waltz.model.EntityReference) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) BaseInMemoryIntegrationTest(org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 13 with IdSelectionOptions

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());
}
Also used : ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) EntityKind(org.finos.waltz.model.EntityKind) PhysicalFlowChangeUnitViewItem(org.finos.waltz.model.change_unit.PhysicalFlowChangeUnitViewItem) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Autowired(org.springframework.beans.factory.annotation.Autowired) RatingSchemeService(org.finos.waltz.service.rating_scheme.RatingSchemeService) AssessmentRatingDetail(org.finos.waltz.model.assessment_rating.AssessmentRatingDetail) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) SetUtilities.map(org.finos.waltz.common.SetUtilities.map) ImmutablePhysicalFlowChangeUnitViewItem(org.finos.waltz.model.change_unit.ImmutablePhysicalFlowChangeUnitViewItem) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) Service(org.springframework.stereotype.Service) MapUtilities.groupBy(org.finos.waltz.common.MapUtilities.groupBy) Map(java.util.Map) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) Collectors.toSet(java.util.stream.Collectors.toSet) IdSelectionOptions.mkOptsForAllLifecycleStates(org.finos.waltz.model.IdSelectionOptions.mkOptsForAllLifecycleStates) PhysicalFlowService(org.finos.waltz.service.physical_flow.PhysicalFlowService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Collections.emptySet(java.util.Collections.emptySet) Collection(java.util.Collection) Set(java.util.Set) MapUtilities.indexBy(org.finos.waltz.common.MapUtilities.indexBy) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) AssessmentRatingService(org.finos.waltz.service.assessment_rating.AssessmentRatingService) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) ImmutableAssessmentRatingDetail(org.finos.waltz.model.assessment_rating.ImmutableAssessmentRatingDetail) HierarchyQueryScope(org.finos.waltz.model.HierarchyQueryScope) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) Collectors.toSet(java.util.stream.Collectors.toSet) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) RatingSchemeItem(org.finos.waltz.model.rating.RatingSchemeItem) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) AssessmentRating(org.finos.waltz.model.assessment_rating.AssessmentRating) Collection(java.util.Collection) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 14 with IdSelectionOptions

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();
    });
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationIdSelectorFactory(org.finos.waltz.data.application.ApplicationIdSelectorFactory) ScenarioRatingItemRecord(org.finos.waltz.schema.tables.records.ScenarioRatingItemRecord) Timestamp(java.sql.Timestamp) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Example 15 with IdSelectionOptions

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);
    });
}
Also used : EntityReference(org.finos.waltz.model.EntityReference) IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions)

Aggregations

IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)39 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)15 EntityReference (org.finos.waltz.model.EntityReference)14 Record1 (org.jooq.Record1)9 DSLContext (org.jooq.DSLContext)8 EntityKind (org.finos.waltz.model.EntityKind)7 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)6 ApplicationIdSelectorFactory (org.finos.waltz.data.application.ApplicationIdSelectorFactory)5 LogicalFlowService (org.finos.waltz.service.logical_flow.LogicalFlowService)5 Collection (java.util.Collection)4 List (java.util.List)4 GenericSelector (org.finos.waltz.data.GenericSelector)4 IdSelectionOptions.mkOpts (org.finos.waltz.model.IdSelectionOptions.mkOpts)4 Set (java.util.Set)3 MeasurableIdSelectorFactory (org.finos.waltz.data.measurable.MeasurableIdSelectorFactory)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 Collections.emptySet (java.util.Collections.emptySet)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2