Commit 2f35199d authored by Matija Obreza's avatar Matija Obreza

Merge branch 'forages' into staging

# Conflicts:
#	src/main/java/org/genesys2/server/model/elastic/AccessionDetails.java
#	src/main/java/org/genesys2/server/persistence/domain/AccessionRepository.java
#	src/main/java/org/genesys2/server/service/GenesysService.java
#	src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
#	src/main/webapp/WEB-INF/jsp/accession/details.jsp
#	src/main/webapp/WEB-INF/jsp/crop/index.jsp
parents f74479e6 247ca4fa
......@@ -569,7 +569,7 @@
<configuration>
<stopPort>8888</stopPort>
<stopKey>stop</stopKey>
<jvmArgs>-Dspring.profiles.active=dev -Xmx2048M -Xms1024M -XX:MaxPermSize=128M -Djava.awt.headless=true -server</jvmArgs>
<jvmArgs>-Dspring.profiles.active=dev -Xmx2048M -Xms1024M -XX:MaxPermSize=128M -Djava.awt.headless=true -server -Dorg.eclipse.jetty.server.Request.maxFormContentSize=5000000</jvmArgs>
</configuration>
</plugin>
<plugin>
......@@ -606,7 +606,7 @@
</configuration>
</execution>
<execution>
<id>grunt build</id>
<id>grunt-build</id>
<goals>
<goal>grunt</goal>
</goals>
......
......@@ -74,6 +74,8 @@ public class AccessionDetails {
@Field(type = FieldType.Nested, store = false)
private ArrayList<Remark> remarks;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String cropName;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private ArrayList<String> crops;
......@@ -123,6 +125,7 @@ public class AccessionDetails {
ad.sampStat = accession.getSampleStatus();
ad.storage = new ArrayList<Integer>(accession.getStoRage());
ad.lists = new HashSet<String>();
ad.cropName=accession.getCropName();
ad.inSgsv = accession.getInSvalbard() != null && accession.getInSvalbard() == true ? true : false;
for (AccessionList al : accession.getAccessionId().getLists()) {
ad.lists.add(al.getUuid().toString());
......@@ -168,6 +171,7 @@ public class AccessionDetails {
* @param shortName
*/
public void crops(String cropName) {
cropName = StringUtils.defaultIfBlank(cropName, null);
if (StringUtils.isBlank(cropName))
return;
this.crops = new ArrayList<String>();
......@@ -360,6 +364,14 @@ public class AccessionDetails {
this.remarks = remarks;
}
public String getCropName() {
return cropName;
}
public void setCropName(String cropName) {
this.cropName = cropName;
}
public ArrayList<String> getCrops() {
return crops;
}
......
......@@ -60,6 +60,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select count(a) from Accession a where a.institute.country = ?1 and a.historic = false")
long countByLocation(Country country);
@Query(value = "select a.cropName, count(a.id) from Accession a where a.institute = ?1 and a.historic = false group by a.cropName order by count(a) desc", countQuery = "select count(distinct a.cropName) from Accession a where a.institute = ?1")
Page<Object[]> statisticsCropNameInInstitute(FaoInstitute institute, Pageable pageable);
@Query(value = "select t.genus, count(a.id) from Accession a inner join a.taxonomy t where a.institute = ?1 and a.historic = false group by t.genus order by count(a) desc", countQuery = "select count(distinct a.taxonomy.taxGenus) from Accession a where a.institute = ?1")
Page<Object[]> statisticsGenusInInstitute(FaoInstitute institute, Pageable pageable);
......@@ -131,7 +134,11 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select a from Accession a where a.cropName != null")
Stream<Accession> streamWithCropname();
@Query("select a.id from Accession a where a.cropName != null")
List<Long> listAccessionIdsWithCropname();
@Query("update Accession a set a.crop = ?2 where a = ?1")
@Modifying
public void updateCrop(Accession accession, Crop crop);
}
......@@ -20,6 +20,8 @@ public interface FilterConstants {
public static final String CROPS = "crops";
public static final String CROPNAME = "cropName";
public static final String SAMPSTAT = "sampStat";
public static final String STORAGE = "storage";
......
......@@ -116,6 +116,8 @@ public interface GenesysService {
Accession getAccession(String instCode, String acceNumb, String genus) throws NonUniqueAccessionException;
Page<Object[]> statisticsCropNameByInstitute(FaoInstitute faoInstitute, Pageable pageRequest);
Page<Object[]> statisticsGenusByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute faoInstitute, Pageable pageable);
......@@ -264,8 +266,6 @@ public interface GenesysService {
List<SvalbardDeposit> saveSvalbards(List<SvalbardDeposit> svalbards);
Stream<Accession> streamWithCropname();
List<Accession> saveAccessionCrops(ArrayList<Accession> copy);
List<Accession> saveAccessionCrops(ArrayList<Long> accessionIds);
}
......@@ -186,7 +186,7 @@ public class CropServiceImpl implements CropService {
public void rebuildTaxonomies(Crop crop) {
LOG.info("Rebuilding crop taxonomy for: " + crop.getName());
// for all rules
final List<CropRule> cropRules = crop.getCropRules();
final List<CropRule> cropRules = getCropRules(crop);
LOG.warn("Using rules: " + cropRules);
rebuildCropTaxonomies(crop, cropRules);
}
......@@ -199,9 +199,9 @@ public class CropServiceImpl implements CropService {
if (!cr.isIncluded())
continue;
if (cr.getSpecies() == null && cr.getSubtaxa() == null) {
if (StringUtils.isBlank(cr.getSpecies()) && StringUtils.isBlank(cr.getSubtaxa())) {
taxa.addAll(taxonomy2Repository.findByGenus(cr.getGenus()));
} else if (cr.getSubtaxa() == null) {
} else if (StringUtils.isBlank(cr.getSubtaxa())) {
taxa.addAll(taxonomy2Repository.findByGenusAndSpecies(cr.getGenus(), cr.getSpecies()));
} else {
taxa.addAll(taxonomy2Repository.findByGenusAndSpeciesAndSubtaxa(cr.getGenus(), cr.getSpecies(), cr.getSubtaxa()));
......
......@@ -171,6 +171,7 @@ public class DirectMysqlQuery {
createQuery(whereBuffer, "a.seqNo", filters.get(FilterConstants.SEQUENTIAL_NUMBER), params);
createQuery(whereBuffer, "a.orgCty", filters.get(FilterConstants.ORGCTY_ISO3), params);
createQuery(whereBuffer, "a.instCode", filters.get(FilterConstants.INSTCODE), params);
createQuery(whereBuffer, "a.cropName", filters.get(FilterConstants.CROPNAME), params);
createQuery(whereBuffer, "faocty.code3", filters.get(FilterConstants.INSTITUTE_COUNTRY_ISO3), params);
createQuery(whereBuffer, "a.inSGSV", filters.get(FilterConstants.SGSV), params);
createQuery(whereBuffer, "a.mlsStat", filters.get(FilterConstants.MLSSTATUS), params);
......
......@@ -57,7 +57,7 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
/**
* Converts filter requests (usually JSON) to internal data structures
*
* @author matijaobreza
* @author Matija Obreza
*
*/
@Component
......@@ -66,8 +66,6 @@ public class FilterHandler {
@Autowired
private TraitService traitService;
@Autowired
private ObjectMapper objectMapper;
private final ArrayList<GenesysFilter> availableFilters;
......@@ -81,6 +79,7 @@ public class FilterHandler {
this.availableFilters = new ArrayList<GenesysFilter>();
this.availableFilters.add(new BasicFilter(FilterConstants.CROPS, DataType.STRING));
this.availableFilters.add(new BasicFilter(FilterConstants.CROPNAME, DataType.STRING));
this.availableFilters.add(new BasicFilter(FilterConstants.LISTS, DataType.STRING));
this.availableFilters.add(new I18nListFilter<Integer>(FilterConstants.SAMPSTAT, DataType.NUMERIC).build("accession.sampleStatus", new Integer[] { 100,
......
......@@ -33,16 +33,11 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
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;
......@@ -127,6 +122,10 @@ 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 {
......@@ -208,6 +207,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
columnList.add("taxonomy." + Api1Constants.Taxonomy.SPECIES);
columnList.add("taxonomy." + Api1Constants.Taxonomy.SUBTAXA);
columnList.add(Api1Constants.Accession.CROP_NAMES);
columnList.add(Api1Constants.Accession.CROPNAME);
columnList.add(Api1Constants.Accession.ORIGCTY);
columnList.add(Api1Constants.Accession.SAMPSTAT);
columnList.add("institute." + Api1Constants.Institute.INSTCODE);
......@@ -358,7 +358,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
if (all.accession.getCrop() != null) {
ad.crops(all.accession.getCrop().getShortName());
} else {
ad.crops(cropService.getCrops(all.accession.getTaxonomy()));
// Ignore taxonomy crops: ad.crops(cropService.getCrops(all.accession.getTaxonomy()));
}
return ad;
}
......@@ -628,6 +628,11 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return traitValueRepository.getValues(metadata, methods, accessions);
}
@Override
public Page<Object[]> statisticsCropNameByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsCropNameInInstitute(institute, pageable);
}
@Override
public Page<Object[]> statisticsGenusByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsGenusInInstitute(institute, pageable);
......@@ -740,7 +745,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public List<Accession> saveAccessions(Iterable<Accession> accessions) {
Set<FaoInstitute> institutes = new HashSet<FaoInstitute>();
for (Accession accession : accessions) {
System.out.println("Saving " + accession + " STO=" + accession.getStoRage() + " ST=" + accession.getStorage());
// System.out.println("Saving " + accession + " STO=" + accession.getStoRage() + " ST=" + accession.getStorage());
institutes.add(accession.getInstitute());
}
List<Accession> res = accessionRepository.save(accessions);
......@@ -1790,17 +1795,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
genesysLowlevelRepository.updateAccessionSequentialNumber(batch);
}
@Override
public Stream<Accession> streamWithCropname() {
return accessionRepository.streamWithCropname();
}
@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
// @PreAuthorize("hasRole('ADMINISTRATOR')")
public List<Accession> saveAccessionCrops(ArrayList<Accession> accessions) {
for (Accession accession : accessions)
public List<Accession> saveAccessionCrops(ArrayList<Long> accessionIds) {
List<Accession> accessions = new ArrayList<>(accessionRepository.findAll(accessionIds));
for (Accession accession : accessions) {
accessionRepository.updateCrop(accession, cropService.getCrop(accession.getCropName()));
}
return accessions;
}
}
......@@ -20,9 +20,8 @@ import org.springframework.stereotype.Component;
import com.hazelcast.core.IQueue;
/**
* ES Processor component uses Spring's @Scheduled annotation to scan queues
* with 2000ms delay measured from the completion time of each preceding
* invocation.
* ES Processor component uses Spring's @Scheduled annotation to scan queues with 2000ms delay measured from the
* completion time of each preceding invocation.
*/
@Component
class ElasticUpdaterProcessor {
......@@ -92,8 +91,7 @@ class ElasticUpdaterProcessor {
}
if (LOG.isInfoEnabled() && (i % 500 == 0)) {
LOG.info("Queue size update=" + elasticUpdateQueue.size() + " indexed=" + i + " rate=" + (1000.0 * i / (stopWatch.getTime()))
+ " records/s");
LOG.info("Queue size update=" + elasticUpdateQueue.size() + " indexed=" + i + " rate=" + Math.round(1000.0 * i / (stopWatch.getTime())) + " records/s");
}
} while (toUpdate != null);
......
......@@ -16,11 +16,14 @@
package org.genesys2.server.servlet.controller;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.elasticsearch.common.lang3.StringUtils;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.CropRule;
import org.genesys2.server.model.impl.CropTaxonomy;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
......@@ -43,6 +46,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@Controller
@RequestMapping("/c")
public class CropController extends BaseController {
......@@ -100,6 +109,11 @@ public class CropController extends BaseController {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasPermission(#crop, 'ADMINISTRATION')")
public String edit(ModelMap model, @PathVariable(value = "shortName") String shortName) {
view(model, shortName);
try {
model.addAttribute("cropRulesJson", new ObjectMapper().writeValueAsString(model.get("cropRules")));
} catch (JsonProcessingException e) {
}
return "/crop/edit";
}
......@@ -117,7 +131,7 @@ public class CropController extends BaseController {
return "/crop/edit";
}
@RequestMapping("/{shortName}/update")
@RequestMapping(value = "/{shortName}/update", method = RequestMethod.POST)
public String update(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("cropName") String cropName,
@RequestParam("blurp") String aboutBody, @RequestParam(value = "summary", required = false) String summary) {
......@@ -132,7 +146,7 @@ public class CropController extends BaseController {
return "redirect:/c/" + shortName;
}
@RequestMapping(value = "/{shortName}/update", params = { "otherNames" })
@RequestMapping(value = "/{shortName}/update", params = { "otherNames" }, method = RequestMethod.POST)
public String updateOtherNames(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("otherNames") String otherNames) {
_logger.debug("Updating crop aliases for " + shortName);
......@@ -147,6 +161,37 @@ public class CropController extends BaseController {
return edit(model, shortName);
}
@RequestMapping(value = "/{shortName}/update", params = { "action=update-rules", "cropRules" }, method = RequestMethod.POST)
public String updateCropRules(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("cropRules") String cropRulesJson)
throws JsonParseException, JsonMappingException, IOException {
_logger.debug("Updating crop rules for " + shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
List<CropRule> rules = new ObjectMapper().readValue(cropRulesJson, new TypeReference<List<CropRule>>() {
});
cropService.setCropRules(crop, rules);
return edit(model, shortName);
}
@RequestMapping(value = "/{shortName}/update", params = { "action=update-taxonomy" }, method = RequestMethod.POST)
public String updateTaxonomies(ModelMap model, @PathVariable(value = "shortName") String shortName) {
_logger.debug("Updating crop taxonomies for " + shortName);
final Crop crop = cropService.getCrop(shortName);
if (crop == null) {
throw new ResourceNotFoundException();
}
cropService.rebuildTaxonomies(crop);
return edit(model, shortName);
}
@RequestMapping("/{shortName}/ajax/taxonomies")
public String ajaxTaxonomies(ModelMap model, @PathVariable(value = "shortName") String shortName,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......
......@@ -135,8 +135,7 @@ public class WiewsController extends BaseController {
{
AppliedFilters instituteFilter = new AppliedFilters();
instituteFilter.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(
new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
instituteFilter.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
try {
model.addAttribute("statisticsCrops", elasticService.termStatisticsAuto(instituteFilter, FilterConstants.CROPS, 5));
......@@ -144,6 +143,7 @@ public class WiewsController extends BaseController {
_logger.warn(e.getMessage());
}
}
model.addAttribute("statisticsCropName", genesysService.statisticsCropNameByInstitute(faoInstitute, new PageRequest(0, 5)));
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));
......@@ -155,6 +155,16 @@ public class WiewsController extends BaseController {
return "/wiews/details";
}
@RequestMapping(value = "/{wiewsCode}/stat-cropName", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Object[]> getCropNameStats(@PathVariable(value = "wiewsCode") String wiewsCode) {
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
return genesysService.statisticsCropNameByInstitute(faoInstitute, new PageRequest(0, 10)).getContent();
}
@RequestMapping(value = "/{wiewsCode}/stat-genus", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Object[]> getGenusStats(@PathVariable(value = "wiewsCode") String wiewsCode) {
......@@ -196,9 +206,8 @@ public class WiewsController extends BaseController {
@RequestMapping("/{wiewsCode}/update")
public String update(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam("blurp") String aboutBody,
@RequestParam(value = "summary", required = false) String summary, @RequestParam("gaTracker") String gaTracker,
@RequestParam("mailto") String mailto, @RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs,
@RequestParam(value = "allowMaterialRequests", required = false, defaultValue = "false") boolean allowMaterialRequests,
@RequestParam(value = "summary", required = false) String summary, @RequestParam("gaTracker") String gaTracker, @RequestParam("mailto") String mailto,
@RequestParam("uniqueAcceNumbs") boolean uniqueAcceNumbs, @RequestParam(value = "allowMaterialRequests", required = false, defaultValue = "false") boolean allowMaterialRequests,
@RequestParam("codeSVGS") String codeSVGS) {
_logger.debug("Updating institite " + wiewsCode);
......@@ -220,8 +229,7 @@ public class WiewsController extends BaseController {
}
@RequestMapping("/{wiewsCode}/data")
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing country " + wiewsCode);
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
......@@ -232,7 +240,7 @@ public class WiewsController extends BaseController {
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping("/{wiewsCode}/data/map")
public String viewData(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode) {
_logger.debug("Viewing map for institute " + wiewsCode);
......@@ -254,16 +262,33 @@ public class WiewsController extends BaseController {
}
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(
new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
return "forward:/explore/overview?filter=" + URLEncoder.encode(appliedFilters.toString(), "UTF8");
}
@RequestMapping("/{wiewsCode}/cropName/{cropName}")
public String viewDataByCropname(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @PathVariable(value = "cropName") String cropName,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing institute " + wiewsCode);
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
}
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(wiewsCode)));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.CROPNAME).addFilterValue(new FilterHandler.LiteralValueFilter(cropName)));
model.addAttribute("filter", appliedFilters.toString());
model.addAttribute("page", page);
return "redirect:/explore";
}
@RequestMapping("/{wiewsCode}/t/{genus}")
public String viewDataByGenusSpecies(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @PathVariable(value = "genus") String genus,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) {
_logger.debug("Viewing country " + wiewsCode);
_logger.debug("Viewing institute " + wiewsCode);
final FaoInstitute faoInstitute = instituteService.getInstitute(wiewsCode);
if (faoInstitute == null) {
throw new ResourceNotFoundException();
......@@ -276,8 +301,11 @@ public class WiewsController extends BaseController {
}
_logger.debug("Got " + taxonomy2);
model.addAttribute("filter", "{\"" + FilterConstants.INSTCODE + "\":[\"" + faoInstitute.getCode() + "\"],\"" + FilterConstants.TAXONOMY_GENUS
+ "\":[\"" + taxonomy2.getGenus() + "\"]}");
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(wiewsCode)));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.TAXONOMY_GENUS).addFilterValue(new FilterHandler.LiteralValueFilter(taxonomy2.getGenus())));
model.addAttribute("filter", appliedFilters.toString());
model.addAttribute("page", page);
return "redirect:/explore";
}
......@@ -298,8 +326,12 @@ public class WiewsController extends BaseController {
}
_logger.debug("Got " + taxonomy2);
model.addAttribute("filter", "{\"" + FilterConstants.INSTCODE + "\":[\"" + faoInstitute.getCode() + "\"],\"" + FilterConstants.TAXONOMY_GENUS
+ "\":[\"" + taxonomy2.getGenus() + "\"],\"" + FilterConstants.TAXONOMY_SPECIES + "\":[\"" + taxonomy2.getSpecies() + "\"]}");
AppliedFilters appliedFilters = new AppliedFilters();
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(wiewsCode)));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.TAXONOMY_GENUS).addFilterValue(new FilterHandler.LiteralValueFilter(taxonomy2.getGenus())));
appliedFilters.add(new AppliedFilter().setFilterName(FilterConstants.TAXONOMY_SPECIES).addFilterValue(new FilterHandler.LiteralValueFilter(taxonomy2.getSpecies())));
model.addAttribute("filter", appliedFilters.toString());
model.addAttribute("page", page);
return "redirect:/explore";
}
......
......@@ -34,9 +34,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.StopWatch;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.persistence.domain.AccessionRepository;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepository;
import org.genesys2.server.service.CountryNamesUpdater;
import org.genesys2.server.service.CropService;
......@@ -56,8 +57,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -118,6 +117,9 @@ public class AdminController {
ObjectMapper mapper = new ObjectMapper();
@Autowired
private AccessionRepository accessionRepository;
@RequestMapping("/")
public String root(Model model) {
return "/admin/index";
......@@ -362,8 +364,7 @@ public class AdminController {
}
/**
* Scan AccessionData table and convert ACCENUMB to ACCENUMBNUMB (extract
* the number from the ACCNUMB)
* Scan AccessionData table and convert ACCENUMB to ACCENUMBNUMB (extract the number from the ACCNUMB)
*
* @return
*/
......@@ -374,39 +375,41 @@ public class AdminController {
return "redirect:/admin/";
}
@RequestMapping(value = "/rebuild-taxonomies", method = RequestMethod.POST)
@RequestMapping(value = "/taxonomy", method = RequestMethod.POST, params={"action=taxonomy-rebuild"})
public String rebuild() {
LOG.info("Rebuilding taxonomies");
cropService.rebuildTaxonomies();
return "redirect:/admin/";
}
@RequestMapping(value = "/cleanup-taxonomies", method = RequestMethod.POST)
@RequestMapping(value = "/taxonomy", method = RequestMethod.POST, params={"action=taxonomy-cleanup"})
public String cleanupTaxonomies() {
taxonomyService.cleanupTaxonomies();
return "redirect:/admin/";
}
@Transactional(readOnly=true, propagation=Propagation.REQUIRES_NEW)
@RequestMapping(value = "/cropname-crop", method = RequestMethod.POST)
public String assignCropWithCropname() {
LOG.info("Assigning crops to accessions with CROPNAME.");
AtomicLong counter = new AtomicLong(0);
List<Accession> batch = Collections.synchronizedList(new ArrayList<>());
genesysService.streamWithCropname().parallel().forEach(accession -> {
batch.add(accession);
ArrayList<Accession> copy = null;
StopWatch stopWatch = new StopWatch();
stopWatch.start();
final List<Long> batch = Collections.synchronizedList(new ArrayList<>());
List<Long> list = accessionRepository.listAccessionIdsWithCropname();
LOG.info("The list has " + list.size() + " elements");
list.stream().parallel().forEach(accessionId -> {
batch.add(accessionId);
ArrayList<Long> copy = null;
synchronized (batch) {
if (batch.size() > 100) {
copy = new ArrayList<>(batch);
batch.clear();
}
}
if (copy != null) {
if (copy != null)
genesysService.saveAccessionCrops(copy);
}
if (counter.incrementAndGet() % 1000 == 0 && LOG.isInfoEnabled()) {
LOG.info("Updated " + counter.get() + " records");
LOG.info("Updated " + counter.get() + " records overall_rate=" + Math.round(1000.0 * counter.get() / (stopWatch.getTime())) + " records/s");
}
});
LOG.info("Done assigning crops to accessions with CROPNAME.");
......
......@@ -184,6 +184,7 @@ faoInstitutes.page.profile.title=WIEWS {0}
faoInstitutes.stat.accessionCount=Accessions in Genesys:
faoInstitutes.stat.datasetCount=Additional datasets in Genesys:
faoInstitute.stat-by-crop=Most represented Crops