示例#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;
  }
示例#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);
 }
示例#3
0
  public List<Feedback> loadAllFeedback(User user, SurveyInstance survey)
      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;
  }
示例#4
0
 @Override
 public List<Country> getCountries() {
   Search searchCriteria = new Search(Country.class);
   searchCriteria.addSortAsc("name");
   List<Country> countries = countryDAO.search(searchCriteria);
   return countries;
 }
 @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);
 }
 @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);
 }
示例#7
0
 /**
  * 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;
 }
示例#8
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;
 }
示例#9
0
  /* (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.");
  }
示例#10
0
 @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;
 }
  @Override
  public List<Map<String, Object>> listUltimaLocalizacion(
      Localizacion ejemplo, String[] atributos) {
    if (atributos == null || atributos.length == 0) {
      throw new RuntimeException("La lista de propiedades no puede ser nula o vacía");
    }

    JPASearchProcessor jpaSP =
        new JPASearchProcessor(
            HibernateMetadataUtil.getInstanceForSessionFactory(this.getSessionFactory()));
    Search searchConfig =
        this.getSearchConfig(jpaSP, ejemplo, atributos, false, 0, 1, null, null, false);

    // Acá indicamos que solo traiga la última localización tomada.
    searchConfig.addSort("fechaCreacion", true, true);

    return jpaSP.search(this.getEm(), searchConfig);
  }
示例#12
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());
    }
  }
示例#13
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;
  }
示例#14
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;
  }
示例#15
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;
  }
示例#16
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);
    }
  }
示例#17
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;
  }
示例#18
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;
  }
示例#19
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());
  }
  @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);
  }
 @Override
 public GPProject findByProjectName(String projectName) {
   Search search = new Search();
   search.addFilterEqual("name", projectName);
   return searchUnique(search);
 }
示例#22
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);
 }
  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;
  }
 @Override
 public List<T> searchByRecordStatus(RecordStatus recordStatus) {
   Search search = new Search();
   search.addFilterEqual("recordStatus", recordStatus);
   return search(search);
 }