protected DataResponse getQueryResponse(
      ExecutionQueryRequest queryRequest, Map<String, String> requestParams, UriInfo uriInfo) {

    RuntimeService runtimeService = BPMNOSGIService.getRumtimeService();
    ExecutionQuery query = runtimeService.createExecutionQuery();

    // Populate query based on request
    if (queryRequest.getId() != null) {
      query.executionId(queryRequest.getId());
      requestParams.put("id", queryRequest.getId());
    }
    if (queryRequest.getProcessInstanceId() != null) {
      query.processInstanceId(queryRequest.getProcessInstanceId());
      requestParams.put("processInstanceId", queryRequest.getProcessInstanceId());
    }
    if (queryRequest.getProcessDefinitionKey() != null) {
      query.processDefinitionKey(queryRequest.getProcessDefinitionKey());
      requestParams.put("processDefinitionKey", queryRequest.getProcessDefinitionKey());
    }
    if (queryRequest.getProcessDefinitionId() != null) {
      query.processDefinitionId(queryRequest.getProcessDefinitionId());
      requestParams.put("processDefinitionId", queryRequest.getProcessDefinitionId());
    }
    if (queryRequest.getProcessBusinessKey() != null) {
      query.processInstanceBusinessKey(queryRequest.getProcessBusinessKey());
      requestParams.put("processInstanceBusinessKey", queryRequest.getProcessBusinessKey());
    }
    if (queryRequest.getActivityId() != null) {
      query.activityId(queryRequest.getActivityId());
      requestParams.put("activityId", queryRequest.getActivityId());
    }
    if (queryRequest.getParentId() != null) {
      query.parentId(queryRequest.getParentId());
      requestParams.put("parentId", queryRequest.getParentId());
    }
    if (queryRequest.getMessageEventSubscriptionName() != null) {
      query.messageEventSubscriptionName(queryRequest.getMessageEventSubscriptionName());
      requestParams.put(
          "messageEventSubscriptionName", queryRequest.getMessageEventSubscriptionName());
    }
    if (queryRequest.getSignalEventSubscriptionName() != null) {
      query.signalEventSubscriptionName(queryRequest.getSignalEventSubscriptionName());
      requestParams.put(
          "signalEventSubscriptionName", queryRequest.getSignalEventSubscriptionName());
    }

    if (queryRequest.getVariables() != null) {
      addVariables(query, queryRequest.getVariables(), false);
    }

    if (queryRequest.getProcessInstanceVariables() != null) {
      addVariables(query, queryRequest.getProcessInstanceVariables(), true);
    }

    if (queryRequest.getTenantId() != null) {
      query.executionTenantId(queryRequest.getTenantId());
      requestParams.put("tenantId", queryRequest.getTenantId());
    }

    if (queryRequest.getTenantIdLike() != null) {
      query.executionTenantIdLike(queryRequest.getTenantIdLike());
      requestParams.put("tenantIdLike", queryRequest.getTenantIdLike());
    }

    if (Boolean.TRUE.equals(queryRequest.getWithoutTenantId())) {
      query.executionWithoutTenantId();
      requestParams.put("withoutTenantId", queryRequest.getWithoutTenantId().toString());
    }

    DataResponse dataResponse =
        new ExecutionPaginateList(new RestResponseFactory(), uriInfo)
            .paginateList(
                requestParams, queryRequest, query, "processInstanceId", allowedSortProperties);
    return dataResponse;
  }
  protected void addVariables(
      ExecutionQuery processInstanceQuery, List<QueryVariable> variables, boolean process) {
    for (QueryVariable variable : variables) {
      if (variable.getVariableOperation() == null) {
        throw new ActivitiIllegalArgumentException(
            "Variable operation is missing for variable: " + variable.getName());
      }
      if (variable.getValue() == null) {
        throw new ActivitiIllegalArgumentException(
            "Variable value is missing for variable: " + variable.getName());
      }

      boolean nameLess = variable.getName() == null;

      Object actualValue = new RestResponseFactory().getVariableValue(variable);

      // A value-only query is only possible using equals-operator
      if (nameLess
          && variable.getVariableOperation() != QueryVariable.QueryVariableOperation.EQUALS) {
        throw new ActivitiIllegalArgumentException(
            "Value-only query (without a variable-name) is only supported when using 'equals' operation.");
      }

      switch (variable.getVariableOperation()) {
        case EQUALS:
          if (nameLess) {
            if (process) {
              processInstanceQuery.processVariableValueEquals(actualValue);
            } else {
              processInstanceQuery.variableValueEquals(actualValue);
            }
          } else {
            if (process) {
              processInstanceQuery.processVariableValueEquals(variable.getName(), actualValue);
            } else {
              processInstanceQuery.variableValueEquals(variable.getName(), actualValue);
            }
          }
          break;

        case EQUALS_IGNORE_CASE:
          if (actualValue instanceof String) {
            if (process) {
              processInstanceQuery.processVariableValueEqualsIgnoreCase(
                  variable.getName(), (String) actualValue);
            } else {
              processInstanceQuery.variableValueEqualsIgnoreCase(
                  variable.getName(), (String) actualValue);
            }
          } else {
            throw new ActivitiIllegalArgumentException(
                "Only string variable values are supported when ignoring casing, but was: "
                    + actualValue.getClass().getName());
          }
          break;

        case NOT_EQUALS:
          if (process) {
            processInstanceQuery.processVariableValueNotEquals(variable.getName(), actualValue);
          } else {
            processInstanceQuery.variableValueNotEquals(variable.getName(), actualValue);
          }
          break;

        case NOT_EQUALS_IGNORE_CASE:
          if (actualValue instanceof String) {
            if (process) {
              processInstanceQuery.processVariableValueNotEqualsIgnoreCase(
                  variable.getName(), (String) actualValue);
            } else {
              processInstanceQuery.variableValueNotEqualsIgnoreCase(
                  variable.getName(), (String) actualValue);
            }
          } else {
            throw new ActivitiIllegalArgumentException(
                "Only string variable values are supported when ignoring casing, but was: "
                    + actualValue.getClass().getName());
          }
          break;
        default:
          throw new ActivitiIllegalArgumentException(
              "Unsupported variable query operation: " + variable.getVariableOperation());
      }
    }
  }