Beispiel #1
0
  public static void createFeedEntry() throws BusinessException {
    StatisticBean global;
    StatisticBean firstGs;
    String overview = "";
    String imageTags = "";
    String hubChart = "";
    String newestHubChart = "";
    try {
      global = PollBusiness.findLatestGlobalStats();
      firstGs = PollBusiness.findFirstGlobalStats();
      if (global != null && firstGs != null) {
        List<StatisticBean> statList =
            StatisticBusiness.findStatisticsForPresentation(
                true,
                true,
                AppConstants.ORDER_CHANNEL,
                false, // order asc?
                0, // start page
                20); // rows
        overview = createOverview(global);
        imageTags = createImageTags(firstGs, global);
        hubChart = createHubChart(statList);
        List<StatisticBean> newestHubList = StatisticBusiness.findNewestHubStatistics(0, 5);
        newestHubChart = createNewestHubChart(newestHubList);
      }
    } catch (OrmException e) {
      throw new BusinessException(e.getMessage(), e);
    }

    FeedEntries fe = new FeedEntries();
    fe.setTitle(
        "Hubzilla network statistics " + AppConstants.FORMAT_DAY_SQL.format(global.getPollTime()));
    fe.setLink(AppConstants.FEED_LINK);
    fe.setDescriptionType("text/html");
    fe.setPublishedDate(global.getPollTime());
    String htmlContent = "<html>" + overview + imageTags + hubChart + newestHubChart + "</html>";
    fe.setDescriptionValue(htmlContent);

    Session ses = HibernateSessionFactory.getSession();
    Transaction trn = ses.beginTransaction();
    try {
      GenericDao.saveGeneric(ses, fe);
      trn.commit();
    } catch (OrmException e) {
      trn.rollback();
      throw new BusinessException(e.getMessage(), e);
    } finally {
      ses.close();
    }
  }
Beispiel #2
0
  public static void deleteOlderFeedEntries() throws BusinessException {
    GregorianCalendar cal = new GregorianCalendar();
    cal.add(Calendar.DAY_OF_WEEK, (-1) * AppConstants.FEED_DAYS_BEFORE_DELETION);
    Date beginDt = cal.getTime();

    Session ses = HibernateSessionFactory.getSession();
    Transaction trn = ses.beginTransaction();
    try {
      new FeedEntriesDao().deleteOlder(ses, beginDt);
      trn.commit();
    } catch (OrmException e) {
      trn.rollback();
      throw new BusinessException(e.getMessage(), e);
    } finally {
      ses.close();
    }
  }