protected DataMapping findDataFlow(
      Interaction interaction, String parameterId, Direction direction)
      throws WebApplicationException {
    DataMapping ret = null;
    ApplicationContext definition = interaction.getDefinition();

    if ((null != definition) && !isEmpty(parameterId)) {
      AccessPoint outParam = findParameterDefinition(interaction, parameterId, direction);
      if (null == outParam) {
        if (InteractionDataFlowUtils.supportDataMappingIds()) {
          ret = definition.getDataMapping(direction, parameterId);
        }
      } else {
        List<DataMapping> allDataMappings = definition.getAllDataMappings();
        for (DataMapping dataMapping : allDataMappings) {
          if (outParam.equals(dataMapping.getApplicationAccessPoint())) {
            ret = dataMapping;
            break;
          }
        }
      }
    }

    if (ret == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }

    return ret;
  }