Esempio n. 1
0
  @Override
  public List<Value> getEntryListByVariableName(List<String> names, String iso3)
      throws BadRequestServiceEx {

    Search searchCriteria = new Search(EntryItem.class);

    Country country = findCountryByISO3(iso3);
    if (country == null) {
      throw new BadRequestServiceEx("Country with code " + iso3 + " does not exist.");
    }
    searchCriteria.addFilterIn("rowName", names);
    List<Value> results = new ArrayList<Value>();
    List<EntryItem> items = entryItemDAO.search(searchCriteria);
    for (EntryItem item : items) {
      String type = item.getType();
      ValueDAO valueDAO = daoMap.get(type);
      if (valueDAO != null) {
        Value value = valueDAO.read(item.getId(), country);
        if (value != null) {

          results.add(value);
        }
      }
    }
    return results;
  }
Esempio n. 2
0
 @Override
 public List<Question> getQuestions(Integer[] questionNumbers) {
   Search searchCriteria = new Search();
   searchCriteria.addFilterIn("id", Arrays.asList(questionNumbers));
   searchCriteria.addSort("id", false);
   return questionDAO.search(searchCriteria);
 }
Esempio n. 3
0
  @Override
  public List<Value> getEntryItemsListByFieldValues(
      String field,
      List<String> fieldValues,
      List<String> rowNamesValue,
      String iso3,
      boolean emptyValues)
      throws BadRequestServiceEx {

    Search searchCriteria = new Search(EntryItem.class);

    Country country = findCountryByISO3(iso3);
    if (country == null) {
      throw new BadRequestServiceEx("Country with code " + iso3 + " does not exist.");
    }
    searchCriteria.addFilterIn(field, fieldValues);
    if (rowNamesValue != null && !rowNamesValue.isEmpty()) {
      searchCriteria.addFilterIn("rowName", rowNamesValue);
    }
    List<Value> results = new ArrayList<Value>();
    List<EntryItem> items = entryItemDAO.search(searchCriteria);
    for (EntryItem item : items) {
      String type = item.getType();
      ValueDAO valueDAO = daoMap.get(type);
      if (valueDAO != null) {
        Value value = valueDAO.read(item.getId(), country);
        if (value == null && emptyValues) {

          Value val = new NumberValue();
          val.setEntryItem(item);
          results.add(val);
        } else if (value != null && !emptyValues) {
          results.add(value);
        }
      }
    }
    return results;
  }
Esempio n. 4
0
  public boolean checkQuestionFeedbackStatus(User user, SurveyInstance survey, Long question) {

    Collection<Entry> entries = catalog.getEntriesForQuestion(question);

    Search search = new Search();
    search.addFilterEqual("user", user);
    search.addFilterEqual("harmonized", false);
    search.addFilterEqual("survey", survey);
    search.addFilterEqual("entry.question.id", question);
    search.addFilterIn("status", "ok", "ko");
    search.addFilterGreaterThan("timestamp", survey.getStatus().getLastContributorSubmission());
    List<Feedback> list = feedbackDAO.search(search);
    return (list.size() == entries.size());
  }
Esempio n. 5
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;
  }