Search in sources :

Example 6 with PhysicalSpecification

use of org.finos.waltz.model.physical_specification.PhysicalSpecification 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 7 with PhysicalSpecification

use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.

the class PhysicalFlowService method copyExternalIdFromFlowAndSpecification.

private void copyExternalIdFromFlowAndSpecification(String username, EntityReference toRef, PhysicalFlow sourcePhysicalFlow) {
    PhysicalFlow targetPhysicalFlow = physicalFlowDao.getById(toRef.id());
    Set<String> externalIdentifiers = externalIdentifierService.findByEntityReference(toRef).stream().map(ExternalIdentifier::externalId).collect(Collectors.toSet());
    sourcePhysicalFlow.externalId().filter(id -> !isEmpty(id)).ifPresent(sourceExtId -> {
        if (isEmpty(targetPhysicalFlow.externalId())) {
            physicalFlowDao.updateExternalId(toRef.id(), sourceExtId);
        } else if (!externalIdentifiers.contains(sourceExtId)) {
            externalIdentifierService.create(toRef, sourceExtId, username);
            externalIdentifiers.add(sourceExtId);
        }
    });
    PhysicalSpecification sourceSpec = physicalSpecificationService.getById(sourcePhysicalFlow.specificationId());
    sourceSpec.externalId().filter(id -> !isEmpty(id)).ifPresent(sourceExtId -> {
        PhysicalSpecification targetSpec = physicalSpecificationService.getById(targetPhysicalFlow.specificationId());
        if (isEmpty(targetSpec.externalId())) {
            targetSpec.id().ifPresent(id -> physicalSpecificationService.updateExternalId(id, sourceExtId));
        } else if (!externalIdentifiers.contains(sourceExtId)) {
            externalIdentifierService.create(toRef, sourceExtId, username);
        }
    });
}
Also used : org.finos.waltz.model(org.finos.waltz.model) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) CommandOutcome(org.finos.waltz.model.command.CommandOutcome) PhysicalSpecificationService(org.finos.waltz.service.physical_specification.PhysicalSpecificationService) ExternalIdentifier(org.finos.waltz.model.external_identifier.ExternalIdentifier) LocalDateTime(java.time.LocalDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) PhysicalFlowDao(org.finos.waltz.data.physical_flow.PhysicalFlowDao) StringUtilities.isEmpty(org.finos.waltz.common.StringUtilities.isEmpty) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) Record1(org.jooq.Record1) Service(org.springframework.stereotype.Service) LogicalFlowService(org.finos.waltz.service.logical_flow.LogicalFlowService) ImmutablePhysicalSpecificationDeleteCommand(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecificationDeleteCommand) Select(org.jooq.Select) ChangeLogService(org.finos.waltz.service.changelog.ChangeLogService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) ExternalIdentifierService(org.finos.waltz.service.external_identifier.ExternalIdentifierService) Collection(java.util.Collection) StringUtilities.mkSafe(org.finos.waltz.common.StringUtilities.mkSafe) Set(java.util.Set) org.finos.waltz.model.physical_flow(org.finos.waltz.model.physical_flow) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) PhysicalFlowIdSelectorFactory(org.finos.waltz.data.physical_flow.PhysicalFlowIdSelectorFactory) DateTimeUtilities.nowUtc(org.finos.waltz.common.DateTimeUtilities.nowUtc) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) PHYSICAL_FLOW(org.finos.waltz.model.EntityKind.PHYSICAL_FLOW) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification)

Example 8 with PhysicalSpecification

use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.

the class PhysicalFlowGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    List<PhysicalSpecification> specifications = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).fetch(PhysicalSpecificationDao.TO_DOMAIN_MAPPER);
    List<String> transportKinds = dsl.select(ENUM_VALUE.KEY).from(ENUM_VALUE).where(ENUM_VALUE.TYPE.eq(EnumValueKind.TRANSPORT_KIND.dbValue())).fetch(ENUM_VALUE.KEY);
    List<Tuple3<Long, Long, Long>> allLogicalFLows = dsl.select(LOGICAL_FLOW.ID, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.TARGET_ENTITY_ID).from(LOGICAL_FLOW).fetch(r -> Tuple.tuple(r.getValue(LOGICAL_FLOW.ID), r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_ID), r.getValue(LOGICAL_FLOW.TARGET_ENTITY_ID)));
    Map<Long, Collection<Long>> logicalFlowIdsBySourceApp = groupBy(t -> t.v2(), t -> t.v1(), allLogicalFLows);
    final int flowBatchSize = 100000;
    List<PhysicalFlowRecord> flowBatch = new ArrayList<PhysicalFlowRecord>((int) (flowBatchSize * 1.2));
    for (PhysicalSpecification spec : specifications) {
        Collection<Long> relatedLogicalFlowsIds = logicalFlowIdsBySourceApp.get(spec.owningEntity().id());
        if (!isEmpty(relatedLogicalFlowsIds)) {
            List<PhysicalFlowRecord> physicalFlowRecords = mkPhysicalFlowRecords(spec, new LinkedList<>(relatedLogicalFlowsIds), transportKinds);
            flowBatch.addAll(physicalFlowRecords);
        }
        if (flowBatch.size() >= flowBatchSize) {
            log(String.format("--- saving records: count: %s", flowBatch.size()));
            dsl.batchInsert(flowBatch).execute();
            flowBatch.clear();
        }
    }
    log(String.format("--- saving records: count: %s", flowBatch.size()));
    dsl.batchInsert(flowBatch).execute();
    flowBatch.clear();
    log("---done");
    return null;
}
Also used : PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) PhysicalFlowRecord(org.finos.waltz.schema.tables.records.PhysicalFlowRecord) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) DSLContext(org.jooq.DSLContext) Tuple3(org.jooq.lambda.tuple.Tuple3)

Example 9 with PhysicalSpecification

use of org.finos.waltz.model.physical_specification.PhysicalSpecification 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;
}
Also used : LocalDateTime(java.time.LocalDateTime) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) DataFormatKind(org.finos.waltz.model.physical_specification.DataFormatKind) DataTypeDecorator(org.finos.waltz.model.datatype.DataTypeDecorator) EntityReference(org.finos.waltz.model.EntityReference)

Example 10 with PhysicalSpecification

use of org.finos.waltz.model.physical_specification.PhysicalSpecification in project waltz by khartec.

the class PhysicalSpecificationService method markRemovedIfUnused.

public CommandResponse<PhysicalSpecificationDeleteCommand> markRemovedIfUnused(PhysicalSpecificationDeleteCommand command, String username) {
    checkNotNull(command, "command cannot be null");
    CommandOutcome commandOutcome = CommandOutcome.SUCCESS;
    String responseMessage = null;
    PhysicalSpecification specification = specificationDao.getById(command.specificationId());
    if (specification == null) {
        commandOutcome = CommandOutcome.FAILURE;
        responseMessage = "Specification not found";
    } else {
        int deleteCount = specificationDao.markRemovedIfUnused(command.specificationId());
        if (deleteCount == 0) {
            commandOutcome = CommandOutcome.FAILURE;
            responseMessage = "This specification cannot be deleted as it is being referenced by one or more physical flows";
        }
    }
    if (commandOutcome == CommandOutcome.SUCCESS) {
        logChange(username, specification.owningEntity(), String.format("Specification: %s removed", specification.name()), Operation.REMOVE);
    }
    return ImmutableCommandResponse.<PhysicalSpecificationDeleteCommand>builder().entityReference(EntityReference.mkRef(EntityKind.PHYSICAL_SPECIFICATION, command.specificationId())).originalCommand(command).outcome(commandOutcome).message(Optional.ofNullable(responseMessage)).build();
}
Also used : CommandOutcome(org.finos.waltz.model.command.CommandOutcome) ImmutablePhysicalSpecification(org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification)

Aggregations

PhysicalSpecification (org.finos.waltz.model.physical_specification.PhysicalSpecification)21 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)16 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)13 BaseInMemoryIntegrationTest (org.finos.waltz.integration_test.inmem.BaseInMemoryIntegrationTest)9 Test (org.junit.jupiter.api.Test)9 PhysicalFlow (org.finos.waltz.model.physical_flow.PhysicalFlow)4 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)3 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 String.format (java.lang.String.format)2 LocalDateTime (java.time.LocalDateTime)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 DateTimeUtilities.nowUtc (org.finos.waltz.common.DateTimeUtilities.nowUtc)2 ListUtilities.newArrayList (org.finos.waltz.common.ListUtilities.newArrayList)2 StringUtilities.isEmpty (org.finos.waltz.common.StringUtilities.isEmpty)2 PhysicalFlowDao (org.finos.waltz.data.physical_flow.PhysicalFlowDao)2 org.finos.waltz.model (org.finos.waltz.model)2