@Override
 public List<T> searchByPropertyEqual(String property, Object value, RecordStatus recordStatus) {
   Search search = new Search();
   search.addFilterEqual(property, value);
   search.addFilterEqual("recordStatus", recordStatus);
   return search(search);
 }
Example #2
0
  /**
   * Load All feedbacks related to the Latest review / ReviewEditing. The feedback is loaded only if
   * his timestamp is > to the LastContributorSubmission field stored in the survey status
   *
   * @param user
   * @param survey
   * @param question
   * @param harmonized
   * @return
   * @throws BadRequestServiceEx
   */
  public List<Feedback> loadFeedback(User user, SurveyInstance survey, Long question)
      throws BadRequestServiceEx {

    List<Feedback> list = new ArrayList<Feedback>();
    List<Feedback> harmonizedList = new ArrayList<Feedback>();
    try {

      Search search = new Search();
      if (user != null) {
        search.addFilterEqual("user", user);
      }
      search.addFilterEqual("harmonized", false);
      search.addFilterEqual("survey", survey);
      search.addFilterEqual("entry.question.id", question);

      // search.addFilterGreaterThan("timestamp", survey.getStatus().getLastSurveyReview());
      search.addFilterGreaterThan("timestamp", survey.getStatus().getLastPendingFixSubmit());

      list = feedbackDAO.search(search);
    } catch (Exception e) {

      LOGGER.error(e.getLocalizedMessage());
      throw new BadRequestServiceEx(e.getLocalizedMessage());
    }
    list.addAll(harmonizedList);
    return list;
  }
Example #3
0
  /**
   * Load the feedbacks that are saved between the previous editor submission and the latest in
   * order to allow the reviewer to see their previous comment for each entry.
   *
   * @param user
   * @param survey
   * @param question
   * @param harmonized
   * @return
   * @throws BadRequestServiceEx
   */
  public List<Feedback> loadPreviousReviewFeedbacks(User user, SurveyInstance survey, Long question)
      throws BadRequestServiceEx {

    List<Feedback> list = new ArrayList<Feedback>();
    try {

      Search search = new Search();
      search.addFilterEqual("user", user);
      search.addFilterEqual("survey", survey);
      search.addFilterEqual("entry.question.id", question);
      Long prev =
          (survey.getStatus().getPreviousPendingFix() != null)
              ? survey.getStatus().getPreviousPendingFix()
              : 0;

      // Long last = (survey.getStatus().getLastSurveyReview() !=
      // null)?survey.getStatus().getLastSurveyReview():0;
      Long last =
          (survey.getStatus().getLastPendingFixSubmit() != null)
              ? survey.getStatus().getLastPendingFixSubmit()
              : 0;

      search.addFilterGreaterThan("timestamp", prev);
      search.addFilterLessThan("timestamp", last);
      list = feedbackDAO.search(search);
    } catch (Exception e) {

      LOGGER.error(e.getLocalizedMessage());
      throw new BadRequestServiceEx(e.getLocalizedMessage());
    }
    return list;
  }
 @SuppressWarnings("unchecked")
 @Override
 public T searchUniqueByPropertyEqual(String property, Object value, RecordStatus recordStatus) {
   Search search = new Search();
   search.addFilterEqual(property, value);
   search.addFilterEqual("recordStatus", recordStatus);
   return (T) searchUnique(search);
 }
  /* (non-Javadoc)
   * @see it.geosolutions.fra2015.services.SurveyService#updateValues(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.String)
   */
  @Override
  public Entry updateValues(String iso3, String entryId, Integer row, Integer col, String value)
      throws BadRequestServiceEx, NotFoundServiceEx {

    Entry entry = entryDAO.findByName(entryId);
    if (entry != null) {
      Search searchCriteria = new Search(EntryItem.class);
      searchCriteria.addFilterEqual("rowNumber", row);
      searchCriteria.addFilterEqual("columnNumber", col);
      searchCriteria.addFilterEqual("entry.id", entry.getId());
      List<EntryItem> items = entryItemDAO.search(searchCriteria);
      EntryItem item = null;
      if (items.isEmpty()) {
        // create a new entry item for this entry
        item = new EntryItem();
        item.setType("String"); // TODO
        item.setColumnNumber(col);
        item.setRowNumber(row);
        item.setEntry(entry);

        entry.addEntryItem(item);

        entryItemDAO.persist(item);
        entryDAO.merge(entry);
      } else {
        item = items.get(0);
      }

      // find a country with the given name
      Country country = findCountryByISO3(iso3);
      if (country == null) {
        throw new BadRequestServiceEx("Country with code " + iso3 + " does not exist.");
      }

      // retrieve previous value if it is an update
      ValueDAO valueDAO = daoMap.get(item.getType());
      Value dbValue = valueDAO.read(item.getId(), country);
      if (dbValue == null) {
        // create a new value
        ValueDTO v = new ValueDTO();
        v.setEntryItem(item);
        v.setCountry(country);
        // set value
        v.setContent(value);
        valueDAO.persist(v);
      } else {
        // update values
        dbValue.setContent(value);
        valueDAO.merge(dbValue);
      }

      return entry;
    }
    throw new BadRequestServiceEx("Entry " + entryId + " not found.");
  }
 @Override
 public QuestionRevision findQuestionRevision(Country country, Question question) {
   Search searchCriteria = new Search(QuestionRevision.class);
   searchCriteria.addFilterEqual("country", country);
   searchCriteria.addFilterEqual("question", question);
   List<QuestionRevision> qr = questionRevisionDAO.search(searchCriteria);
   if (qr.size() > 0) {
     return qr.get(0);
   }
   return null;
 }
Example #7
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());
  }
Example #8
0
  /**
   * Counts feedback for a survey
   *
   * @param survey
   * @param harmonized
   * @return
   */
  public int[] getFeedbackCounter(SurveyInstance survey, boolean harmonized) {
    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.addFilterEqual("survey", survey);
      search.addFilterEqual("entry.question.id", q);

      search.addFilterGreaterThan("timestamp", survey.getStatus().getLastContributorSubmission());
      counts[q] = feedbackDAO.count(search);
    }
    return counts;
  }
 /**
  * retuns a country with the given name, null otherwise
  *
  * @param countryName
  * @return
  */
 private Country findCountryByName(String name) {
   Search searchCriteria = new Search(Country.class);
   searchCriteria.addFilterEqual("name", name);
   List<Country> countries = countryDAO.search(searchCriteria);
   if (countries.size() > 0) {
     return countries.get(0);
   }
   return null;
 }
Example #10
0
 @Override
 public Country findCountryByISO3(String iso3) {
   Search searchCriteria = new Search(Country.class);
   searchCriteria.addFilterEqual("iso3", iso3);
   List<Country> countries = countryDAO.search(searchCriteria);
   if (countries.size() > 0) {
     return countries.get(0);
   }
   return null;
 }
Example #11
0
  public List<Feedback> loadAllHarmonizedfeedbacks(SurveyInstance survey)
      throws BadRequestServiceEx {

    List<Feedback> list = new ArrayList<Feedback>();
    List<Feedback> harmonizedList = new ArrayList<Feedback>();
    try {

      Search search = new Search();
      search.addFilterEqual("harmonized", true);
      search.addFilterEqual("survey", survey);
      // search.addFilterEqual("entry.question.id", question);
      search.addFilterGreaterThan("timestamp", survey.getStatus().getLastContributorSubmission());
      list = feedbackDAO.search(search);
    } catch (Exception e) {

      LOGGER.error(e.getLocalizedMessage());
      throw new BadRequestServiceEx(e.getLocalizedMessage());
    }
    list.addAll(harmonizedList);
    return list;
  }
Example #12
0
  /* (non-Javadoc)
   * @see it.geosolutions.fra2015.services.SurveyService#removeValues(java.lang.String, java.lang.String, java.lang.Integer, java.lang.Integer, java.lang.String)
   */
  @Override
  public boolean removeValues(String iso3, String entryId, Integer row, Integer col, String value)
      throws BadRequestServiceEx, NotFoundServiceEx {

    Entry entry = entryDAO.findByName(entryId);

    if (entry == null) {
      throw new NotFoundServiceEx("Entry " + entryId + " not found.");
    }

    Search searchCriteria = new Search(EntryItem.class);
    searchCriteria.addFilterEqual("rowNumber", row);
    searchCriteria.addFilterEqual("columnNumber", col);
    searchCriteria.addFilterEqual("entry.id", entry.getId());
    List<EntryItem> items = entryItemDAO.search(searchCriteria);
    EntryItem item = null;
    if (items.isEmpty()) {
      return false;
    } else {
      item = items.get(0);
    }

    // find a country with the given name
    Country country = findCountryByISO3(iso3);
    if (country == null) {
      throw new NotFoundServiceEx("Country with code " + iso3 + " does not exist.");
    }

    // retrieve previous value if it is an update
    ValueDAO valueDAO = daoMap.get(item.getType());
    Value dbValue = valueDAO.read(item.getId(), country);
    if (dbValue == null) {
      return false;
    } else {
      valueDAO.remove(dbValue.getId());
    }

    return true;
  }
Example #13
0
  /**
   * Count all the feedbacks associated to an User
   *
   * @param user
   * @param survey
   * @return
   * @throws BadRequestServiceEx
   */
  public int countFeedback(User user) throws BadRequestServiceEx {

    try {

      Search search = new Search();
      if (user == null) {
        throw new IllegalArgumentException(
            "The User be NOT NULL in order to count their feedbacks...");
      }
      search.addFilterEqual("user", user);

      return feedbackDAO.count(search);
    } catch (Exception e) {

      LOGGER.error(e.getLocalizedMessage());
      throw new BadRequestServiceEx(e.getLocalizedMessage());
    }
  }
Example #14
0
  /**
   * <b>Regra(s) de negócio:</b> Consulta entidade de acordo com os parametros, caso ela não exista,
   * salva o registro
   *
   * @author gilberto.nery
   * @date 09/09/2015
   * @return PersistentObject - Entidade que foi salva ou entidade que estava cadastrada
   */
  @Override
  public PersistentObject saveIfNotExist(PersistentObject entity) {

    Pagina pagina = (Pagina) entity;

    Search search = new Search();

    search.addFilterEqual("pagina", pagina.getPagina());

    search.setMaxResults(1);

    PersistentObject obj = searchUnique(search);

    if (UtilObjeto.isReferencia(obj)) {

      return obj;

    } else {

      return this.save(entity);
    }
  }
 @Override
 public GPProject findByProjectName(String projectName) {
   Search search = new Search();
   search.addFilterEqual("name", projectName);
   return searchUnique(search);
 }
 @Override
 public List<T> searchByRecordStatus(RecordStatus recordStatus) {
   Search search = new Search();
   search.addFilterEqual("recordStatus", recordStatus);
   return search(search);
 }
Example #17
0
 /* (non-Javadoc)
  * @see it.geosolutions.fra2015.services.SurveyService#searchCountry(java.lang.String)
  */
 @Override
 public Country searchCountry(String iso3) {
   Search searchCriteria = new Search(Country.class);
   searchCriteria.addFilterEqual("iso3", iso3);
   return countryDAO.search(searchCriteria).get(0);
 }