Пример #1
0
  /**
   * Gets globally popular applications (the per-user popular apps are a property on UserDMO)
   *
   * @param viewpoint
   * @param start
   * @return
   * @throws IQException
   */
  @IQMethod(name = "getPopularApplications", type = IQ.Type.get)
  @IQParams({"start=0", "category=null", "distribution=null", "lang=null"})
  public Collection<ApplicationDMO> getPopularApplications(
      UserViewpoint viewpoint, int start, String category, String distribution, String lang)
      throws IQException {
    if (start < 0 || start > 4096) // Arbitrary but reasonable limit
    start = 0;

    Pageable<ApplicationView> pageable = new Pageable<ApplicationView>("applications");
    pageable.setPosition(start);
    pageable.setInitialPerPage(30);

    ApplicationCategory cat = null;
    if (category != null) {
      for (ApplicationCategory c : ApplicationCategory.values()) {
        if (c.getDisplayName().equals(category)) {
          cat = c;
          break;
        }
      }
      if (cat == null) cat = ApplicationCategory.fromRaw(Collections.singleton(category));
    }
    applicationSystem.pagePopularApplications(null, -1, cat, pageable);

    return getResults(pageable);
  }
Пример #2
0
  /**
   * Searches applications globally (not per-user)
   *
   * @param viewpoint
   * @param start
   * @return
   * @throws IQException
   */
  @IQMethod(name = "searchApplications", type = IQ.Type.get)
  @IQParams({"start=0", "search", "distribution=null", "lang=null"})
  public Collection<ApplicationDMO> searchApplications(
      UserViewpoint viewpoint, int start, String search, String distribution, String lang)
      throws IQException {
    if (start < 0 || start > 4096) // Arbitrary but reasonable limit
    start = 0;

    Pageable<ApplicationView> pageable = new Pageable<ApplicationView>("applications");
    pageable.setPosition(start);
    pageable.setInitialPerPage(30);
    applicationSystem.search(search, -1, null, pageable);

    return getResults(pageable);
  }
Пример #3
0
  private List<ApplicationDMO> getResults(Pageable<ApplicationView> pageable) {
    // FIXME this is wasteful; we create ApplicationView then just get the IDs from
    // the views and use them to create an ApplicationDMO, which itself has an ApplicationView
    // internally

    DataModel model = DataService.getModel();
    DMSession session = model.currentSessionRO();

    List<ApplicationDMO> result = new ArrayList<ApplicationDMO>();

    for (ApplicationView appView : pageable.getResults()) {
      result.add(session.findUnchecked(ApplicationDMO.class, appView.getApplication().getId()));
    }

    return result;
  }