AnalyticsReportsDataProvider { public Long getTotalViews(long companyId, String url) throws PortalException { try { long totalViews = GetterUtil.getLong( _asahFaroBackendClient.doGet( companyId, "api/1.0/pages/view-count?canonicalURL=" + HtmlUtil.escapeURL(url))); return Math.max(0, totalViews - _getTodayViews(companyId, url)); } catch (Exception exception) { throw new PortalException("Unable to get total views", exception); } } AnalyticsReportsDataProvider(Http http); HistoricalMetric getHistoricalReadsHistoricalMetric(
			long companyId, TimeRange timeRange, String url); HistoricalMetric getHistoricalViewsHistoricalMetric(
			long companyId, TimeRange timeRange, String url); Long getTotalReads(long companyId, String url); Long getTotalViews(long companyId, String url); List<TrafficSource> getTrafficSources(long companyId, String url); boolean isValidAnalyticsConnection(long companyId);  }
@Test public void testGetTotalViews() throws Exception { LocalDate localDate = LocalDate.now(); AnalyticsReportsDataProvider analyticsReportsDataProvider = new AnalyticsReportsDataProvider( _getHttp( HashMapBuilder.put( "/view-count", "12345" ).put( "/view-counts", JSONUtil.put( "histogram", JSONUtil.put( JSONUtil.put( "key", localDate.format( DateTimeFormatter.ISO_LOCAL_DATE) ).put( "value", 5 )) ).put( "value", 5 ).toJSONString() ).build())); Long totalViews = analyticsReportsDataProvider.getTotalViews( RandomTestUtil.randomLong(), RandomTestUtil.randomString()); Assert.assertEquals(Long.valueOf(12340), totalViews); }
@Test(expected = PortalException.class) public void testGetTotalViewsWithAsahFaroBackendError() throws Exception { AnalyticsReportsDataProvider analyticsReportsDataProvider = new AnalyticsReportsDataProvider(_getHttp(new IOException())); analyticsReportsDataProvider.getTotalViews( RandomTestUtil.randomLong(), RandomTestUtil.randomString()); }