use of org.orcid.statistics.jpa.entities.StatisticValuesEntity in project ORCID-Source by ORCID.
the class StatsApiServiceBaseImplTest method init.
@Before
public void init() {
// create our mock data
List<StatisticValuesEntity> statsTimelineValues = new ArrayList<StatisticValuesEntity>();
List<StatisticValuesEntity> statsSummaryValues = new ArrayList<StatisticValuesEntity>();
StatisticValuesEntity a = new StatisticValuesEntity();
a.setId(1l);
a.setStatisticName(StatisticsEnum.KEY_LIVE_IDS.value());
a.setStatisticValue(100l);
StatisticKeyEntity akey = new StatisticKeyEntity();
akey.setGenerationDate(new Date(2000, 1, 1));
akey.setId(200L);
a.setKey(akey);
StatisticValuesEntity b = new StatisticValuesEntity();
b.setId(1l);
b.setStatisticName(StatisticsEnum.KEY_LIVE_IDS.value());
b.setStatisticValue(101l);
StatisticKeyEntity bkey = new StatisticKeyEntity();
bkey.setGenerationDate(new Date(1999, 1, 1));
bkey.setId(201L);
b.setKey(bkey);
StatisticValuesEntity c = new StatisticValuesEntity();
c.setId(1l);
c.setStatisticName(StatisticsEnum.KEY_NUMBER_OF_WORKS.value());
c.setStatisticValue(102l);
c.setKey(akey);
statsTimelineValues.add(a);
statsTimelineValues.add(b);
statsSummaryValues.add(a);
statsSummaryValues.add(c);
// mock the methods used
when(statisticsDao.getLatestKey()).thenReturn(akey);
when(statisticsDao.getStatistic(StatisticsEnum.KEY_LIVE_IDS.value())).thenReturn(statsTimelineValues);
when(statisticsDao.getStatistic(200l)).thenReturn(statsSummaryValues);
// mock the methods used
StatisticKeyEntity key200 = new StatisticKeyEntity();
key200.setId(200L);
key200.setGenerationDate(new Date(2000, 1, 1));
StatisticKeyEntity key201 = new StatisticKeyEntity();
key201.setId(201L);
key201.setGenerationDate(new Date(1999, 1, 1));
when(statisticsDao.getKey(200L)).thenReturn(key200);
when(statisticsDao.getKey(201L)).thenReturn(key201);
TargetProxyHelper.injectIntoProxy(statsManagerReadOnly, "statisticsDaoReadOnly", statisticsDao);
// setup security context
ArrayList<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
roles.add(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));
Authentication auth = new AnonymousAuthenticationToken("anonymous", "anonymous", roles);
SecurityContextHolder.getContext().setAuthentication(auth);
}
use of org.orcid.statistics.jpa.entities.StatisticValuesEntity in project ORCID-Source by ORCID.
the class StatisticsManagerReadOnlyImpl method getLiveIds.
/**
* Get the the latest live ids statistics
*
* @param locale
* @return the latest statistics live ids statistics
*/
public String getLiveIds(Locale locale) {
StatisticValuesEntity entity = getLatestStatistics(StatisticsEnum.KEY_LIVE_IDS.value());
long amount = entity == null ? 0 : entity.getStatisticValue();
NumberFormat nf = NumberFormat.getInstance(locale);
return nf.format(amount);
}
use of org.orcid.statistics.jpa.entities.StatisticValuesEntity 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.statistics.jpa.entities.StatisticValuesEntity in project ORCID-Source by ORCID.
the class StatisticsManagerReadOnlyImpl method getLatestStatisticsModel.
/**
* Get the list of the latest statistics as a domain model
*
* @return a list that contains the latest set of statistics
*/
@Override
public StatisticsSummary getLatestStatisticsModel() {
StatisticKeyEntity latestKey = statisticsDaoReadOnly.getLatestKey();
if (latestKey == null)
return null;
List<StatisticValuesEntity> list = statisticsDaoReadOnly.getStatistic(latestKey.getId());
if (list == null || list.size() == 0)
return null;
// convert to model
StatisticsSummary summary = new StatisticsSummary();
Map<String, Long> map = new TreeMap<String, Long>();
for (StatisticValuesEntity entry : list) {
map.put(entry.getStatisticName(), entry.getStatisticValue());
}
summary.setStatistics(map);
summary.setDate(latestKey.getGenerationDate());
return summary;
}
use of org.orcid.statistics.jpa.entities.StatisticValuesEntity in project ORCID-Source by ORCID.
the class StatisticsDaoTest method testStatistics.
@Test
@Transactional
public void testStatistics() {
StatisticKeyEntity key = statisticsDao.createKey();
StatisticKeyEntity latestKey = statisticsDao.createKey();
StatisticValuesEntity os1 = new StatisticValuesEntity(latestKey, "s1", 11);
StatisticValuesEntity os2 = new StatisticValuesEntity(latestKey, "s2", 3);
StatisticValuesEntity os3 = new StatisticValuesEntity(latestKey, "s3", 12);
StatisticValuesEntity os4 = new StatisticValuesEntity(latestKey, "s4", 7);
StatisticValuesEntity os5 = new StatisticValuesEntity(latestKey, "s5", 0);
StatisticValuesEntity os6 = new StatisticValuesEntity(key, "s6", 0);
StatisticValuesEntity os7 = new StatisticValuesEntity(key, "s7", 0);
statisticsDao.persist(os1);
statisticsDao.persist(os2);
statisticsDao.persist(os3);
statisticsDao.persist(os4);
statisticsDao.persist(os5);
statisticsDao.persist(os6);
statisticsDao.persist(os7);
StatisticKeyEntity latestKeyFromDB = statisticsDao.getLatestKey();
assertEquals(latestKey, latestKeyFromDB);
List<StatisticValuesEntity> statistics = statisticsDao.getStatistic(latestKeyFromDB.getId());
assertNotNull(statistics);
assertEquals(statistics.size(), 5);
assertTrue(statistics.contains(os1));
assertTrue(statistics.contains(os2));
assertTrue(statistics.contains(os3));
assertTrue(statistics.contains(os4));
assertTrue(statistics.contains(os5));
assertFalse(statistics.contains(os6));
assertFalse(statistics.contains(os7));
}
Aggregations