Search in sources :

Example 1 with ExternalIdentifier

use of org.finos.waltz.model.external_identifier.ExternalIdentifier 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)

Aggregations

String.format (java.lang.String.format)1 LocalDateTime (java.time.LocalDateTime)1 Collection (java.util.Collection)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)1 DateTimeUtilities.nowUtc (org.finos.waltz.common.DateTimeUtilities.nowUtc)1 StringUtilities.isEmpty (org.finos.waltz.common.StringUtilities.isEmpty)1 StringUtilities.mkSafe (org.finos.waltz.common.StringUtilities.mkSafe)1 PhysicalFlowDao (org.finos.waltz.data.physical_flow.PhysicalFlowDao)1 PhysicalFlowIdSelectorFactory (org.finos.waltz.data.physical_flow.PhysicalFlowIdSelectorFactory)1 org.finos.waltz.model (org.finos.waltz.model)1 PHYSICAL_FLOW (org.finos.waltz.model.EntityKind.PHYSICAL_FLOW)1 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)1 CommandOutcome (org.finos.waltz.model.command.CommandOutcome)1 ExternalIdentifier (org.finos.waltz.model.external_identifier.ExternalIdentifier)1 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)1 org.finos.waltz.model.physical_flow (org.finos.waltz.model.physical_flow)1 ImmutablePhysicalSpecification (org.finos.waltz.model.physical_specification.ImmutablePhysicalSpecification)1