Commit 498dc684 authored by Matija Obreza's avatar Matija Obreza

Use new taxonomy statistics, edit uniqueAcceNumbs

parent fdbabd5d
......@@ -212,6 +212,10 @@ public class FaoInstitute extends BusinessModel implements GeoReferencedEntity,
this.settings = settings;
}
public boolean isUniqueAcceNumbs() {
return this.uniqueAcceNumbs;
}
public boolean hasUniqueAcceNumbs() {
return this.uniqueAcceNumbs;
}
......
......@@ -49,11 +49,11 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select count(a) from Accession a where a.institute = ?1")
long countByInstitute(FaoInstitute institute);
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxonomy.genus) from Accession a where a.institute = ?1")
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxGenus) from Accession a where a.institute = ?1")
Page<Object[]> statisticsGenusInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select t, count(a) from Accession a inner join a.taxonomy t where a.institute = ?1 group by a.taxonomy order by count(a) desc", countQuery = "select count(distinct a.taxonomy) from Accession a where a.institute = ?1")
Page<Object[]> statisticsTaxonomyInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select a.taxSpecies, count(a) from Accession a where a.institute = ?1 group by a.taxSpecies order by count(a) desc", countQuery = "select count(distinct a.taxSpecies) from Accession a where a.institute = ?1")
Page<Object[]> statisticsSpeciesInInstitute(FaoInstitute institute, Pageable pageable);
// FIXME Slow query
// FIXME TOOD taxonomy1!
......
......@@ -98,7 +98,7 @@ public interface GenesysService {
Page<Object[]> statisticsGenusByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsTaxonomyByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute faoInstitute, Pageable pageable);
// Page<Object[]> statisticsCropByInstitute(FaoInstitute faoInstitute, Pageable pageable);
......
......@@ -57,4 +57,6 @@ public interface InstituteService {
long countActive();
void setUniqueAcceNumbs(FaoInstitute faoInstitute, boolean uniqueAcceNumbs);
}
......@@ -43,4 +43,6 @@ public interface TaxonomyService {
long upgradeTaxonomy(Taxonomy t1, Taxonomy2 t2);
Taxonomy2 get(Long id);
}
......@@ -209,8 +209,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
public List<Accession> listAccessions(List<? extends AccessionIdentifier3> accns) {
List<Accession> result = new ArrayList<Accession>(accns.size());
for (AccessionIdentifier3 aid3 : accns) {
Accession accn = accessionRepository.findOne(aid3.getHoldingInstitute(), aid3.getAccessionName(),
aid3.getGenus());
Accession accn = accessionRepository.findOne(aid3.getHoldingInstitute(), aid3.getAccessionName(), aid3.getGenus());
// Including null's
result.add(accn);
if (accn == null) {
......@@ -362,8 +361,12 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
}
@Override
public Page<Object[]> statisticsTaxonomyByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsTaxonomyInInstitute(institute, pageable);
public Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute institute, Pageable pageable) {
Page<Object[]> page = accessionRepository.statisticsSpeciesInInstitute(institute, pageable);
for (Object[] r : page.getContent()) {
r[0] = taxonomyService.get((Long) r[0]);
}
return page;
}
@Override
......
......@@ -128,6 +128,16 @@ public class InstituteServiceImpl implements InstituteService {
contentService.updateArticle(faoInstitute, "blurp", null, blurp, locale);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
public void setUniqueAcceNumbs(FaoInstitute faoInstitute, boolean uniqueAcceNumbs) {
FaoInstitute inst = instituteRepository.findOne(faoInstitute.getId());
LOG.info("Setting 'uniqueAcceNumbs' to " + uniqueAcceNumbs + " for " + faoInstitute);
inst.setUniqueAcceNumbs(uniqueAcceNumbs);
instituteRepository.save(inst);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#faoInstitute, 'ADMINISTRATION')")
@Transactional(readOnly = false)
......
......@@ -43,6 +43,11 @@ public class TaxonomyServiceImpl implements TaxonomyService {
@Autowired
private Taxonomy2Repository taxonomy2Repository;
@Override
public Taxonomy2 get(Long id) {
return taxonomy2Repository.findOne(id);
}
@Override
public Taxonomy get(String genus, String species) {
return taxonomyRepository.getByGenusAndSpecies(genus, species);
......@@ -174,16 +179,16 @@ public class TaxonomyServiceImpl implements TaxonomyService {
}
taxonomy = taxonomy2Repository.save(taxonomy);
return taxonomy;
// TODO Should update crop taxonomy lists?
} catch (Throwable e) {
LOG.warn("Error " + e.getMessage() + " :" + taxonomy);
continue;
}
} else {
return taxonomy;
}
return taxonomy;
}
// Should not get here!
......@@ -210,7 +215,7 @@ public class TaxonomyServiceImpl implements TaxonomyService {
/**
* @deprecated Will be removed when {@link Taxonomy} is removed.
*/
// TODO FIXME Remove
// TODO FIXME Remove
@Override
public List<Taxonomy> findAll() {
return taxonomyRepository.findAll();
......@@ -219,7 +224,7 @@ public class TaxonomyServiceImpl implements TaxonomyService {
/**
* @deprecated Will be removed when {@link Taxonomy} is removed.
*/
// TODO FIXME Remove
// TODO FIXME Remove
@Override
@Transactional
public long upgradeTaxonomy(Taxonomy t1, Taxonomy2 t2) {
......
......@@ -101,7 +101,7 @@ public class WiewsController extends BaseController {
// PageRequest(0, 30)));
model.addAttribute("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 30)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsTaxonomyByInstitute(faoInstitute, new PageRequest(0, 30)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsSpeciesByInstitute(faoInstitute, new PageRequest(0, 30)));
return "/wiews/details";
}
......@@ -127,7 +127,7 @@ public class WiewsController extends BaseController {
@RequestMapping("/{wiewsCode}/update")
public String update(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam("blurp") String blurp,
@RequestParam("gaTracker") String gaTracker) {
@RequestParam("gaTracker") String gaTracker, @RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs) {
_logger.debug("Updating institite " + wiewsCode);
FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
......@@ -138,6 +138,7 @@ public class WiewsController extends BaseController {
Map<String, String> settings = new HashMap<String, String>();
settings.put("googleAnalytics.tracker", gaTracker);
instituteService.updateSettings(faoInstitute, settings);
instituteService.setUniqueAcceNumbs(faoInstitute, uniqueAcceNumbs);
return "redirect:/wiews/" + wiewsCode;
}
......
......@@ -154,6 +154,8 @@ faoInstitute.email=Contact email
faoInstitute.acronym=Acronym
faoInstitute.url=Web link
faoInstitute.member-of-organizations-and-networks=Organizations and Networks:
faoInstitute.uniqueAcceNumbs.true=Each accession number is unique within this institute.
faoInstitute.uniqueAcceNumbs.false=The same accession number may be used in separate collections in this institute.
view.accessions=View accessions...
view.datasets=View datasets...
......
......@@ -29,6 +29,13 @@
<input type="text" name="gaTracker" class="form-control required" value="${faoInstitute.settings['googleAnalytics.tracker'].value}" />
</div>
</div>
<div class="form-group">
<div class="controls col-offset-2 col-lg-3">
<label><input type="radio" name="uniqueAcceNumbs" class="" value="true" ${faoInstitute.uniqueAcceNumbs==true ? 'checked' : ''} /> <spring:message code="faoInstitute.uniqueAcceNumbs.true" /></label>
<label><input type="radio" name="uniqueAcceNumbs" class="" value="false" ${faoInstitute.uniqueAcceNumbs==false ? 'checked' : ''} /> <spring:message code="faoInstitute.uniqueAcceNumbs.false" /></label>
</div>
</div>
<input type="submit" value="<spring:message code="save"/>" class="btn btn-primary" /> <a href="<c:url value="/wiews/${faoInstitute.code.toLowerCase()}" />" class="btn btn-default"> <spring:message code="cancel" />
</a>
......
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