示例#1
0
  public int[] getFeedbackCounter(SurveyInstance survey, boolean harmonized, List<String> users) {
    List<Feedback> list = new ArrayList<Feedback>();
    int[] counts = new int[22];
    for (int q = 0; q < counts.length; q++) {
      Search search = new Search();

      search.addFilterEqual("harmonized", harmonized);
      if (!harmonized) {
        search.addFilterEqual("status", "ko");
        search.addFilterIn("user.username", users);
      }
      search.addFilterEqual("survey", survey);
      search.setDistinct(true);
      search.addField("entry.id");
      search.addFilterEqual("entry.question.id", q);

      search.addFilterGreaterThan("timestamp", survey.getStatus().getLastContributorSubmission());
      counts[q] = feedbackDAO.count(search);
    }
    return counts;
  }
  @Override
  public List<Map<String, Object>> listAtributosPorFecha(
      Localizacion ejemplo,
      String[] atributos,
      String[] atributosFecha,
      Timestamp fechaInicio,
      Timestamp fechaFin) {
    JPASearchProcessor jpaSP =
        new JPASearchProcessor(
            HibernateMetadataUtil.getInstanceForSessionFactory(this.getSessionFactory()));

    Search searchConfig = new Search(this.getEntityBeanType());

    if (ejemplo != null) {
      ExampleOptions exampleOptions = new ExampleOptions();
      exampleOptions.setExcludeNulls(true);
      searchConfig.addFilter(jpaSP.getFilterFromExample(ejemplo, exampleOptions));
    }

    for (String atrFec : atributosFecha) {
      if (fechaInicio == null) {
        searchConfig.addFilter(Filter.lessOrEqual(atrFec, fechaFin));
      } else {
        searchConfig.addFilter(
            Filter.and(
                Filter.greaterOrEqual(atrFec, fechaInicio), Filter.lessOrEqual(atrFec, fechaFin)));
      }
    }
    if (atributos != null && atributos.length > 0) {
      for (String a : atributos) {
        searchConfig.addField(a);
      }
      searchConfig.setResultMode(Search.RESULT_MAP);
    }
    searchConfig.addSort("fechaCreacion", false, true);

    return jpaSP.search(getEm(), searchConfig);
  }
  public Search getSearchConfig(
      JPASearchProcessor jpaSP,
      Localizacion ejemplo,
      String[] atributos,
      boolean all,
      Integer primerResultado,
      Integer cantResultados,
      String[] orderByAttrList,
      String[] orderByDirList,
      boolean like) {

    Search searchConfig = new Search(this.getEntityBeanType());

    if (ejemplo != null) {
      ExampleOptions exampleOptions = new ExampleOptions();
      exampleOptions.setExcludeNulls(true);

      if (like) {
        exampleOptions.setIgnoreCase(true);
        exampleOptions.setLikeMode(ExampleOptions.ANYWHERE);
      }

      searchConfig.addFilter(jpaSP.getFilterFromExample(ejemplo, exampleOptions));
    }

    if (!all) {
      searchConfig.setFirstResult(primerResultado);
      searchConfig.setMaxResults(cantResultados);
    }

    if (orderByAttrList != null
        && orderByDirList != null
        && orderByAttrList.length == orderByDirList.length) {
      for (int i = 0; i < orderByAttrList.length; i++) {
        if (orderByDirList[i].equalsIgnoreCase("desc")) {
          searchConfig.addSortDesc(orderByAttrList[i]);
        } else {
          searchConfig.addSortAsc(orderByAttrList[i]);
        }
      }
    } else if ((orderByAttrList != null && orderByDirList == null)
        || (orderByAttrList == null && orderByDirList != null)) {
      throw new RuntimeException(
          "No puede proporcionarse una lista de "
              + "atributos para ordenamiento sin la correspondiente "
              + "lista de direcciones de ordenamiento, o viceversa");
    } else if (orderByAttrList != null
        && orderByDirList != null
        && orderByAttrList.length != orderByDirList.length) {
      throw new RuntimeException(
          "No puede proporcionarse una lista de "
              + "atributos para ordenamiento de tamaño dieferente a la "
              + "lista de direcciones de ordenamiento");
    }

    if (atributos != null && atributos.length > 0) {
      for (String a : atributos) {
        searchConfig.addField(a);
      }
      searchConfig.setResultMode(Search.RESULT_MAP);
    }

    return searchConfig;
  }