test_class.declarator: connectionConfig
test_class.modifier: private
test_class.original_string: private VersionedConnection connectionConfig;
test_class.type: VersionedConnection
test_class.var_name: connectionConfig
test_class.declarator: connectionService
test_class.modifier: private
test_class.original_string: private FDConnectionService connectionService;
test_class.type: FDConnectionService
test_class.var_name: connectionService
test_class.file: efm/efm-flow-designer/efm-flow-designer-framework/src/test/java/com/cloudera/cem/efm/service/component/TestStandardFDConnectionService.java
test_class.identifier: TestStandardFDConnectionService
test_class.superclass: extends BaseFDServiceTest
test_case.body: @Test(expected = IllegalArgumentException.class)
      public void testUpdateWhenDestinationGroupDoesNotExist() {
          final String flowId = flow.getFlowMetadata().getIdentifier();
          when(flowManager.getFlow(flowId)).thenReturn(Optional.of(flow));
  
          final ConnectableComponent newDest = ComponentUtils.createConnectableComponent(group2Processor1);
          newDest.setGroupId("DOES-NOT-EXIST");
  
          final VersionedConnection requestConnection = new VersionedConnection();
          requestConnection.setIdentifier(connectionG2P2toG2P3.getIdentifier());
          requestConnection.setSource(connectionG2P2toG2P3.getSource());
          requestConnection.setDestination(newDest);
  
          connectionService.update(flowId, requestConnection);
      }
test_case.class_method_signature: TestStandardFDConnectionService.testUpdateWhenDestinationGroupDoesNotExist()
test_case.full_signature: @Test(expected = IllegalArgumentException.class) public void testUpdateWhenDestinationGroupDoesNotExist()
test_case.identifier: testUpdateWhenDestinationGroupDoesNotExist
test_case.invocations: getIdentifier getFlowMetadata thenReturn when getFlow of createConnectableComponent setGroupId setIdentifier getIdentifier setSource getSource setDestination update
test_case.modifiers: @Test(expected = IllegalArgumentException.class) public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testUpdateWhenDestinationGroupDoesNotExist()
focal_class.declarator: DEFAULT_BACK_PRESSURE_DATA_SIZE_THRESHOLD = "10000 B"
focal_class.modifier: public static final
focal_class.original_string: public static final String DEFAULT_BACK_PRESSURE_DATA_SIZE_THRESHOLD = "10000 B";
focal_class.type: String
focal_class.var_name: DEFAULT_BACK_PRESSURE_DATA_SIZE_THRESHOLD
focal_class.declarator: DEFAULT_BACK_PRESSURE_OBJECT_SIZE_THRESHOLD = 0
focal_class.modifier: public static final
focal_class.original_string: public static final long DEFAULT_BACK_PRESSURE_OBJECT_SIZE_THRESHOLD = 0;
focal_class.type: long
focal_class.var_name: DEFAULT_BACK_PRESSURE_OBJECT_SIZE_THRESHOLD
focal_class.declarator: DEFAULT_FLOW_FILE_EXPIRATION = "60 seconds"
focal_class.modifier: public static final
focal_class.original_string: public static final String DEFAULT_FLOW_FILE_EXPIRATION = "60 seconds";
focal_class.type: String
focal_class.var_name: DEFAULT_FLOW_FILE_EXPIRATION
focal_class.declarator: componentTypeFunctionMap
focal_class.modifier: private static
focal_class.original_string: private static Map<ConnectableComponentType, Function<VersionedProcessGroup, Set<? extends VersionedComponent>>> componentTypeFunctionMap;
focal_class.type: Map<ConnectableComponentType, Function<VersionedProcessGroup, Set<? extends VersionedComponent>>>
focal_class.var_name: componentTypeFunctionMap
focal_class.file: efm/efm-flow-designer/efm-flow-designer-framework/src/main/java/com/cloudera/cem/efm/service/component/StandardFDConnectionService.java
focal_class.identifier: StandardFDConnectionService
focal_class.interfaces: implements com.cloudera.cem.efm.service.component.FDConnectionService
focal_class.class_method_signature: StandardFDConnectionService.StandardFDConnectionService(final FDFlowManager flowManager, final ValidationService validationService)
focal_class.full_signature: public  StandardFDConnectionService(final FDFlowManager flowManager, final ValidationService validationService)
focal_class.identifier: StandardFDConnectionService
focal_class.modifiers: public
focal_class.parameters: (final FDFlowManager flowManager, final ValidationService validationService)
focal_class.signature:  StandardFDConnectionService(final FDFlowManager flowManager, final ValidationService validationService)
focal_class.class_method_signature: StandardFDConnectionService.create(final String flowId, final String processGroupId, final VersionedConnection requestComponentConfig)
focal_class.full_signature: @Override public FDConnection create(final String flowId, final String processGroupId, final VersionedConnection requestComponentConfig)
focal_class.identifier: create
focal_class.modifiers: @Override public
focal_class.parameters: (final String flowId, final String processGroupId, final VersionedConnection requestComponentConfig)
focal_class.return: FDConnection
focal_class.signature: FDConnection create(final String flowId, final String processGroupId, final VersionedConnection requestComponentConfig)
focal_class.class_method_signature: StandardFDConnectionService.get(final String flowId, final String componentId)
focal_class.full_signature: @Override public FDConnection get(final String flowId, final String componentId)
focal_class.identifier: get
focal_class.modifiers: @Override public
focal_class.parameters: (final String flowId, final String componentId)
focal_class.return: FDConnection
focal_class.signature: FDConnection get(final String flowId, final String componentId)
focal_class.class_method_signature: StandardFDConnectionService.update(final String flowId, final VersionedConnection requestComponentConfig)
focal_class.full_signature: @Override public FDConnection update(final String flowId, final VersionedConnection requestComponentConfig)
focal_class.identifier: update
focal_class.modifiers: @Override public
focal_class.parameters: (final String flowId, final VersionedConnection requestComponentConfig)
focal_class.return: FDConnection
focal_class.signature: FDConnection update(final String flowId, final VersionedConnection requestComponentConfig)
focal_class.class_method_signature: StandardFDConnectionService.delete(final String flowId, final String componentId)
focal_class.full_signature: @Override public void delete(final String flowId, final String componentId)
focal_class.identifier: delete
focal_class.modifiers: @Override public
focal_class.parameters: (final String flowId, final String componentId)
focal_class.return: void
focal_class.signature: void delete(final String flowId, final String componentId)
focal_class.class_method_signature: StandardFDConnectionService.instantiateComponent(final VersionedConnection componentConfig)
focal_class.full_signature: @Override protected FDConnection instantiateComponent(final VersionedConnection componentConfig)
focal_class.identifier: instantiateComponent
focal_class.modifiers: @Override protected
focal_class.parameters: (final VersionedConnection componentConfig)
focal_class.return: FDConnection
focal_class.signature: FDConnection instantiateComponent(final VersionedConnection componentConfig)
focal_class.class_method_signature: StandardFDConnectionService.configureComponentSpecifics(final VersionedConnection requestComponent,
                                                 final VersionedConnection resultComponent)
focal_class.full_signature: @Override protected void configureComponentSpecifics(final VersionedConnection requestComponent,
                                                 final VersionedConnection resultComponent)
focal_class.identifier: configureComponentSpecifics
focal_class.modifiers: @Override protected
focal_class.parameters: (final VersionedConnection requestComponent,
                                                 final VersionedConnection resultComponent)
focal_class.return: void
focal_class.signature: void configureComponentSpecifics(final VersionedConnection requestComponent,
                                                 final VersionedConnection resultComponent)
focal_class.class_method_signature: StandardFDConnectionService.containsChildGroup(final VersionedProcessGroup parentGroup, final String childGroupId)
focal_class.full_signature: private boolean containsChildGroup(final VersionedProcessGroup parentGroup, final String childGroupId)
focal_class.identifier: containsChildGroup
focal_class.modifiers: private
focal_class.parameters: (final VersionedProcessGroup parentGroup, final String childGroupId)
focal_class.return: boolean
focal_class.signature: boolean containsChildGroup(final VersionedProcessGroup parentGroup, final String childGroupId)
focal_class.class_method_signature: StandardFDConnectionService.containsConnectable(final VersionedProcessGroup sourceGroup, final ConnectableComponent source)
focal_class.full_signature: private boolean containsConnectable(final VersionedProcessGroup sourceGroup, final ConnectableComponent source)
focal_class.identifier: containsConnectable
focal_class.modifiers: private
focal_class.parameters: (final VersionedProcessGroup sourceGroup, final ConnectableComponent source)
focal_class.return: boolean
focal_class.signature: boolean containsConnectable(final VersionedProcessGroup sourceGroup, final ConnectableComponent source)
focal_class.class_method_signature: StandardFDConnectionService.getVersionedComponentConnectable(
              final VersionedProcessGroup sourceGroup, final ConnectableComponent source)
focal_class.full_signature: private Optional<VersionedComponent> getVersionedComponentConnectable(
              final VersionedProcessGroup sourceGroup, final ConnectableComponent source)
focal_class.identifier: getVersionedComponentConnectable
focal_class.modifiers: private
focal_class.parameters: (
              final VersionedProcessGroup sourceGroup, final ConnectableComponent source)
focal_class.return: Optional<VersionedComponent>
focal_class.signature: Optional<VersionedComponent> getVersionedComponentConnectable(
              final VersionedProcessGroup sourceGroup, final ConnectableComponent source)
focal_class.class_method_signature: StandardFDConnectionService.isDestStillUsed(final VersionedConnection existingConnection,
                                      final ConnectableComponent existingDestination,
                                      final VersionedProcessGroup connectionGroup)
focal_class.full_signature: private boolean isDestStillUsed(final VersionedConnection existingConnection,
                                      final ConnectableComponent existingDestination,
                                      final VersionedProcessGroup connectionGroup)
focal_class.identifier: isDestStillUsed
focal_class.modifiers: private
focal_class.parameters: (final VersionedConnection existingConnection,
                                      final ConnectableComponent existingDestination,
                                      final VersionedProcessGroup connectionGroup)
focal_class.return: boolean
focal_class.signature: boolean isDestStillUsed(final VersionedConnection existingConnection,
                                      final ConnectableComponent existingDestination,
                                      final VersionedProcessGroup connectionGroup)
focal_class.class_method_signature: StandardFDConnectionService.isSourceStillUsed(final VersionedConnection existingConnection,
                                      final ConnectableComponent existingSource,
                                      final VersionedProcessGroup connectionGroup)
focal_class.full_signature: private boolean isSourceStillUsed(final VersionedConnection existingConnection,
                                      final ConnectableComponent existingSource,
                                      final VersionedProcessGroup connectionGroup)
focal_class.identifier: isSourceStillUsed
focal_class.modifiers: private
focal_class.parameters: (final VersionedConnection existingConnection,
                                      final ConnectableComponent existingSource,
                                      final VersionedProcessGroup connectionGroup)
focal_class.return: boolean
focal_class.signature: boolean isSourceStillUsed(final VersionedConnection existingConnection,
                                      final ConnectableComponent existingSource,
                                      final VersionedProcessGroup connectionGroup)
focal_class.class_method_signature: StandardFDConnectionService.removeRemoteInputPort(final VersionedProcessGroup connectionGroup, final ConnectableComponent remoteInputPort)
focal_class.full_signature: private void removeRemoteInputPort(final VersionedProcessGroup connectionGroup, final ConnectableComponent remoteInputPort)
focal_class.identifier: removeRemoteInputPort
focal_class.modifiers: private
focal_class.parameters: (final VersionedProcessGroup connectionGroup, final ConnectableComponent remoteInputPort)
focal_class.return: void
focal_class.signature: void removeRemoteInputPort(final VersionedProcessGroup connectionGroup, final ConnectableComponent remoteInputPort)
focal_class.class_method_signature: StandardFDConnectionService.removeRemoteOutputPort(VersionedProcessGroup connectionGroup, ConnectableComponent remoteOutputPort)
focal_class.full_signature: private void removeRemoteOutputPort(VersionedProcessGroup connectionGroup, ConnectableComponent remoteOutputPort)
focal_class.identifier: removeRemoteOutputPort
focal_class.modifiers: private
focal_class.parameters: (VersionedProcessGroup connectionGroup, ConnectableComponent remoteOutputPort)
focal_class.return: void
focal_class.signature: void removeRemoteOutputPort(VersionedProcessGroup connectionGroup, ConnectableComponent remoteOutputPort)
focal_class.class_method_signature: StandardFDConnectionService.validateRequestConfig(final VersionedConnection requestComponentConfig)
focal_class.full_signature: private void validateRequestConfig(final VersionedConnection requestComponentConfig)
focal_class.identifier: validateRequestConfig
focal_class.modifiers: private
focal_class.parameters: (final VersionedConnection requestComponentConfig)
focal_class.return: void
focal_class.signature: void validateRequestConfig(final VersionedConnection requestComponentConfig)
focal_class.superclass: extends BaseComponentService<VersionedConnection, FDConnection>
focal_method.body: @Override
      public FDConnection update(final String flowId, final VersionedConnection requestComponentConfig) {
          final FDFlow currentFlow = getFlowOrNotFound(flowId);
          final VersionedProcessGroup flowContents = currentFlow.getFlowContent();
  
          // locate the connection component and ensure it exists
          final String componentId = requestComponentConfig.getIdentifier();
          final VersionedConnection existingConnection = ComponentUtils.getComponentOrNotFound(
                  componentId, flowContents, VersionedProcessGroup::getConnections);
  
          // locate the connection group and ensure it exists
          final String connectionGroupId = existingConnection.getGroupIdentifier();
          final VersionedProcessGroup connectionGroup = ComponentUtils.getProcessGroupOrIllegalArgument(connectionGroupId, flowContents);
  
          final ConnectableComponent requestSource = requestComponentConfig.getSource();
          final ConnectableComponent existingSource = existingConnection.getSource();
  
          // if a source was provided then ensure it is the same source as the existing connection
          if (isNotNull(requestSource) && isNotNull(requestSource.getId()) && !requestSource.getId().equals(existingSource.getId())) {
              throw new IllegalStateException("Connection with id " + existingConnection.getIdentifier() + " has conflicting source id");
          }
  
          // If a processor specifies a non-null set of selected relationships, then it must not be empty
          if (existingSource.getType() == ConnectableComponentType.PROCESSOR
                  && isNotNull(requestComponentConfig.getSelectedRelationships())
                  && requestComponentConfig.getSelectedRelationships().isEmpty()) {
              throw new IllegalArgumentException("Selected relationships cannot be empty");
          }
  
          // validate the common request fields for create/update
          validateRequestConfig(requestComponentConfig);
  
          // determine if the destination changed
          final ConnectableComponent proposedDestination = requestComponentConfig.getDestination();
          if (proposedDestination != null) {
              if (proposedDestination.getId() == null) {
                  throw new IllegalArgumentException("Proposed destination must contain an id");
              }
  
              if (proposedDestination.getType() == null) {
                  throw new IllegalArgumentException("Proposed destination must contain a type");
              }
  
              if (proposedDestination.getType() == ConnectableComponentType.FUNNEL
                      && proposedDestination.getId().equals(existingSource.getId())) {
                  throw new IllegalArgumentException("Connecting a funnel to itself is not allowed");
              }
  
              final ConnectableComponent currentDestination = existingConnection.getDestination();
  
              // handle remote input port differently
              if (ConnectableComponentType.REMOTE_OUTPUT_PORT == proposedDestination.getType()) {
                  throw new IllegalArgumentException("Destination cannot be a remote output port");
              } else if (ConnectableComponentType.REMOTE_INPUT_PORT == proposedDestination.getType()) {
  
                  final String proposedDestinationId = proposedDestination.getId();
                  final String proposedDestinationGroupId = proposedDestination.getGroupId();
  
                  try {
                      UUID.fromString(proposedDestinationId);
                  } catch (Exception  e) {
                      throw new IllegalArgumentException("The ID of a remote input port must be a UUID");
                  }
  
                  // the group id must be specified
                  if (proposedDestinationGroupId == null) {
                      throw new IllegalArgumentException("When the destination is a remote input port its group id is required.");
                  }
  
                  // if the current destination is a remote input port
                  boolean isDifferentRemoteProcessGroup = false;
                  if (currentDestination.getType() == ConnectableComponentType.REMOTE_INPUT_PORT) {
                      if (!proposedDestinationGroupId.equals(currentDestination.getGroupId())) {
                          isDifferentRemoteProcessGroup = true;
                      }
                  }
  
                  // if the destination is changing or the previous destination was a different remote process group
                  if (!proposedDestinationId.equals(currentDestination.getId()) || isDifferentRemoteProcessGroup) {
                      // locate the remote process group or throw exception if not found
                      final VersionedRemoteProcessGroup proposedRemoteProcessGroup = connectionGroup.getRemoteProcessGroups().stream()
                              .filter(rpg -> rpg.getIdentifier().equals(proposedDestinationGroupId))
                              .findFirst()
                              .orElseThrow(() -> new IllegalArgumentException("Unable to find the specified remote process group for the destination"));
  
                      // locate an existing remote input port with a target id that matches the proposed destination id
                      final Optional<VersionedRemoteGroupPort> remoteInputPort = proposedRemoteProcessGroup.getInputPorts().stream()
                              .filter(p -> p.getTargetId().equals(proposedDestinationId))
                              .findFirst();
  
                      // if an existing port wasn't found then create one
                      final VersionedRemoteGroupPort newRemoteInputPort = new VersionedRemoteGroupPort();
                      if (!remoteInputPort.isPresent()) {
                          newRemoteInputPort.setIdentifier(UUID.randomUUID().toString());
                          newRemoteInputPort.setGroupIdentifier(connectionGroup.getIdentifier());
                          newRemoteInputPort.setRemoteGroupId(proposedDestinationGroupId);
                          newRemoteInputPort.setTargetId(proposedDestinationId);
                          newRemoteInputPort.setName(proposedDestinationId);
                          newRemoteInputPort.setComponentType(ComponentType.REMOTE_INPUT_PORT);
                      }
  
                      // determine if any other connections are still using the original remote input port, and if not remove it
                      if (!isDestStillUsed(existingConnection, currentDestination, connectionGroup)) {
                          removeRemoteInputPort(connectionGroup, currentDestination);
                      }
  
                      // add the port and update destination on the existing connection
                      proposedRemoteProcessGroup.getInputPorts().add(newRemoteInputPort);
                      proposedDestination.setName(proposedDestinationId);
                      existingConnection.setDestination(proposedDestination);
                  }
  
              } else {
  
                  // if there is a different destination id
                  if (!proposedDestination.getId().equals(currentDestination.getId())) {
                      // if the destination connectable's group id has not been set, its inferred to be the current group
                      if (proposedDestination.getGroupId() == null) {
                          proposedDestination.setGroupId(existingConnection.getGroupIdentifier());
                      }
  
                      // locate the destination group and ensure it exists
                      final VersionedProcessGroup destinationGroup = ComponentUtils.getProcessGroupOrIllegalArgument(
                              proposedDestination.getGroupId(), currentFlow.getFlowContent());
  
                      // locate destination component in the destination group and ensure it exists
                      final Optional<VersionedComponent> newDestination = getVersionedComponentConnectable(
                              destinationGroup, proposedDestination);
  
                      if (!newDestination.isPresent()) {
                          throw new IllegalArgumentException("Unable to find the specified destination.");
                      }
  
                      // if the group of the new dest component is not the group the connection is in, then ensure
                      // the group is a child of the connection's group, and ensure the component is an input port
  
                      final String existingConnectionGroupId = existingConnection.getGroupIdentifier();
                      final String newDestinationGroupId = newDestination.get().getGroupIdentifier();
  
                      if (!existingConnectionGroupId.equals(newDestinationGroupId)) {
                          final ComponentType newDestinationComponentType = newDestination.get().getComponentType();
                          if (newDestinationComponentType != ComponentType.INPUT_PORT) {
                              throw new IllegalStateException("Cannot update connection because the destination is in " +
                                      "a different process group and is not an input port");
                          }
  
                          final boolean connectionGroupContainsDestGroup = containsChildGroup(connectionGroup, newDestinationGroupId);
                          if (!connectionGroupContainsDestGroup) {
                              throw new IllegalStateException("Cannot update connection because the new destination " +
                                      "group is not a child group of the connection group");
                          }
                      }
  
                      // update the existing connection's destination
                      existingConnection.setDestination(proposedDestination);
                  }
              }
          }
  
          final FDConnection connection = updateComponent(currentFlow, requestComponentConfig, existingConnection, null);
  
          getValidationService().clearValidationErrors(connection.getComponentConfiguration().getSource().getId());
          getValidationService().clearValidationErrors(connection.getComponentConfiguration().getDestination().getId());
  
          return connection;
      }
focal_method.class_method_signature: StandardFDConnectionService.update(final String flowId, final VersionedConnection requestComponentConfig)
focal_method.full_signature: @Override public FDConnection update(final String flowId, final VersionedConnection requestComponentConfig)
focal_method.identifier: update
focal_method.invocations: getFlowOrNotFound getFlowContent getIdentifier getComponentOrNotFound getGroupIdentifier getProcessGroupOrIllegalArgument getSource getSource isNotNull isNotNull getId equals getId getId getIdentifier getType isNotNull getSelectedRelationships isEmpty getSelectedRelationships validateRequestConfig getDestination getId getType getType equals getId getId getDestination getType getType getId getGroupId fromString getType equals getGroupId equals getId orElseThrow findFirst filter stream getRemoteProcessGroups equals getIdentifier findFirst filter stream getInputPorts equals getTargetId isPresent setIdentifier toString randomUUID setGroupIdentifier getIdentifier setRemoteGroupId setTargetId setName setComponentType isDestStillUsed removeRemoteInputPort add getInputPorts setName setDestination equals getId getId getGroupId setGroupId getGroupIdentifier getProcessGroupOrIllegalArgument getGroupId getFlowContent getVersionedComponentConnectable isPresent getGroupIdentifier getGroupIdentifier get equals getComponentType get containsChildGroup setDestination updateComponent clearValidationErrors getValidationService getId getSource getComponentConfiguration clearValidationErrors getValidationService getId getDestination getComponentConfiguration
focal_method.modifiers: @Override public
focal_method.parameters: (final String flowId, final VersionedConnection requestComponentConfig)
focal_method.return: FDConnection
focal_method.signature: FDConnection update(final String flowId, final VersionedConnection requestComponentConfig)