Commit 102a6617 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '27-update-statistics' into 'master'

Resolve "Update statistics"

Closes #27

See merge request !9
parents 8b8d5d50 6406d81f
......@@ -38,7 +38,11 @@ import javax.persistence.UniqueConstraint;
*
*/
@Entity
@Table(name = "accession", uniqueConstraints = { @UniqueConstraint(name = "UQ_accession_genus_inst", columnNames = { "instituteId", "taxGenus", "acceNumb" }) }, indexes = { @Index(name = "IX_seqNo", columnList = "seqNo") })
@Table(name = "accession",
// Unique constraints
uniqueConstraints = { @UniqueConstraint(name = "UQ_accession_genus_inst", columnNames = { "instituteId", "taxGenus", "acceNumb" }) },
// Indexes
indexes = { @Index(name = "IX_seqNo", columnList = "seqNo"), @Index(name = "IX_accession_lastModifiedDate", columnList = "lastModifiedDate") })
public class Accession extends AccessionData {
/**
*
......
......@@ -141,4 +141,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Modifying
public void updateCrop(Accession accession, Crop crop);
@Query("select year(a.lastModifiedDate), month(a.lastModifiedDate), day(a.lastModifiedDate), a.institute, count(a) from Accession a group by year(a.lastModifiedDate), month(a.lastModifiedDate), day(a.lastModifiedDate), a.institute order by year(a.lastModifiedDate) desc, month(a.lastModifiedDate) desc, day(a.lastModifiedDate) desc, a.institute.code")
public List<Object[]> lastUpdatedStatistics();
@Query("select year(a.lastModifiedDate), month(a.lastModifiedDate), day(a.lastModifiedDate), count(a) from Accession a where a.institute = ?1 group by year(a.lastModifiedDate), month(a.lastModifiedDate), day(a.lastModifiedDate) order by year(a.lastModifiedDate) desc, month(a.lastModifiedDate) desc, day(a.lastModifiedDate) desc")
public List<Object[]> lastUpdatedStatistics(FaoInstitute faoInstitute);
}
......@@ -51,7 +51,6 @@ import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Organization;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.impl.NoSuchAccessionException;
import org.genesys2.spring.ResourceNotFoundException;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -270,4 +269,8 @@ public interface GenesysService {
AccessionDetails getAccession(UUID accessionUuid) throws NoSuchAccessionException;
List<Object[]> getLastUpdatedStatistics();
List<Object[]> getLastUpdatedStatistics(FaoInstitute faoInstitute);
}
......@@ -38,6 +38,10 @@ import java.util.zip.ZipOutputStream;
import javax.persistence.EntityManager;
import com.opencsv.CSVWriter;
import com.opencsv.ResultSetHelper;
import com.opencsv.ResultSetHelperService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang.StringUtils;
......@@ -107,7 +111,6 @@ import org.genesys2.spring.SecurityContextUtil;
import org.genesys2.util.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.data.domain.Page;
......@@ -123,10 +126,6 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.opencsv.CSVWriter;
import com.opencsv.ResultSetHelper;
import com.opencsv.ResultSetHelperService;
@Service
@Transactional(readOnly = true)
public class GenesysServiceImpl implements GenesysService, DatasetService {
......@@ -712,7 +711,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionCountryRefs() {
genesysLowlevelRepository.updateCountryRefs();
}
......@@ -720,14 +719,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionInstitueRefs() {
genesysLowlevelRepository.updateFaoInstituteRefs();
}
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void updateAccessionCount(FaoInstitute institute) {
if (institute == null)
return;
......@@ -742,14 +741,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Deprecated
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void addAccessions(List<Accession> accessions) {
accessionRepository.save(accessions);
}
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<Accession> saveAccessions(FaoInstitute institute, List<Accession> accessions) {
if (LOG.isDebugEnabled()) {
LOG.debug("Saving " + accessions.size() + " accessions");
......@@ -761,7 +760,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public AccessionData saveAccession(AccessionData accession) {
if (LOG.isDebugEnabled())
LOG.debug("Updating " + accession);
......@@ -778,7 +777,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<Accession> saveAccessions(Iterable<Accession> accessions) {
Set<FaoInstitute> institutes = new HashSet<FaoInstitute>();
for (Accession accession : accessions) {
......@@ -795,7 +794,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'DELETE') or hasPermission(#institute, 'ADMINISTRATION')")
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionHistoric> removeAccessions(FaoInstitute institute, List<Accession> toDelete) {
List<AccessionHistoric> deleted = new ArrayList<AccessionHistoric>();
......@@ -842,7 +841,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
// Worker threads don't carry this information
// @PreAuthorize("hasRole('ADMINISTRATOR')")
@Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.READ_UNCOMMITTED)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<SvalbardDeposit> saveSvalbards(List<SvalbardDeposit> svalbardDeposits) {
if (CollectionUtils.isEmpty(svalbardDeposits)) {
return svalbardDeposits;
......@@ -890,7 +889,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionCollect> saveCollecting(List<AccessionCollect> all) {
accessionCollectRepository.save(all);
return all;
......@@ -898,7 +897,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionCollect> removeCollecting(List<AccessionCollect> all) {
accessionCollectRepository.delete(all);
return all;
......@@ -906,7 +905,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionGeo> saveGeo(List<AccessionGeo> all) {
accessionGeoRepository.save(all);
return all;
......@@ -914,7 +913,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionGeo> removeGeo(List<AccessionGeo> all) {
accessionGeoRepository.delete(all);
return all;
......@@ -922,7 +921,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionBreeding> saveBreeding(List<AccessionBreeding> all) {
accessionBreedingRepository.save(all);
return all;
......@@ -930,7 +929,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionBreeding> removeBreeding(List<AccessionBreeding> all) {
accessionBreedingRepository.delete(all);
return all;
......@@ -938,7 +937,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionExchange> saveExchange(List<AccessionExchange> all) {
accessionExchangeRepository.save(all);
return all;
......@@ -946,7 +945,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionExchange> removeExchange(List<AccessionExchange> all) {
accessionExchangeRepository.delete(all);
return all;
......@@ -954,7 +953,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionRemark> saveRemarks(List<AccessionRemark> toSaveRemarks) {
accessionRemarkRepository.save(toSaveRemarks);
return toSaveRemarks;
......@@ -962,7 +961,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionRemark> removeRemarks(List<AccessionRemark> toRemoveRemarks) {
accessionRemarkRepository.delete(toRemoveRemarks);
return toRemoveRemarks;
......@@ -1003,7 +1002,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public Metadata addDataset(FaoInstitute institute, String title, String description) {
final Metadata metadata = new Metadata();
metadata.setInstituteCode(institute.getCode());
......@@ -1031,7 +1030,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#metadata, 'WRITE')")
@Transactional(readOnly = false)
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void upsertAccessionData(Metadata metadata, AccessionId accession, Map<Long, List<Object>> methodValues) {
// // Load all existing records for metadata+accession
// List<AccessionTrait> existingEntries =
......@@ -1487,14 +1486,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void refreshMetadataMethods() {
genesysLowlevelRepository.refreshMetadataMethods();
}
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionAlias> saveAliases(List<AccessionAlias> aliases) {
if (aliases.size() > 0) {
accessionAliasRepository.save(aliases);
......@@ -1504,7 +1503,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<AccessionAlias> removeAliases(List<AccessionAlias> aliases) {
if (aliases.size() > 0) {
accessionAliasRepository.delete(aliases);
......@@ -1515,7 +1514,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR')")
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public void upsertAliases(long accessionId, String acceNames, String otherIds) {
final AccessionData accession = getAccession(accessionId);
if (accession == null) {
......@@ -1607,7 +1606,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public Set<Long> removeAliases(Set<Long> toRemove) {
for (final Long id : toRemove) {
this.accessionAliasRepository.delete(id);
......@@ -1665,7 +1664,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
// @CacheEvict(value = "statistics", allEntries = true)
public List<PDCI> updatePDCI(final Set<Long> ids) {
if (LOG.isDebugEnabled())
LOG.debug("Calculating PDCI for " + ids.size() + " accessions");
......@@ -1689,7 +1688,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
@CacheEvict(value = "statistics", allEntries = true)
public PDCI updatePDCI(Long accessionId) {
if (pdciCalculator == null || accessionId == null) {
return null;
......@@ -1833,4 +1831,16 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
return accessions;
}
@Override
@Cacheable(value = "statistics", unless = "#result == null", key = "'stats.' + #root.methodName")
public List<Object[]> getLastUpdatedStatistics() {
return accessionRepository.lastUpdatedStatistics();
}
@Override
@Cacheable(value = "statistics", unless = "#result == null", key = "'stats.' + #root.methodName + '-' + #faoInstitute.code")
public List<Object[]> getLastUpdatedStatistics(FaoInstitute faoInstitute) {
return accessionRepository.lastUpdatedStatistics(faoInstitute);
}
}
......@@ -261,4 +261,9 @@ public class AccessionController extends BaseController {
return "redirect:/explore";
}
@RequestMapping("/updates")
public String updateStats(ModelMap model) {
model.addAttribute("updates", genesysService.getLastUpdatedStatistics());
return "/accession/updates";
}
}
......@@ -147,6 +147,7 @@ public class WiewsController extends BaseController {
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 5)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsSpeciesByInstitute(faoInstitute, new PageRequest(0, 5)));
model.addAttribute("statisticsPDCI", statisticsService.statisticsPDCI(faoInstitute));
model.addAttribute("updates", genesysService.getLastUpdatedStatistics(faoInstitute));
if (datasetCount > 0) {
model.addAttribute("statisticsPheno", statisticsService.statisticsPheno(faoInstitute));
......
......@@ -376,6 +376,9 @@ accession.resolve=Multiple accessions with the name ''{0}'' found in Genesys. Se
accession.page.data.title=Accession browser
accession.page.data.intro=Explore the accession data with Genesys. To refine your search, add filters such as country of origin, crop, species, or the latitude and longitude of the collecting site.
accession.taxonomy-at-institute=View {0} at {1}
accession.page.updates.title=Last updates of passport data
accession.page.updates.intro=Updates of passport data by date of last update, institute and number of records updated
accession.page.updated.never=Data provided before 2014
accession.svalbard-data=Svalbard Global Seed Vault duplication data
accession.svalbard-data.taxonomy=Reported scientific name
......
......@@ -1192,7 +1192,7 @@ $light-font-family: 'Roboto-Light';
}
div {
width: 20%;
// width: 20%;
/*text-align: right;*/
}
&:nth-child(odd) {
......@@ -4887,9 +4887,9 @@ table.accessions {
a {
width: 75%;
}
div {
width: 25%;
}
// div {
// width: 25%;
// }
}
}
......
......@@ -50,6 +50,10 @@
<a href="<c:url value="/content/about/history-of-genesys" />"> <spring:message code="menu.history-of-genesys" />
</a>
</li>
<li class="pull-left">
<a href="<c:url value="/acn/updates" />"> <spring:message code="accession.page.updates.title" />
</a>
</li>
<li class="pull-left">
<a href="<c:url value="/content/about/newsletter" />"> <spring:message code="menu.newsletter" />
</a>
......
<!DOCTYPE html>
<%@ include file="/WEB-INF/jsp/init.jsp" %>
<html>
<head>
<title><spring:message code="accession.page.updates.title" /></title>
</head>
<body class="about-page">
<cms:informative-h1 title="accession.page.updates.title" fancy="true" info="accession.page.updates.intro"/>
<spring:eval expression="T(java.text.DateFormatSymbols).getInstance(pageContext.response.locale).getMonths()" var="monthNames" />
<c:set var="year" value="" />
<c:set var="month" value="" />
<c:set var="day" value="" />
<div class="institute-list">
<c:forEach items="${updates}" var="update">
<c:if test="${month ne update[1]}">
<c:set var="month" value="${update[1]}" />
<c:if test="${update[0] eq null}">
<h1><spring:message code="accession.page.updated.never" /></h1>
</c:if>
<c:if test="${update[0] ne null}">
<h1>${monthNames[update[1]-1]} ${update[0]}</h1>
</c:if>
</c:if>
<div class="row">
<div class="col-xs-2"><b>
<c:if test="${update[0] ne null}">
${update[2]} ${monthNames[update[1]-1]} ${update[0]}
</c:if>
<c:if test="${update[0] eq null}">
----
</c:if>
</b></div>
<div class="col-xs-1"><b>${update[3].code}</b></div>
<div class="col-xs-8"><a href="<c:url value='/wiews/${update[3].code}' />">${update[3].fullName}</a></div>
<%-- <div class="col-xs-1">${update[4]}</div> --%>
<div class="col-xs-1 text-right"><b><fmt:formatNumber value="${update[4]}" /></b></div>
</div>
</c:forEach>
</div>
</body>
</html>
\ No newline at end of file
......@@ -462,7 +462,34 @@
</div>
</div>
</c:if>
</div>
<c:if test="${countByInstitute gt 0}">
<spring:eval expression="T(java.text.DateFormatSymbols).getInstance(pageContext.response.locale).getMonths()" var="monthNames" />
<div class="collect-info col-lg-6 col-md-12 col-sm-12 col-xs-12">
<h4 class="row section-heading"><span><spring:message code="accession.page.updates.title" /></span></h4>
<div class="section-inner-content">
<div class="terms-table">
<c:forEach items="${updates}" var="update" varStatus="status">
<div class="row">
<div class="col-lg-8 col-md-6 col-sm-6 col-xs-6">
<c:if test="${update[0] eq null}">
<spring:message code="accession.page.updated.never" />
</c:if>
<c:if test="${update[3] ne null}">
<c:out value="${update[2]} ${monthNames[update[1]-1]} ${update[0]}" />
</c:if>
</div>
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-6 text-right">
<fmt:formatNumber value="${update[3]}" />
</div>
</div>
</c:forEach>
</div>
</div>
</div>
</div>
</c:if>
<security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<a href="<c:url value="/acl/${faoInstitute.getClass().name}/${faoInstitute.id}/permissions"><c:param name="back">/wiews/${faoInstitute.code}</c:param></c:url>" class="close">
......
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