Esempio n. 1
0
 private void checkCollumns(ReportParams params) {
   List<String> all =
       Arrays.asList(
           StatsManager.T_SITE,
           StatsManager.T_USER,
           StatsManager.T_EVENT,
           StatsManager.T_TOOL,
           StatsManager.T_RESOURCE,
           StatsManager.T_RESOURCE_ACTION,
           StatsManager.T_DATE,
           StatsManager.T_DATEMONTH,
           StatsManager.T_DATEYEAR,
           StatsManager.T_LASTDATE,
           StatsManager.T_TOTAL,
           StatsManager.T_VISITS,
           StatsManager.T_UNIQUEVISITS,
           StatsManager.T_DURATION);
   List<String> totalsBy = params.getHowTotalsBy();
   for (String c : all) {
     boolean containsColumn = M_rm.isReportColumnAvailable(params, c);
     boolean expected =
         totalsBy == null
             || totalsBy.contains(c)
             || (c.equals(StatsManager.T_TOTAL)
                 && !ReportManager.WHAT_PRESENCES.equals(params.getWhat()))
             || (c.equals(StatsManager.T_DURATION)
                 && ReportManager.WHAT_PRESENCES.equals(params.getWhat()));
     // System.out.println("containsColumn("+c+"): "+containsColumn+" expected: "+expected);
     assertEquals(expected, containsColumn);
   }
 }
  private void generateReportTable(List<Stat> data, ReportParams params) throws SAXException {
    if (data == null || params == null) {
      throw new NullPointerException("Parameter 'data', 'params' must not be null");
    }
    if (handler == null) {
      throw new IllegalStateException("ContentHandler not set");
    }

    final Map<String, ToolInfo> eventIdToolMap = M_ers.getEventIdToolMap();

    boolean showSite = M_rm.isReportColumnAvailable(params, StatsManager.T_SITE);
    boolean showUser = M_rm.isReportColumnAvailable(params, StatsManager.T_USER);
    boolean showTool = M_rm.isReportColumnAvailable(params, StatsManager.T_TOOL);
    boolean showEvent = M_rm.isReportColumnAvailable(params, StatsManager.T_EVENT);
    boolean showResource = M_rm.isReportColumnAvailable(params, StatsManager.T_RESOURCE);
    boolean showResourceAction =
        M_rm.isReportColumnAvailable(params, StatsManager.T_RESOURCE_ACTION);
    boolean showDate =
        M_rm.isReportColumnAvailable(params, StatsManager.T_DATE)
            || M_rm.isReportColumnAvailable(params, StatsManager.T_DATEMONTH)
            || M_rm.isReportColumnAvailable(params, StatsManager.T_DATEYEAR);
    boolean showLastDate = M_rm.isReportColumnAvailable(params, StatsManager.T_LASTDATE);
    boolean showTotal = M_rm.isReportColumnAvailable(params, StatsManager.T_TOTAL);
    boolean showTotalVisits = M_rm.isReportColumnAvailable(params, StatsManager.T_VISITS);
    boolean showTotalUnique = M_rm.isReportColumnAvailable(params, StatsManager.T_UNIQUEVISITS);
    boolean showDuration = M_rm.isReportColumnAvailable(params, StatsManager.T_DURATION);

    Iterator<Stat> i = data.iterator();
    while (i.hasNext()) {
      Stat cs = i.next();
      handler.startElement("datarow");

      // set column display info
      setColumnDisplayInfo(params);

      if (showSite) {
        String siteId = cs.getSiteId();
        String site = null;
        try {
          site = M_ss.getSite(siteId).getTitle();
        } catch (IdUnusedException e) {
          site = msgs.getString("site_unknown");
        }
        handler.element("site", site);
      }
      if (showUser) {
        String userId = null;
        String userName = null;
        String id = cs.getUserId();
        if (id != null) {
          if (("-").equals(id)) {
            userId = "-";
            userName = msgs.getString("user_anonymous");
          } else if (("?").equals(id)) {
            userId = "-";
            userName = msgs.getString("user_anonymous_access");
          } else {
            try {
              User user = M_uds.getUser(id);
              userId = user.getDisplayId();
              userName = M_sm.getUserNameForDisplay(user);
            } catch (UserNotDefinedException e1) {
              userId = id;
              userName = msgs.getString("user_unknown");
            }
          }
        } else {
          userName = msgs.getString("user_unknown");
        }
        handler.element("userid", userId);
        handler.element("username", userName);
      }
      if (showTool) {
        EventStat es = (EventStat) cs;
        String toolId = es.getToolId();
        handler.element("tool", M_ers.getToolName(toolId == null ? "" : toolId));
        handler.element("showToolIcon", "true");
        handler.element("toolicon", "sitestats://" + M_ers.getToolIcon(toolId));
      }
      if (showEvent) {
        EventStat es = (EventStat) cs;
        String eventRef = es.getEventId();
        handler.element("event", M_ers.getEventName(eventRef == null ? "" : eventRef));
        ToolInfo toolInfo = eventIdToolMap.get(eventRef);
        if (toolInfo != null && !showTool) {
          handler.element("showToolEventIcon", "true");
          String toolId = toolInfo.getToolId();
          handler.element("tooleventicon", "sitestats://" + M_ers.getToolIcon(toolId));
        } else {
          handler.element("showToolEventIcon", "false");
        }
      }
      if (showResource) {
        ResourceStat rs = (ResourceStat) cs;
        String resName = M_sm.getResourceName(rs.getResourceRef());
        handler.element("resource", resName == null ? "" : resName);
        handler.element(
            "resourceimg",
            "library://" + M_sm.getResourceImageLibraryRelativePath(rs.getResourceRef()));
      }
      if (showResourceAction) {
        ResourceStat rs = (ResourceStat) cs;
        String resAction = rs.getResourceAction();
        handler.element("action", resAction == null ? "" : msgs.getString("action_" + resAction));
      }
      if (showDate) {
        java.util.Date date = cs.getDate();
        if (M_rm.isReportColumnAvailable(params, StatsManager.T_DATE)) {
          handler.element(
              "date", date == null ? "" : M_ts.newTime(date.getTime()).toStringLocalDate());
        } else if (M_rm.isReportColumnAvailable(params, StatsManager.T_DATEMONTH)) {
          handler.element("date", date == null ? "" : dateMonthFrmt.format(date));
        } else if (M_rm.isReportColumnAvailable(params, StatsManager.T_DATEYEAR)) {
          handler.element("date", date == null ? "" : dateYearFrmt.format(date));
        }
      }
      if (showLastDate) {
        java.util.Date date = cs.getDate();
        handler.element(
            "lastdate", date == null ? "" : M_ts.newTime(date.getTime()).toStringLocalDate());
      }
      if (showTotal) {
        handler.element("total", String.valueOf(cs.getCount()));
      }
      if (showTotalVisits) {
        SiteVisits ss = (SiteVisits) cs;
        handler.element("totalVisits", String.valueOf(ss.getTotalVisits()));
      }
      if (showTotalUnique) {
        SiteVisits ss = (SiteVisits) cs;
        handler.element("totalUnique", String.valueOf(ss.getTotalUnique()));
      }
      if (showDuration) {
        SitePresence ss = (SitePresence) cs;
        double durationInMin =
            ss.getDuration() == 0
                ? 0
                : Util.round((double) ss.getDuration() / 1000 / 60, 1); // in minutes
        handler.element("duration", String.valueOf(durationInMin));
      }

      handler.endElement("datarow");
    }

    // empty report
    if (data.size() == 0) {
      String messageNoData = msgs.getString("no_data");

      handler.startElement("datarow");
      // set column display info
      setColumnDisplayInfo(params);

      if (showSite) {
        handler.element("site", messageNoData);
        messageNoData = "";
      }
      if (showUser) {
        handler.element("userid", messageNoData);
        messageNoData = "";
        handler.element("username", messageNoData);
      }
      if (showTool) {
        handler.element("tool", messageNoData);
        messageNoData = "";
        handler.element("showToolIcon", "");
        handler.element("toolicon", "");
      }
      if (showEvent) {
        handler.element("event", messageNoData);
        messageNoData = "";
        handler.element("showToolEventIcon", "false");
      }
      if (showResource) {
        handler.element("resource", messageNoData);
        messageNoData = "";
        handler.element("resourceimg", "");
      }
      if (showResourceAction) {
        handler.element("action", messageNoData);
        messageNoData = "";
      }
      if (showDate) {
        handler.element("date", messageNoData);
        messageNoData = "";
      }
      if (showLastDate) {
        handler.element("lastdate", messageNoData);
        messageNoData = "";
      }
      if (showTotal) {
        handler.element("total", messageNoData);
        messageNoData = "";
      }
      if (showTotalVisits) {
        handler.element("totalVisits", messageNoData);
        messageNoData = "";
      }
      if (showTotalUnique) {
        handler.element("totalUnique", messageNoData);
        messageNoData = "";
      }
      if (showDuration) {
        handler.element("duration", messageNoData);
        messageNoData = "";
      }
      handler.endElement("datarow");
    }
  }
 private void setColumnDisplayInfo(ReportParams params) throws SAXException {
   if (handler == null) {
     throw new IllegalStateException("ContentHandler not set");
   }
   handler.element("what", params.getWhat());
   handler.element("who", params.getWho());
   handler.element(
       "showSite", String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_SITE)));
   handler.element(
       "showUser", String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_USER)));
   handler.element(
       "showTool", String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_TOOL)));
   handler.element(
       "showEvent", String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_EVENT)));
   handler.element(
       "showResource",
       String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_RESOURCE)));
   handler.element(
       "showResourceAction",
       String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_RESOURCE_ACTION)));
   handler.element(
       "showDate",
       String.valueOf(
           M_rm.isReportColumnAvailable(params, StatsManager.T_DATE)
               || M_rm.isReportColumnAvailable(params, StatsManager.T_DATEMONTH)
               || M_rm.isReportColumnAvailable(params, StatsManager.T_DATEYEAR)));
   handler.element(
       "showLastDate",
       String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_LASTDATE)));
   handler.element(
       "showTotal", String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_TOTAL)));
   handler.element(
       "showTotalVisits",
       String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_VISITS)));
   handler.element(
       "showTotalUnique",
       String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_UNIQUEVISITS)));
   handler.element(
       "showDuration",
       String.valueOf(M_rm.isReportColumnAvailable(params, StatsManager.T_DURATION)));
 }