Search in sources :

Example 1 with StatisticsTimeline

use of org.orcid.jaxb.model.statistics.StatisticsTimeline in project ORCID-Source by ORCID.

the class StatsApiServiceBaseImplTest method testViewStatsTimeline.

@Test
public void testViewStatsTimeline() {
    assertNotNull(serviceDelegator.getStatsSummary());
    assertEquals(200, serviceDelegator.getStatsSummary().getStatus());
    serviceDelegator.updateToLatestStatisticsTimeline();
    Response r = serviceDelegator.getStatsTimeline(StatisticsEnum.KEY_LIVE_IDS);
    assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
    StatisticsTimeline s = (StatisticsTimeline) r.getEntity();
    assertNotNull(s);
    assertNotNull(s.getStatisticName());
    assertEquals(s.getStatisticName(), StatisticsEnum.KEY_LIVE_IDS.value());
    assertEquals(s.getTimeline().size(), 2);
    Long time1 = new Date(1999, 1, 1).getTime();
    assertEquals((long) s.getTimeline().get(time1), 101l);
    Long time2 = new Date(2000, 1, 1).getTime();
    assertEquals((long) s.getTimeline().get(time2), 100l);
}
Also used : Response(javax.ws.rs.core.Response) StatisticsTimeline(org.orcid.jaxb.model.statistics.StatisticsTimeline) Date(java.util.Date) Test(org.junit.Test)

Example 2 with StatisticsTimeline

use of org.orcid.jaxb.model.statistics.StatisticsTimeline in project ORCID-Source by ORCID.

the class StatisticsTimelineListMBWriter method writeTo.

@Override
public void writeTo(StatsTimelineList data, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    StringBuffer buf = new StringBuffer();
    SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
    buf.append("type");
    buf.append(',');
    buf.append("date");
    buf.append(',');
    buf.append("stat");
    buf.append('\n');
    for (StatisticsTimeline line : data.getTimelines()) {
        for (Long l : line.getTimeline().keySet()) {
            buf.append(line.getStatisticName());
            buf.append(',');
            Date d = new Date(l);
            buf.append(format.format((d)));
            buf.append(',');
            buf.append(line.getTimeline().get(d));
            buf.append('\n');
        }
    }
    final PrintStream printStream = new PrintStream(entityStream);
    printStream.print(buf.toString());
}
Also used : PrintStream(java.io.PrintStream) StatisticsTimeline(org.orcid.jaxb.model.statistics.StatisticsTimeline) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with StatisticsTimeline

use of org.orcid.jaxb.model.statistics.StatisticsTimeline in project ORCID-Source by ORCID.

the class StatsApiServiceDelegatorImpl method getAllStatsTimelines.

@Override
@AccessControl(requiredScope = ScopePathType.READ_PUBLIC, enableAnonymousAccess = true)
public Response getAllStatsTimelines() {
    StatisticsSummary summary = statisticsCacheManager.retrieve();
    if (summary == null)
        return Response.status(Status.NOT_FOUND).build();
    StatsTimelineList statsTimelines = new StatsTimelineList();
    for (String key : summary.getStatistics().keySet()) {
        StatisticsTimeline timeline = statisticsCacheManager.getStatisticsTimelineModel(StatisticsEnum.fromString(key));
        if (timeline != null)
            statsTimelines.getTimelines().add(timeline);
    }
    return Response.ok(statsTimelines).build();
}
Also used : StatsTimelineList(org.orcid.api.common.writer.stats.StatsTimelineList) StatisticsSummary(org.orcid.jaxb.model.statistics.StatisticsSummary) StatisticsTimeline(org.orcid.jaxb.model.statistics.StatisticsTimeline) AccessControl(org.orcid.core.security.visibility.aop.AccessControl)

Example 4 with StatisticsTimeline

use of org.orcid.jaxb.model.statistics.StatisticsTimeline in project ORCID-Source by ORCID.

the class StatisticsManagerReadOnlyImpl method getStatisticsTimelineModel.

/**
     * Get all entries with a given name;
     * 
     * @param statisticName
     * @return all statistics values for the statistics name parameter
     */
public StatisticsTimeline getStatisticsTimelineModel(StatisticsEnum statisticName) {
    List<StatisticValuesEntity> list = statisticsDaoReadOnly.getStatistic(statisticName.value());
    if (list == null)
        return null;
    // convert to model
    StatisticsTimeline timeline = new StatisticsTimeline();
    timeline.setStatisticName(statisticName.value());
    Map<Long, Long> map = new TreeMap<Long, Long>();
    Map<Long, Date> generationDateMap = new HashMap<Long, Date>();
    for (StatisticValuesEntity entry : list) {
        if (!generationDateMap.containsKey(entry.getKey().getId())) {
            StatisticKeyEntity key = statisticsDaoReadOnly.getKey(entry.getKey().getId());
            Long time = key.getGenerationDate().getTime();
            map.put(time, entry.getStatisticValue());
            generationDateMap.put(key.getId(), key.getGenerationDate());
        } else {
            Date date = generationDateMap.get(entry.getKey().getId());
            map.put(date.getTime(), entry.getStatisticValue());
        }
    }
    timeline.setTimeline(map);
    return timeline;
}
Also used : StatisticValuesEntity(org.orcid.statistics.jpa.entities.StatisticValuesEntity) HashMap(java.util.HashMap) StatisticKeyEntity(org.orcid.statistics.jpa.entities.StatisticKeyEntity) StatisticsTimeline(org.orcid.jaxb.model.statistics.StatisticsTimeline) TreeMap(java.util.TreeMap) Date(java.util.Date)

Example 5 with StatisticsTimeline

use of org.orcid.jaxb.model.statistics.StatisticsTimeline in project ORCID-Source by ORCID.

the class StatisticsCacheManagerImpl method setLatestStatisticsTimeline.

@Override
public synchronized void setLatestStatisticsTimeline() {
    LOG.info("Getting the latest statistics timeline map");
    Map<StatisticsEnum, StatisticsTimeline> latestStatisticsTimelineMap = new HashMap<StatisticsEnum, StatisticsTimeline>();
    for (StatisticsEnum type : StatisticsEnum.values()) {
        StatisticsTimeline statisticsTimeline = statisticsManagerReadOnly.getStatisticsTimelineModel(type);
        latestStatisticsTimelineMap.put(type, statisticsTimeline);
    }
    if (statisticsCache.get(CACHE_TIMELINE_KEY) == null) {
        statisticsCache.put(new Element(CACHE_TIMELINE_KEY, latestStatisticsTimelineMap));
    } else {
        statisticsCache.replace(new Element(CACHE_TIMELINE_KEY, latestStatisticsTimelineMap));
    }
}
Also used : HashMap(java.util.HashMap) StatisticsEnum(org.orcid.core.utils.statistics.StatisticsEnum) Element(net.sf.ehcache.Element) StatisticsTimeline(org.orcid.jaxb.model.statistics.StatisticsTimeline)

Aggregations

StatisticsTimeline (org.orcid.jaxb.model.statistics.StatisticsTimeline)5 Date (java.util.Date)3 HashMap (java.util.HashMap)2 PrintStream (java.io.PrintStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 TreeMap (java.util.TreeMap)1 Response (javax.ws.rs.core.Response)1 Element (net.sf.ehcache.Element)1 Test (org.junit.Test)1 StatsTimelineList (org.orcid.api.common.writer.stats.StatsTimelineList)1 AccessControl (org.orcid.core.security.visibility.aop.AccessControl)1 StatisticsEnum (org.orcid.core.utils.statistics.StatisticsEnum)1 StatisticsSummary (org.orcid.jaxb.model.statistics.StatisticsSummary)1 StatisticKeyEntity (org.orcid.statistics.jpa.entities.StatisticKeyEntity)1 StatisticValuesEntity (org.orcid.statistics.jpa.entities.StatisticValuesEntity)1