@Test public void shouldSetManagementUrl() { Integration integration = new Integration.Builder().id(INTEGRATION_ID).build(); IntegrationDeployment deployment = new IntegrationDeployment.Builder().spec(integration).version(3) .currentState(IntegrationDeploymentState.Published).id(INTEGRATION_DEPLOYMENT_ID).build(); when(dataManager.fetchAll(eq(IntegrationDeployment.class), any(), any())).thenReturn(ListResult.of(deployment)); when(exposueHelper.getManagementUrl(any())).thenReturn("https: IntegrationOverview integrationOverview = handler.toCurrentIntegrationOverview(integration); assertThat(integrationOverview.getManagementUrl()).isEqualTo(Optional.of("https: }
@SuppressWarnings("PMD.NPathComplexity") IntegrationOverview toCurrentIntegrationOverview(final Integration integration) { final String id = integration.getId().get(); final IntegrationOverview.Builder builder = new IntegrationOverview.Builder().createFrom(integration); DataManagerSupport.fetchBoard(dataManager, IntegrationBulletinBoard.class, id).ifPresent(builder::board); builder.isDraft(true); builder.currentState(IntegrationDeploymentState.Unpublished); builder.targetState(IntegrationDeploymentState.Unpublished); if (!integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { throw new IllegalStateException(String.format("Integration has inconsistent state: flows=%d, steps=%d", integration.getFlows().size(), integration.getSteps().size())); } if (integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { builder.addFlow(new Flow.Builder().id(String.format("%s:flows:fromSteps", integration.getId().get())) .name(integration.getName()).description(integration.getDescription()).steps(integration.getSteps()) .build()); builder.steps(Collections.emptyList()); } else { builder.flows(integration.getFlows().stream().map(f -> UpdatesHelper.toCurrentFlow(f, dataManager)) .collect(Collectors.toList())); } final ListResult<IntegrationDeployment> deployments = dataManager.fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id + ":"), ReverseFilter.getInstance()); final List<IntegrationDeployment> activeDeployments = new ArrayList<>(); for (final IntegrationDeployment deployment : deployments) { builder.addDeployment(IntegrationDeploymentOverview.of(deployment)); if (deployment.getCurrentState() == IntegrationDeploymentState.Pending || deployment.getCurrentState() == IntegrationDeploymentState.Published) { activeDeployments.add(deployment); } } Optional<IntegrationDeployment> maybePublished = activeDeployments.stream() .filter(deployment -> deployment.getCurrentState() == IntegrationDeploymentState.Published) .findFirst(); if (integration.isExposable()) { builder.exposureMeans(exposureHelper.getExposureMeans()); } IntegrationDeployment exposedDeployment = null; if (maybePublished.isPresent()) { IntegrationDeployment published = maybePublished.get(); builder.isDraft(computeDraft(integration, published.getSpec())); builder.version(published.getVersion()); exposedDeployment = published; } else if (activeDeployments.size() == 1) { exposedDeployment = activeDeployments.get(0); } if (exposedDeployment != null) { builder.deploymentVersion(exposedDeployment.getVersion()); builder.targetState(exposedDeployment.getTargetState()); builder.currentState(exposedDeployment.getCurrentState()); if (exposedDeployment.getId().isPresent()) { builder.managementUrl(Optional.ofNullable(exposureHelper.getManagementUrl(integration.getExposure()))); final IntegrationEndpoint endpoint = dataManager.fetch(IntegrationEndpoint.class, exposedDeployment.getId().get()); if (endpoint != null) { builder.url(endpoint.getUrl()); } } } else if (!deployments.getItems().isEmpty()) { builder.targetState(deployments.getItems().get(0).getTargetState()); builder.currentState(deployments.getItems().get(0).getCurrentState()); } return builder.build(); }
IntegrationOverviewHelper { @SuppressWarnings("PMD.NPathComplexity") IntegrationOverview toCurrentIntegrationOverview(final Integration integration) { final String id = integration.getId().get(); final IntegrationOverview.Builder builder = new IntegrationOverview.Builder().createFrom(integration); DataManagerSupport.fetchBoard(dataManager, IntegrationBulletinBoard.class, id).ifPresent(builder::board); builder.isDraft(true); builder.currentState(IntegrationDeploymentState.Unpublished); builder.targetState(IntegrationDeploymentState.Unpublished); if (!integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { throw new IllegalStateException(String.format("Integration has inconsistent state: flows=%d, steps=%d", integration.getFlows().size(), integration.getSteps().size())); } if (integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { builder.addFlow(new Flow.Builder().id(String.format("%s:flows:fromSteps", integration.getId().get())) .name(integration.getName()).description(integration.getDescription()).steps(integration.getSteps()) .build()); builder.steps(Collections.emptyList()); } else { builder.flows(integration.getFlows().stream().map(f -> UpdatesHelper.toCurrentFlow(f, dataManager)) .collect(Collectors.toList())); } final ListResult<IntegrationDeployment> deployments = dataManager.fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id + ":"), ReverseFilter.getInstance()); final List<IntegrationDeployment> activeDeployments = new ArrayList<>(); for (final IntegrationDeployment deployment : deployments) { builder.addDeployment(IntegrationDeploymentOverview.of(deployment)); if (deployment.getCurrentState() == IntegrationDeploymentState.Pending || deployment.getCurrentState() == IntegrationDeploymentState.Published) { activeDeployments.add(deployment); } } Optional<IntegrationDeployment> maybePublished = activeDeployments.stream() .filter(deployment -> deployment.getCurrentState() == IntegrationDeploymentState.Published) .findFirst(); if (integration.isExposable()) { builder.exposureMeans(exposureHelper.getExposureMeans()); } IntegrationDeployment exposedDeployment = null; if (maybePublished.isPresent()) { IntegrationDeployment published = maybePublished.get(); builder.isDraft(computeDraft(integration, published.getSpec())); builder.version(published.getVersion()); exposedDeployment = published; } else if (activeDeployments.size() == 1) { exposedDeployment = activeDeployments.get(0); } if (exposedDeployment != null) { builder.deploymentVersion(exposedDeployment.getVersion()); builder.targetState(exposedDeployment.getTargetState()); builder.currentState(exposedDeployment.getCurrentState()); if (exposedDeployment.getId().isPresent()) { builder.managementUrl(Optional.ofNullable(exposureHelper.getManagementUrl(integration.getExposure()))); final IntegrationEndpoint endpoint = dataManager.fetch(IntegrationEndpoint.class, exposedDeployment.getId().get()); if (endpoint != null) { builder.url(endpoint.getUrl()); } } } else if (!deployments.getItems().isEmpty()) { builder.targetState(deployments.getItems().get(0).getTargetState()); builder.currentState(deployments.getItems().get(0).getCurrentState()); } return builder.build(); } }
IntegrationOverviewHelper { @SuppressWarnings("PMD.NPathComplexity") IntegrationOverview toCurrentIntegrationOverview(final Integration integration) { final String id = integration.getId().get(); final IntegrationOverview.Builder builder = new IntegrationOverview.Builder().createFrom(integration); DataManagerSupport.fetchBoard(dataManager, IntegrationBulletinBoard.class, id).ifPresent(builder::board); builder.isDraft(true); builder.currentState(IntegrationDeploymentState.Unpublished); builder.targetState(IntegrationDeploymentState.Unpublished); if (!integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { throw new IllegalStateException(String.format("Integration has inconsistent state: flows=%d, steps=%d", integration.getFlows().size(), integration.getSteps().size())); } if (integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { builder.addFlow(new Flow.Builder().id(String.format("%s:flows:fromSteps", integration.getId().get())) .name(integration.getName()).description(integration.getDescription()).steps(integration.getSteps()) .build()); builder.steps(Collections.emptyList()); } else { builder.flows(integration.getFlows().stream().map(f -> UpdatesHelper.toCurrentFlow(f, dataManager)) .collect(Collectors.toList())); } final ListResult<IntegrationDeployment> deployments = dataManager.fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id + ":"), ReverseFilter.getInstance()); final List<IntegrationDeployment> activeDeployments = new ArrayList<>(); for (final IntegrationDeployment deployment : deployments) { builder.addDeployment(IntegrationDeploymentOverview.of(deployment)); if (deployment.getCurrentState() == IntegrationDeploymentState.Pending || deployment.getCurrentState() == IntegrationDeploymentState.Published) { activeDeployments.add(deployment); } } Optional<IntegrationDeployment> maybePublished = activeDeployments.stream() .filter(deployment -> deployment.getCurrentState() == IntegrationDeploymentState.Published) .findFirst(); if (integration.isExposable()) { builder.exposureMeans(exposureHelper.getExposureMeans()); } IntegrationDeployment exposedDeployment = null; if (maybePublished.isPresent()) { IntegrationDeployment published = maybePublished.get(); builder.isDraft(computeDraft(integration, published.getSpec())); builder.version(published.getVersion()); exposedDeployment = published; } else if (activeDeployments.size() == 1) { exposedDeployment = activeDeployments.get(0); } if (exposedDeployment != null) { builder.deploymentVersion(exposedDeployment.getVersion()); builder.targetState(exposedDeployment.getTargetState()); builder.currentState(exposedDeployment.getCurrentState()); if (exposedDeployment.getId().isPresent()) { builder.managementUrl(Optional.ofNullable(exposureHelper.getManagementUrl(integration.getExposure()))); final IntegrationEndpoint endpoint = dataManager.fetch(IntegrationEndpoint.class, exposedDeployment.getId().get()); if (endpoint != null) { builder.url(endpoint.getUrl()); } } } else if (!deployments.getItems().isEmpty()) { builder.targetState(deployments.getItems().get(0).getTargetState()); builder.currentState(deployments.getItems().get(0).getCurrentState()); } return builder.build(); } IntegrationOverviewHelper(DataManager dataManager, ExposureHelper exposureHelper); }
IntegrationOverviewHelper { @SuppressWarnings("PMD.NPathComplexity") IntegrationOverview toCurrentIntegrationOverview(final Integration integration) { final String id = integration.getId().get(); final IntegrationOverview.Builder builder = new IntegrationOverview.Builder().createFrom(integration); DataManagerSupport.fetchBoard(dataManager, IntegrationBulletinBoard.class, id).ifPresent(builder::board); builder.isDraft(true); builder.currentState(IntegrationDeploymentState.Unpublished); builder.targetState(IntegrationDeploymentState.Unpublished); if (!integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { throw new IllegalStateException(String.format("Integration has inconsistent state: flows=%d, steps=%d", integration.getFlows().size(), integration.getSteps().size())); } if (integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { builder.addFlow(new Flow.Builder().id(String.format("%s:flows:fromSteps", integration.getId().get())) .name(integration.getName()).description(integration.getDescription()).steps(integration.getSteps()) .build()); builder.steps(Collections.emptyList()); } else { builder.flows(integration.getFlows().stream().map(f -> UpdatesHelper.toCurrentFlow(f, dataManager)) .collect(Collectors.toList())); } final ListResult<IntegrationDeployment> deployments = dataManager.fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id + ":"), ReverseFilter.getInstance()); final List<IntegrationDeployment> activeDeployments = new ArrayList<>(); for (final IntegrationDeployment deployment : deployments) { builder.addDeployment(IntegrationDeploymentOverview.of(deployment)); if (deployment.getCurrentState() == IntegrationDeploymentState.Pending || deployment.getCurrentState() == IntegrationDeploymentState.Published) { activeDeployments.add(deployment); } } Optional<IntegrationDeployment> maybePublished = activeDeployments.stream() .filter(deployment -> deployment.getCurrentState() == IntegrationDeploymentState.Published) .findFirst(); if (integration.isExposable()) { builder.exposureMeans(exposureHelper.getExposureMeans()); } IntegrationDeployment exposedDeployment = null; if (maybePublished.isPresent()) { IntegrationDeployment published = maybePublished.get(); builder.isDraft(computeDraft(integration, published.getSpec())); builder.version(published.getVersion()); exposedDeployment = published; } else if (activeDeployments.size() == 1) { exposedDeployment = activeDeployments.get(0); } if (exposedDeployment != null) { builder.deploymentVersion(exposedDeployment.getVersion()); builder.targetState(exposedDeployment.getTargetState()); builder.currentState(exposedDeployment.getCurrentState()); if (exposedDeployment.getId().isPresent()) { builder.managementUrl(Optional.ofNullable(exposureHelper.getManagementUrl(integration.getExposure()))); final IntegrationEndpoint endpoint = dataManager.fetch(IntegrationEndpoint.class, exposedDeployment.getId().get()); if (endpoint != null) { builder.url(endpoint.getUrl()); } } } else if (!deployments.getItems().isEmpty()) { builder.targetState(deployments.getItems().get(0).getTargetState()); builder.currentState(deployments.getItems().get(0).getCurrentState()); } return builder.build(); } IntegrationOverviewHelper(DataManager dataManager, ExposureHelper exposureHelper);  }
IntegrationOverviewHelper { @SuppressWarnings("PMD.NPathComplexity") IntegrationOverview toCurrentIntegrationOverview(final Integration integration) { final String id = integration.getId().get(); final IntegrationOverview.Builder builder = new IntegrationOverview.Builder().createFrom(integration); DataManagerSupport.fetchBoard(dataManager, IntegrationBulletinBoard.class, id).ifPresent(builder::board); builder.isDraft(true); builder.currentState(IntegrationDeploymentState.Unpublished); builder.targetState(IntegrationDeploymentState.Unpublished); if (!integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { throw new IllegalStateException(String.format("Integration has inconsistent state: flows=%d, steps=%d", integration.getFlows().size(), integration.getSteps().size())); } if (integration.getFlows().isEmpty() && !integration.getSteps().isEmpty()) { builder.addFlow(new Flow.Builder().id(String.format("%s:flows:fromSteps", integration.getId().get())) .name(integration.getName()).description(integration.getDescription()).steps(integration.getSteps()) .build()); builder.steps(Collections.emptyList()); } else { builder.flows(integration.getFlows().stream().map(f -> UpdatesHelper.toCurrentFlow(f, dataManager)) .collect(Collectors.toList())); } final ListResult<IntegrationDeployment> deployments = dataManager.fetchAll(IntegrationDeployment.class, new IdPrefixFilter<>(id + ":"), ReverseFilter.getInstance()); final List<IntegrationDeployment> activeDeployments = new ArrayList<>(); for (final IntegrationDeployment deployment : deployments) { builder.addDeployment(IntegrationDeploymentOverview.of(deployment)); if (deployment.getCurrentState() == IntegrationDeploymentState.Pending || deployment.getCurrentState() == IntegrationDeploymentState.Published) { activeDeployments.add(deployment); } } Optional<IntegrationDeployment> maybePublished = activeDeployments.stream() .filter(deployment -> deployment.getCurrentState() == IntegrationDeploymentState.Published) .findFirst(); if (integration.isExposable()) { builder.exposureMeans(exposureHelper.getExposureMeans()); } IntegrationDeployment exposedDeployment = null; if (maybePublished.isPresent()) { IntegrationDeployment published = maybePublished.get(); builder.isDraft(computeDraft(integration, published.getSpec())); builder.version(published.getVersion()); exposedDeployment = published; } else if (activeDeployments.size() == 1) { exposedDeployment = activeDeployments.get(0); } if (exposedDeployment != null) { builder.deploymentVersion(exposedDeployment.getVersion()); builder.targetState(exposedDeployment.getTargetState()); builder.currentState(exposedDeployment.getCurrentState()); if (exposedDeployment.getId().isPresent()) { builder.managementUrl(Optional.ofNullable(exposureHelper.getManagementUrl(integration.getExposure()))); final IntegrationEndpoint endpoint = dataManager.fetch(IntegrationEndpoint.class, exposedDeployment.getId().get()); if (endpoint != null) { builder.url(endpoint.getUrl()); } } } else if (!deployments.getItems().isEmpty()) { builder.targetState(deployments.getItems().get(0).getTargetState()); builder.currentState(deployments.getItems().get(0).getCurrentState()); } return builder.build(); } IntegrationOverviewHelper(DataManager dataManager, ExposureHelper exposureHelper);   }