Commit f1e92b5c authored by Matija Obreza's avatar Matija Obreza
Browse files

Statistics services

parent 86ad0d17
......@@ -39,6 +39,9 @@ public interface CountryRepository extends JpaRepository<Country, Long> {
@Query("from Country c where c.current=false")
List<Country> findInactive();
@Query("select count(c) from Country c where c.current = ?1")
long countByCurrent(boolean current);
List<Country> findByCurrent(boolean current);
Page<Country> findByCurrent(boolean current, Pageable pageable);
......
......@@ -42,6 +42,9 @@ public interface FaoInstituteRepository extends JpaRepository<FaoInstitute, Long
@Query("from FaoInstitute fi where fi.accessionCount > 0")
Page<FaoInstitute> listAllActive(Pageable pageable);
@Query("select count(fi) from FaoInstitute fi where fi.accessionCount > 0")
long countActive();
@Query("from FaoInstitute fi where fi.code in ( ?1 )")
List<FaoInstitute> findAllByCodes(Collection<String> wiewsCodes);
......
......@@ -161,4 +161,6 @@ public interface GenesysService {
void addAccessions(List<Accession> accessions);
long countAll();
}
......@@ -113,4 +113,6 @@ public interface GeoService {
ITPGRFAStatus getITPGRFAStatus(Country country);
long countActive();
}
......@@ -55,4 +55,6 @@ public interface InstituteService {
void updateSettings(FaoInstitute faoInstitute, Map<String, String> settings);
long countActive();
}
......@@ -48,5 +48,4 @@ public interface OrganizationService {
boolean addOrganizationInstitutes(Organization organization, List<String> instituteList);
boolean setOrganizationInstitutes(Organization organization, List<String> instituteList);
}
/**
* Copyright 2014 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.service;
public interface StatisticsService {
long numberOfCountries();
long numberOfInstitutes();
long numberOfAccessions();
}
......@@ -37,6 +37,8 @@ import org.genesys2.server.persistence.domain.ClassPKRepository;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.HtmlSanitizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
......@@ -71,6 +73,7 @@ public class ContentServiceImpl implements ContentService {
}
@Override
@Cacheable(value = "contentcache", key = "#root.methodName")
public List<ActivityPost> lastNews() {
PageRequest page = new PageRequest(0, 10, Direction.DESC, "postDate");
return postRepository.findAll(page).getContent();
......@@ -83,11 +86,13 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "contentcache", allEntries = true)
public void save(Iterable<Article> articles) {
articleRepository.save(articles);
}
@Override
@Cacheable(value = "contentcache", key = "'globalarticle-' + #slug + '-' + #locale.language")
public Article getGlobalArticle(String slug, Locale locale, boolean useDefault) {
return getArticle(Article.class, null, slug, locale, useDefault);
}
......@@ -96,16 +101,19 @@ public class ContentServiceImpl implements ContentService {
* Get article, use default locale if required
*/
@Override
@Cacheable(value = "contentcache", key = "'globalarticle-' + #slug + '-' + #locale.language")
public Article getGlobalArticle(String slug, Locale locale) {
return getGlobalArticle(slug, locale, true);
}
@Override
@Cacheable(value = "contentcache", key = "'article-' + #entity.class.name + '-' + #entity.id + '-' + #slug + '-' + #locale.language")
public Article getArticle(EntityId entity, String slug, Locale locale) {
return getArticle(entity.getClass(), entity.getId(), slug, locale, true);
}
@Override
@Cacheable(value = "contentcache", key = "'article-' + #clazz.name + '-' + #id + '-' + #slug + '-' + #locale.language")
public Article getArticle(Class<?> clazz, Long id, String slug, Locale locale, boolean useDefault) {
Article article = articleRepository.findByClassPkAndTargetIdAndSlugAndLang(getClassPk(clazz), id, slug, locale.getLanguage());
if (article == null && useDefault && !locale.getLanguage().equals(getDefaultLocale().getLanguage())) {
......@@ -117,6 +125,7 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "contentcache", allEntries = true)
public Article updateArticle(long id, String slug, String title, String body) {
Article article = articleRepository.findOne(id);
......@@ -138,6 +147,7 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "contentcache", allEntries = true)
public Article createGlobalArticle(String slug, Locale locale, String title, String body) {
Article article = getGlobalArticle(slug, locale, false);
if (article != null) {
......@@ -167,6 +177,7 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "contentcache", allEntries = true)
public Article updateArticle(EntityId entity, String slug, String title, String body, Locale locale) {
// return
// articleRepository.findByClassPkAndTargetIdAndSlugAndLang(getClassPk(clazz),
......@@ -177,6 +188,7 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "contentcache", allEntries = true)
public Article updateArticle(Class<?> clazz, Long id, String slug, String title, String body, Locale locale) {
Article article = getArticle(clazz, id, slug, locale, false);
if (article == null || !article.getLang().equals(locale.getLanguage())) {
......@@ -221,6 +233,7 @@ public class ContentServiceImpl implements ContentService {
}
@Override
@Cacheable(value = "contentcache", key = "'activityPost-' + #id")
public ActivityPost getActivityPost(long id) {
return postRepository.findOne(id);
}
......@@ -231,6 +244,7 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "contentcache", allEntries = true)
public ActivityPost createActivityPost(String title, String body) {
ActivityPost newPost = new ActivityPost();
newPost.setPostDate(GregorianCalendar.getInstance());
......@@ -240,6 +254,7 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "contentcache", allEntries = true)
public ActivityPost updateActivityPost(long id, String title, String body) {
ActivityPost post = postRepository.findOne(id);
return updatePostData(post, title, body);
......@@ -255,6 +270,7 @@ public class ContentServiceImpl implements ContentService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "contentcache", allEntries = true)
public void deleteActivityPost(long id) {
postRepository.delete(id);
}
......
......@@ -164,6 +164,11 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Autowired
private AccessionAliasRepository accessionAliasRepository;
@Override
public long countAll() {
return accessionRepository.count();
}
@Override
public long countByInstitute(FaoInstitute institute) {
return accessionRepository.countByInstitute(institute);
......
......@@ -86,6 +86,11 @@ public class GeoServiceImpl implements GeoService {
Country.sort(countries, locale);
return countries;
}
@Override
public long countActive() {
return countryRepository.countByCurrent(true);
}
@Override
public List<Country> listITPGRFA(Locale locale) {
......
......@@ -84,6 +84,11 @@ public class InstituteServiceImpl implements InstituteService {
return instituteRepository.listAllActive(pageRequest);
}
@Override
public long countActive() {
return instituteRepository.countActive();
}
@Override
public FaoInstitute getInstitute(String wiewsCode) {
FaoInstitute inst = instituteRepository.findByCode(wiewsCode);
......
package org.genesys2.server.service.impl;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class StatisticsServiceImpl implements StatisticsService {
@Autowired
private GeoService geoService;
@Autowired
private InstituteService instituteService;
@Autowired
private GenesysService genesysService;
@Override
@Cacheable(value="statistics", key="'stats.' + #root.methodName")
public long numberOfCountries() {
return geoService.countActive();
}
@Override
@Cacheable(value="statistics", key="'stats.' + #root.methodName")
public long numberOfInstitutes() {
return instituteService.countActive();
}
@Override
@Cacheable(value="statistics", key="'stats.' + #root.methodName")
public long numberOfAccessions() {
return genesysService.countAll();
}
}
......@@ -28,10 +28,13 @@ import org.genesys2.server.security.lockout.AccountLockoutManager;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.EMailVerificationService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.StatisticsService;
import org.genesys2.server.service.UserService;
import org.genesys2.util.ReCaptchaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
......@@ -54,9 +57,6 @@ public class HtmlController extends BaseController {
@Autowired
private CropService cropService;
@Autowired
private ContentService activityPostService;
@Autowired
private Validator validator;
......@@ -75,6 +75,12 @@ public class HtmlController extends BaseController {
@Value("${captcha.publicKey}")
private String captchaPublicKey;
@Autowired
private StatisticsService statisticsService;
@Autowired
private OrganizationService organizationService;
@RequestMapping("/")
public String index() {
return "redirect:/welcome";
......@@ -86,8 +92,15 @@ public class HtmlController extends BaseController {
model.addAttribute("permissionsList", permissionsList);
// FIXME get user locale!
model.addAttribute("cropList", cropService.list(getLocale()));
model.addAttribute("lastNews", activityPostService.lastNews());
model.addAttribute("lastNews", contentService.lastNews());
model.addAttribute("welcomeBlurp", contentService.getGlobalArticle("welcome", getLocale()));
model.addAttribute("numberOfCountries", statisticsService.numberOfCountries());
model.addAttribute("numberOfInstitutes", statisticsService.numberOfInstitutes());
model.addAttribute("numberOfAccessions", statisticsService.numberOfAccessions());
model.addAttribute("organizations", organizationService.list(new PageRequest(0, 5)));
return "/index";
}
......
......@@ -458,4 +458,8 @@ team.user.enter.email=Enter user email
user.not.found=User not found
team.profile.update.title=Update team information
autocomplete.genus=Find Genus...
\ No newline at end of file
autocomplete.genus=Find Genus...
stats.number-of-countries={0} Countries
stats.number-of-institutes={0} Institutes
stats.number-of-accessions={0} Accessions
......@@ -21,9 +21,8 @@
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1800" timeToLiveSeconds="3600" overflowToDisk="false" />
<!--ACL in-memory cache -->
<cache name="sparsedata" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1800" timeToLiveSeconds="3600" overflowToDisk="false" />
<cache name="sparseentry" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1800" timeToLiveSeconds="3600" overflowToDisk="false" />
<cache name="statistics" maxElementsInMemory="100" eternal="false" timeToIdleSeconds="60" timeToLiveSeconds="120" overflowToDisk="false" />
<cache name="contentcache" maxElementsInMemory="1000" eternal="false" timeToIdleSeconds="60" timeToLiveSeconds="120" overflowToDisk="false" />
<!--CACHEABLE CACHES -->
......
......@@ -21,7 +21,7 @@ db.driverClassName=com.mysql.jdbc.Driver
db.dialect=org.hibernate.dialect.MySQL5Dialect
db.username=root
db.password=
db.showSql=false
db.showSql=true
db.hbm2ddl=do-nothing
c3p0.acquireIncrement=1
......
......@@ -78,9 +78,9 @@
<div class="stats-map">
<div class="all-stats">
<div class="one-stat">326 Countries</div>
<div class="one-stat">13.432 Institutes</div>
<div class="one-stat">2.544.876 Accessions</div>
<div class="one-stat"><a href="<c:url value="/geo/" />"><spring:message code="stats.number-of-countries" arguments="${numberOfCountries}" /></a></div>
<div class="one-stat"><a href="<c:url value="/wiews/active" />"><spring:message code="stats.number-of-institutes" arguments="${numberOfInstitutes}" /></a></div>
<div class="one-stat"><a href="<c:url value="/explore" />"><spring:message code="stats.number-of-accessions" arguments="${numberOfAccessions}" /></a></div>
</div>
</div>
......
......@@ -954,6 +954,10 @@ html[dir="rtl"] #stats .stats-map .all-stats {
padding:1px 5px;
}
#stats .one-stat a {
color: White;
}
html[dir="rtl"] #stats .stats-map .one-stat {
float:right;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment