@Test public void shouldUpdateFlowsStartAndEndDataShapesWithoutChanges() { final Step step = new Step.Builder() .action(new ConnectorAction.Builder() .descriptor(new ConnectorDescriptor.Builder().build()) .build()) .build(); final Flow flow = new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow1").addSteps(step, step).build(); final Integration existing = new Integration.Builder().addFlow(flow).build(); final Integration given = new Integration.Builder().addFlow(flow).build(); final Integration updated = ApiGeneratorHelper.updateFlowsAndStartAndEndDataShapes(existing, given); assertThat(updated).as("there should be no changes in trivial case").isEqualTo(existing); }
public static Integration updateFlowsAndStartAndEndDataShapes(final Integration existing, final Integration given) { final List<Flow> updatedFlows = new ArrayList<>(given.getFlows().size()); for (final Flow givenFlow : given.getFlows()) { final Optional<String> maybeOperationId = givenFlow.getMetadata(OpenApi.OPERATION_ID); if (!maybeOperationId.isPresent()) { continue; } final String operationId = maybeOperationId.get(); final Optional<Flow> maybeExistingFlow = existing.findFlowBy(operationIdEquals(operationId)); if (!maybeExistingFlow.isPresent()) { updatedFlows.add(givenFlow); continue; } final List<Step> givenSteps = givenFlow.getSteps(); if (givenSteps.size() != 2) { throw new IllegalArgumentException("Expecting to get exactly two steps per flow"); } final Step givenStart = givenSteps.get(0); final Optional<DataShape> givenStartDataShape = givenStart.outputDataShape(); final Step givenEnd = givenSteps.get(1); final Optional<DataShape> givenEndDataShape = givenEnd.inputDataShape(); final Flow existingFlow = maybeExistingFlow.get(); final List<Step> existingSteps = existingFlow.getSteps(); final int start = 0; final int end = existingSteps.size() - 1; final Step existingStart = existingSteps.get(start); final Step updatedStart = existingStart.updateOutputDataShape(givenStartDataShape); final Step existingEnd = existingSteps.get(end); final Step updatedEnd = existingEnd.updateInputDataShape(givenEndDataShape); final List<Step> updatedSteps = new ArrayList<>(existingSteps); updatedSteps.set(start, updatedStart); updatedSteps.set(end, updatedEnd); final Flow updatedFlow = existingFlow.builder() .name(givenFlow.getName()) .description(givenFlow.getDescription()) .steps(updatedSteps) .build(); updatedFlows.add(updatedFlow); } return existing.builder().flows(updatedFlows) .resources(given.getResources()).build(); }
ApiGeneratorHelper { public static Integration updateFlowsAndStartAndEndDataShapes(final Integration existing, final Integration given) { final List<Flow> updatedFlows = new ArrayList<>(given.getFlows().size()); for (final Flow givenFlow : given.getFlows()) { final Optional<String> maybeOperationId = givenFlow.getMetadata(OpenApi.OPERATION_ID); if (!maybeOperationId.isPresent()) { continue; } final String operationId = maybeOperationId.get(); final Optional<Flow> maybeExistingFlow = existing.findFlowBy(operationIdEquals(operationId)); if (!maybeExistingFlow.isPresent()) { updatedFlows.add(givenFlow); continue; } final List<Step> givenSteps = givenFlow.getSteps(); if (givenSteps.size() != 2) { throw new IllegalArgumentException("Expecting to get exactly two steps per flow"); } final Step givenStart = givenSteps.get(0); final Optional<DataShape> givenStartDataShape = givenStart.outputDataShape(); final Step givenEnd = givenSteps.get(1); final Optional<DataShape> givenEndDataShape = givenEnd.inputDataShape(); final Flow existingFlow = maybeExistingFlow.get(); final List<Step> existingSteps = existingFlow.getSteps(); final int start = 0; final int end = existingSteps.size() - 1; final Step existingStart = existingSteps.get(start); final Step updatedStart = existingStart.updateOutputDataShape(givenStartDataShape); final Step existingEnd = existingSteps.get(end); final Step updatedEnd = existingEnd.updateInputDataShape(givenEndDataShape); final List<Step> updatedSteps = new ArrayList<>(existingSteps); updatedSteps.set(start, updatedStart); updatedSteps.set(end, updatedEnd); final Flow updatedFlow = existingFlow.builder() .name(givenFlow.getName()) .description(givenFlow.getDescription()) .steps(updatedSteps) .build(); updatedFlows.add(updatedFlow); } return existing.builder().flows(updatedFlows) .resources(given.getResources()).build(); } }
ApiGeneratorHelper { public static Integration updateFlowsAndStartAndEndDataShapes(final Integration existing, final Integration given) { final List<Flow> updatedFlows = new ArrayList<>(given.getFlows().size()); for (final Flow givenFlow : given.getFlows()) { final Optional<String> maybeOperationId = givenFlow.getMetadata(OpenApi.OPERATION_ID); if (!maybeOperationId.isPresent()) { continue; } final String operationId = maybeOperationId.get(); final Optional<Flow> maybeExistingFlow = existing.findFlowBy(operationIdEquals(operationId)); if (!maybeExistingFlow.isPresent()) { updatedFlows.add(givenFlow); continue; } final List<Step> givenSteps = givenFlow.getSteps(); if (givenSteps.size() != 2) { throw new IllegalArgumentException("Expecting to get exactly two steps per flow"); } final Step givenStart = givenSteps.get(0); final Optional<DataShape> givenStartDataShape = givenStart.outputDataShape(); final Step givenEnd = givenSteps.get(1); final Optional<DataShape> givenEndDataShape = givenEnd.inputDataShape(); final Flow existingFlow = maybeExistingFlow.get(); final List<Step> existingSteps = existingFlow.getSteps(); final int start = 0; final int end = existingSteps.size() - 1; final Step existingStart = existingSteps.get(start); final Step updatedStart = existingStart.updateOutputDataShape(givenStartDataShape); final Step existingEnd = existingSteps.get(end); final Step updatedEnd = existingEnd.updateInputDataShape(givenEndDataShape); final List<Step> updatedSteps = new ArrayList<>(existingSteps); updatedSteps.set(start, updatedStart); updatedSteps.set(end, updatedEnd); final Flow updatedFlow = existingFlow.builder() .name(givenFlow.getName()) .description(givenFlow.getDescription()) .steps(updatedSteps) .build(); updatedFlows.add(updatedFlow); } return existing.builder().flows(updatedFlows) .resources(given.getResources()).build(); } private  ApiGeneratorHelper(); }
ApiGeneratorHelper { public static Integration updateFlowsAndStartAndEndDataShapes(final Integration existing, final Integration given) { final List<Flow> updatedFlows = new ArrayList<>(given.getFlows().size()); for (final Flow givenFlow : given.getFlows()) { final Optional<String> maybeOperationId = givenFlow.getMetadata(OpenApi.OPERATION_ID); if (!maybeOperationId.isPresent()) { continue; } final String operationId = maybeOperationId.get(); final Optional<Flow> maybeExistingFlow = existing.findFlowBy(operationIdEquals(operationId)); if (!maybeExistingFlow.isPresent()) { updatedFlows.add(givenFlow); continue; } final List<Step> givenSteps = givenFlow.getSteps(); if (givenSteps.size() != 2) { throw new IllegalArgumentException("Expecting to get exactly two steps per flow"); } final Step givenStart = givenSteps.get(0); final Optional<DataShape> givenStartDataShape = givenStart.outputDataShape(); final Step givenEnd = givenSteps.get(1); final Optional<DataShape> givenEndDataShape = givenEnd.inputDataShape(); final Flow existingFlow = maybeExistingFlow.get(); final List<Step> existingSteps = existingFlow.getSteps(); final int start = 0; final int end = existingSteps.size() - 1; final Step existingStart = existingSteps.get(start); final Step updatedStart = existingStart.updateOutputDataShape(givenStartDataShape); final Step existingEnd = existingSteps.get(end); final Step updatedEnd = existingEnd.updateInputDataShape(givenEndDataShape); final List<Step> updatedSteps = new ArrayList<>(existingSteps); updatedSteps.set(start, updatedStart); updatedSteps.set(end, updatedEnd); final Flow updatedFlow = existingFlow.builder() .name(givenFlow.getName()) .description(givenFlow.getDescription()) .steps(updatedSteps) .build(); updatedFlows.add(updatedFlow); } return existing.builder().flows(updatedFlows) .resources(given.getResources()).build(); } private  ApiGeneratorHelper(); static APIIntegration generateIntegrationFrom(final APIFormData apiFormData, final DataManager dataManager, final APIGenerator apiGenerator); static Optional<OpenApi> specificationFrom(IntegrationResourceManager resourceManager, final Integration integration); static APIIntegration generateIntegrationUpdateFrom(final Integration existing, final APIFormData apiFormData, final DataManager dataManager,
        final APIGenerator apiGenerator); static Integration updateFlowsAndStartAndEndDataShapes(final Integration existing, final Integration given); }
ApiGeneratorHelper { public static Integration updateFlowsAndStartAndEndDataShapes(final Integration existing, final Integration given) { final List<Flow> updatedFlows = new ArrayList<>(given.getFlows().size()); for (final Flow givenFlow : given.getFlows()) { final Optional<String> maybeOperationId = givenFlow.getMetadata(OpenApi.OPERATION_ID); if (!maybeOperationId.isPresent()) { continue; } final String operationId = maybeOperationId.get(); final Optional<Flow> maybeExistingFlow = existing.findFlowBy(operationIdEquals(operationId)); if (!maybeExistingFlow.isPresent()) { updatedFlows.add(givenFlow); continue; } final List<Step> givenSteps = givenFlow.getSteps(); if (givenSteps.size() != 2) { throw new IllegalArgumentException("Expecting to get exactly two steps per flow"); } final Step givenStart = givenSteps.get(0); final Optional<DataShape> givenStartDataShape = givenStart.outputDataShape(); final Step givenEnd = givenSteps.get(1); final Optional<DataShape> givenEndDataShape = givenEnd.inputDataShape(); final Flow existingFlow = maybeExistingFlow.get(); final List<Step> existingSteps = existingFlow.getSteps(); final int start = 0; final int end = existingSteps.size() - 1; final Step existingStart = existingSteps.get(start); final Step updatedStart = existingStart.updateOutputDataShape(givenStartDataShape); final Step existingEnd = existingSteps.get(end); final Step updatedEnd = existingEnd.updateInputDataShape(givenEndDataShape); final List<Step> updatedSteps = new ArrayList<>(existingSteps); updatedSteps.set(start, updatedStart); updatedSteps.set(end, updatedEnd); final Flow updatedFlow = existingFlow.builder() .name(givenFlow.getName()) .description(givenFlow.getDescription()) .steps(updatedSteps) .build(); updatedFlows.add(updatedFlow); } return existing.builder().flows(updatedFlows) .resources(given.getResources()).build(); } private  ApiGeneratorHelper(); static APIIntegration generateIntegrationFrom(final APIFormData apiFormData, final DataManager dataManager, final APIGenerator apiGenerator); static Optional<OpenApi> specificationFrom(IntegrationResourceManager resourceManager, final Integration integration); static APIIntegration generateIntegrationUpdateFrom(final Integration existing, final APIFormData apiFormData, final DataManager dataManager,
        final APIGenerator apiGenerator); static Integration updateFlowsAndStartAndEndDataShapes(final Integration existing, final Integration given);  }