protected static String executeSearch(
      BaseAlloyControllerImpl baseAlloyControllerImpl, ActionRequest actionRequest)
      throws Exception {

    if (baseAlloyControllerImpl.permissioned) {
      AlloyPermission.check(
          baseAlloyControllerImpl.themeDisplay, baseAlloyControllerImpl.controllerPath, "index");
    }

    Map<String, Serializable> attributes = null;

    String attributesString = ParamUtil.getString(actionRequest, "attributes");

    if (Validator.isNotNull(attributesString)) {
      attributes = JSONFactoryUtil.looseDeserialize(attributesString, HashMap.class);
    }

    String keywords = ParamUtil.getString(actionRequest, "keywords");

    Sort[] sorts = null;

    String sortsString = ParamUtil.getString(actionRequest, "sorts");

    if (Validator.isNotNull(sortsString)) {
      Map<String, Boolean> sortsMap =
          JSONFactoryUtil.looseDeserialize(sortsString, LinkedHashMap.class);

      sorts = new Sort[sortsMap.size()];

      int i = 0;

      for (Map.Entry<String, Boolean> entry : sortsMap.entrySet()) {
        sorts[i++] = new Sort(entry.getKey(), entry.getValue());
      }
    }

    AlloySearchResult alloySearchResult =
        baseAlloyControllerImpl.search(
            PortalUtil.getHttpServletRequest(actionRequest),
            actionRequest,
            attributes,
            keywords,
            sorts);

    List<BaseModel<?>> baseModels = alloySearchResult.getBaseModels();

    return JSONFactoryUtil.looseSerialize(baseModels);
  }
  protected static String executeDynamicQuery(
      BaseAlloyControllerImpl baseAlloyControllerImpl, ActionRequest actionRequest)
      throws Exception {

    if (baseAlloyControllerImpl.permissioned) {
      AlloyPermission.check(
          baseAlloyControllerImpl.themeDisplay, baseAlloyControllerImpl.controllerPath, "index");
    }

    AlloyServiceInvoker alloyServiceInvoker = baseAlloyControllerImpl.alloyServiceInvoker;

    List<Object> properties =
        JSONFactoryUtil.looseDeserialize(
            ParamUtil.getString(actionRequest, "properties"), ArrayList.class);
    int start = ParamUtil.getInteger(actionRequest, "start", QueryUtil.ALL_POS);
    int end = ParamUtil.getInteger(actionRequest, "end", QueryUtil.ALL_POS);

    List<BaseModel<?>> baseModels =
        alloyServiceInvoker.executeDynamicQuery(properties.toArray(), start, end);

    return JSONFactoryUtil.looseSerialize(baseModels);
  }