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);
}
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());
}
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();
}
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;
}
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));
}
}
Aggregations