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 @@ ...@@ -569,7 +569,7 @@
<configuration> <configuration>
<stopPort>8888</stopPort> <stopPort>8888</stopPort>
<stopKey>stop</stopKey> <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> </configuration>
</plugin> </plugin>
<plugin> <plugin>
...@@ -606,7 +606,7 @@ ...@@ -606,7 +606,7 @@
</configuration> </configuration>
</execution> </execution>
<execution> <execution>
<id>grunt build</id> <id>grunt-build</id>
<goals> <goals>
<goal>grunt</goal> <goal>grunt</goal>
</goals> </goals>
......
...@@ -74,6 +74,8 @@ public class AccessionDetails { ...@@ -74,6 +74,8 @@ public class AccessionDetails {
@Field(type = FieldType.Nested, store = false) @Field(type = FieldType.Nested, store = false)
private ArrayList<Remark> remarks; private ArrayList<Remark> remarks;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String cropName;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String) @Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private ArrayList<String> crops; private ArrayList<String> crops;
...@@ -123,6 +125,7 @@ public class AccessionDetails { ...@@ -123,6 +125,7 @@ public class AccessionDetails {
ad.sampStat = accession.getSampleStatus(); ad.sampStat = accession.getSampleStatus();
ad.storage = new ArrayList<Integer>(accession.getStoRage()); ad.storage = new ArrayList<Integer>(accession.getStoRage());
ad.lists = new HashSet<String>(); ad.lists = new HashSet<String>();
ad.cropName=accession.getCropName();
ad.inSgsv = accession.getInSvalbard() != null && accession.getInSvalbard() == true ? true : false; ad.inSgsv = accession.getInSvalbard() != null && accession.getInSvalbard() == true ? true : false;
for (AccessionList al : accession.getAccessionId().getLists()) { for (AccessionList al : accession.getAccessionId().getLists()) {
ad.lists.add(al.getUuid().toString()); ad.lists.add(al.getUuid().toString());
...@@ -168,6 +171,7 @@ public class AccessionDetails { ...@@ -168,6 +171,7 @@ public class AccessionDetails {
* @param shortName * @param shortName
*/ */
public void crops(String cropName) { public void crops(String cropName) {
cropName = StringUtils.defaultIfBlank(cropName, null);
if (StringUtils.isBlank(cropName)) if (StringUtils.isBlank(cropName))
return; return;
this.crops = new ArrayList<String>(); this.crops = new ArrayList<String>();
...@@ -360,6 +364,14 @@ public class AccessionDetails { ...@@ -360,6 +364,14 @@ public class AccessionDetails {
this.remarks = remarks; this.remarks = remarks;
} }
public String getCropName() {
return cropName;
}
public void setCropName(String cropName) {
this.cropName = cropName;
}
public ArrayList<String> getCrops() { public ArrayList<String> getCrops() {
return crops; return crops;
} }
......
...@@ -60,6 +60,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> { ...@@ -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") @Query("select count(a) from Accession a where a.institute.country = ?1 and a.historic = false")
long countByLocation(Country country); 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") @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); Page<Object[]> statisticsGenusInInstitute(FaoInstitute institute, Pageable pageable);
...@@ -131,7 +134,11 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> { ...@@ -131,7 +134,11 @@ public interface AccessionRepository extends JpaRepository<Accession, Long> {
@Query("select a from Accession a where a.cropName != null") @Query("select a from Accession a where a.cropName != null")
Stream<Accession> streamWithCropname(); 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") @Query("update Accession a set a.crop = ?2 where a = ?1")
@Modifying @Modifying
public void updateCrop(Accession accession, Crop crop); public void updateCrop(Accession accession, Crop crop);
} }
...@@ -20,6 +20,8 @@ public interface FilterConstants { ...@@ -20,6 +20,8 @@ public interface FilterConstants {
public static final String CROPS = "crops"; public static final String CROPS = "crops";
public static final String CROPNAME = "cropName";
public static final String SAMPSTAT = "sampStat"; public static final String SAMPSTAT = "sampStat";
public static final String STORAGE = "storage"; public static final String STORAGE = "storage";
......
...@@ -116,6 +116,8 @@ public interface GenesysService { ...@@ -116,6 +116,8 @@ public interface GenesysService {
Accession getAccession(String instCode, String acceNumb, String genus) throws NonUniqueAccessionException; 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[]> statisticsGenusByInstitute(FaoInstitute faoInstitute, Pageable pageable);
Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute faoInstitute, Pageable pageable); Page<Object[]> statisticsSpeciesByInstitute(FaoInstitute faoInstitute, Pageable pageable);
...@@ -264,8 +266,6 @@ public interface GenesysService { ...@@ -264,8 +266,6 @@ public interface GenesysService {
List<SvalbardDeposit> saveSvalbards(List<SvalbardDeposit> svalbards); List<SvalbardDeposit> saveSvalbards(List<SvalbardDeposit> svalbards);
Stream<Accession> streamWithCropname(); List<Accession> saveAccessionCrops(ArrayList<Long> accessionIds);
List<Accession> saveAccessionCrops(ArrayList<Accession> copy);
} }
...@@ -186,7 +186,7 @@ public class CropServiceImpl implements CropService { ...@@ -186,7 +186,7 @@ public class CropServiceImpl implements CropService {
public void rebuildTaxonomies(Crop crop) { public void rebuildTaxonomies(Crop crop) {
LOG.info("Rebuilding crop taxonomy for: " + crop.getName()); LOG.info("Rebuilding crop taxonomy for: " + crop.getName());
// for all rules // for all rules
final List<CropRule> cropRules = crop.getCropRules(); final List<CropRule> cropRules = getCropRules(crop);
LOG.warn("Using rules: " + cropRules); LOG.warn("Using rules: " + cropRules);
rebuildCropTaxonomies(crop, cropRules); rebuildCropTaxonomies(crop, cropRules);
} }
...@@ -199,9 +199,9 @@ public class CropServiceImpl implements CropService { ...@@ -199,9 +199,9 @@ public class CropServiceImpl implements CropService {
if (!cr.isIncluded()) if (!cr.isIncluded())
continue; continue;
if (cr.getSpecies() == null && cr.getSubtaxa() == null) { if (StringUtils.isBlank(cr.getSpecies()) && StringUtils.isBlank(cr.getSubtaxa())) {
taxa.addAll(taxonomy2Repository.findByGenus(cr.getGenus())); 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())); taxa.addAll(taxonomy2Repository.findByGenusAndSpecies(cr.getGenus(), cr.getSpecies()));
} else { } else {
taxa.addAll(taxonomy2Repository.findByGenusAndSpeciesAndSubtaxa(cr.getGenus(), cr.getSpecies(), cr.getSubtaxa())); taxa.addAll(taxonomy2Repository.findByGenusAndSpeciesAndSubtaxa(cr.getGenus(), cr.getSpecies(), cr.getSubtaxa()));
......
...@@ -171,6 +171,7 @@ public class DirectMysqlQuery { ...@@ -171,6 +171,7 @@ public class DirectMysqlQuery {
createQuery(whereBuffer, "a.seqNo", filters.get(FilterConstants.SEQUENTIAL_NUMBER), params); createQuery(whereBuffer, "a.seqNo", filters.get(FilterConstants.SEQUENTIAL_NUMBER), params);
createQuery(whereBuffer, "a.orgCty", filters.get(FilterConstants.ORGCTY_ISO3), params); createQuery(whereBuffer, "a.orgCty", filters.get(FilterConstants.ORGCTY_ISO3), params);
createQuery(whereBuffer, "a.instCode", filters.get(FilterConstants.INSTCODE), 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, "faocty.code3", filters.get(FilterConstants.INSTITUTE_COUNTRY_ISO3), params);
createQuery(whereBuffer, "a.inSGSV", filters.get(FilterConstants.SGSV), params); createQuery(whereBuffer, "a.inSGSV", filters.get(FilterConstants.SGSV), params);
createQuery(whereBuffer, "a.mlsStat", filters.get(FilterConstants.MLSSTATUS), params); createQuery(whereBuffer, "a.mlsStat", filters.get(FilterConstants.MLSSTATUS), params);
......
...@@ -57,7 +57,7 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer; ...@@ -57,7 +57,7 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
/** /**
* Converts filter requests (usually JSON) to internal data structures * Converts filter requests (usually JSON) to internal data structures
* *
* @author matijaobreza * @author Matija Obreza
* *
*/ */
@Component @Component
...@@ -66,8 +66,6 @@ public class FilterHandler { ...@@ -66,8 +66,6 @@ public class FilterHandler {
@Autowired @Autowired
private TraitService traitService; private TraitService traitService;
@Autowired
private ObjectMapper objectMapper;
private final ArrayList<GenesysFilter> availableFilters; private final ArrayList<GenesysFilter> availableFilters;
...@@ -81,6 +79,7 @@ public class FilterHandler { ...@@ -81,6 +79,7 @@ public class FilterHandler {
this.availableFilters = new ArrayList<GenesysFilter>(); this.availableFilters = new ArrayList<GenesysFilter>();
this.availableFilters.add(new BasicFilter(FilterConstants.CROPS, DataType.STRING)); 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 BasicFilter(FilterConstants.LISTS, DataType.STRING));
this.availableFilters.add(new I18nListFilter<Integer>(FilterConstants.SAMPSTAT, DataType.NUMERIC).build("accession.sampleStatus", new Integer[] { 100, this.availableFilters.add(new I18nListFilter<Integer>(FilterConstants.SAMPSTAT, DataType.NUMERIC).build("accession.sampleStatus", new Integer[] { 100,
......
...@@ -33,16 +33,11 @@ import java.util.Map; ...@@ -33,16 +33,11 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import javax.persistence.EntityManager; 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.CollectionUtils;
import org.apache.commons.collections4.Predicate; import org.apache.commons.collections4.Predicate;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
...@@ -127,6 +122,10 @@ import org.springframework.transaction.annotation.Isolation; ...@@ -127,6 +122,10 @@ import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import com.opencsv.CSVWriter;
import com.opencsv.ResultSetHelper;
import com.opencsv.ResultSetHelperService;
@Service @Service
@Transactional(readOnly = true) @Transactional(readOnly = true)
public class GenesysServiceImpl implements GenesysService, DatasetService { public class GenesysServiceImpl implements GenesysService, DatasetService {
...@@ -208,6 +207,7 @@ 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.SPECIES);
columnList.add("taxonomy." + Api1Constants.Taxonomy.SUBTAXA); columnList.add("taxonomy." + Api1Constants.Taxonomy.SUBTAXA);
columnList.add(Api1Constants.Accession.CROP_NAMES); columnList.add(Api1Constants.Accession.CROP_NAMES);
columnList.add(Api1Constants.Accession.CROPNAME);
columnList.add(Api1Constants.Accession.ORIGCTY); columnList.add(Api1Constants.Accession.ORIGCTY);
columnList.add(Api1Constants.Accession.SAMPSTAT); columnList.add(Api1Constants.Accession.SAMPSTAT);
columnList.add("institute." + Api1Constants.Institute.INSTCODE); columnList.add("institute." + Api1Constants.Institute.INSTCODE);
...@@ -358,7 +358,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -358,7 +358,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
if (all.accession.getCrop() != null) { if (all.accession.getCrop() != null) {
ad.crops(all.accession.getCrop().getShortName()); ad.crops(all.accession.getCrop().getShortName());
} else { } else {
ad.crops(cropService.getCrops(all.accession.getTaxonomy())); // Ignore taxonomy crops: ad.crops(cropService.getCrops(all.accession.getTaxonomy()));
} }
return ad; return ad;
} }
...@@ -628,6 +628,11 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -628,6 +628,11 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
return traitValueRepository.getValues(metadata, methods, accessions); return traitValueRepository.getValues(metadata, methods, accessions);
} }
@Override
public Page<Object[]> statisticsCropNameByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsCropNameInInstitute(institute, pageable);
}
@Override @Override
public Page<Object[]> statisticsGenusByInstitute(FaoInstitute institute, Pageable pageable) { public Page<Object[]> statisticsGenusByInstitute(FaoInstitute institute, Pageable pageable) {
return accessionRepository.statisticsGenusInInstitute(institute, pageable); return accessionRepository.statisticsGenusInInstitute(institute, pageable);
...@@ -740,7 +745,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -740,7 +745,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public List<Accession> saveAccessions(Iterable<Accession> accessions) { public List<Accession> saveAccessions(Iterable<Accession> accessions) {
Set<FaoInstitute> institutes = new HashSet<FaoInstitute>(); Set<FaoInstitute> institutes = new HashSet<FaoInstitute>();
for (Accession accession : accessions) { 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()); institutes.add(accession.getInstitute());
} }
List<Accession> res = accessionRepository.save(accessions); List<Accession> res = accessionRepository.save(accessions);
...@@ -1790,17 +1795,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -1790,17 +1795,14 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
genesysLowlevelRepository.updateAccessionSequentialNumber(batch); genesysLowlevelRepository.updateAccessionSequentialNumber(batch);
} }
@Override
public Stream<Accession> streamWithCropname() {
return accessionRepository.streamWithCropname();
}
@Override @Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW) @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
// @PreAuthorize("hasRole('ADMINISTRATOR')") // @PreAuthorize("hasRole('ADMINISTRATOR')")
public List<Accession> saveAccessionCrops(ArrayList<Accession> accessions) { public List<Accession> saveAccessionCrops(ArrayList<Long> accessionIds) {
for (Accession accession : accessions) List<Accession> accessions = new ArrayList<>(accessionRepository.findAll(accessionIds));
for (Accession accession : accessions) {
accessionRepository.updateCrop(accession, cropService.getCrop(accession.getCropName())); accessionRepository.updateCrop(accession, cropService.getCrop(accession.getCropName()));
}
return accessions; return accessions;
} }
} }
...@@ -20,9 +20,8 @@ import org.springframework.stereotype.Component; ...@@ -20,9 +20,8 @@ import org.springframework.stereotype.Component;
import com.hazelcast.core.IQueue; import com.hazelcast.core.IQueue;
/** /**
* ES Processor component uses Spring's @Scheduled annotation to scan queues * ES Processor component uses Spring's @Scheduled annotation to scan queues with 2000ms delay measured from the
* with 2000ms delay measured from the completion time of each preceding * completion time of each preceding invocation.
* invocation.
*/ */
@Component @Component
class ElasticUpdaterProcessor { class ElasticUpdaterProcessor {
...@@ -92,8 +91,7 @@ class ElasticUpdaterProcessor { ...@@ -92,8 +91,7 @@ class ElasticUpdaterProcessor {
} }
if (LOG.isInfoEnabled() && (i % 500 == 0)) { if (LOG.isInfoEnabled() && (i % 500 == 0)) {
LOG.info("Queue size update=" + elasticUpdateQueue.size() + " indexed=" + i + " rate=" + (1000.0 * i / (stopWatch.getTime())) LOG.info("Queue size update=" + elasticUpdateQueue.size() + " indexed=" + i + " rate=" + Math.round(1000.0 * i / (stopWatch.getTime())) + " records/s");
+ " records/s");
} }
} while (toUpdate != null); } while (toUpdate != null);
......
...@@ -16,11 +16,14 @@ ...@@ -16,11 +16,14 @@
package org.genesys2.server.servlet.controller; package org.genesys2.server.servlet.controller;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.elasticsearch.common.lang3.StringUtils; import org.elasticsearch.common.lang3.StringUtils;
import org.genesys2.server.model.impl.Crop; 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.model.impl.CropTaxonomy;
import org.genesys2.server.service.ContentService; import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService; import org.genesys2.server.service.CropService;
...@@ -43,6 +46,12 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -43,6 +46,12 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; 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 @Controller
@RequestMapping("/c") @RequestMapping("/c")
public class CropController extends BaseController { public class CropController extends BaseController {
...@@ -100,6 +109,11 @@ public class CropController extends BaseController { ...@@ -100,6 +109,11 @@ public class CropController extends BaseController {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasPermission(#crop, 'ADMINISTRATION')") @PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasPermission(#crop, 'ADMINISTRATION')")
public String edit(ModelMap model, @PathVariable(value = "shortName") String shortName) { public String edit(ModelMap model, @PathVariable(value = "shortName") String shortName) {
view(model, shortName); view(model, shortName);
try {
model.addAttribute("cropRulesJson", new ObjectMapper().writeValueAsString(model.get("cropRules")));
} catch (JsonProcessingException e) {
}
return "/crop/edit"; return "/crop/edit";
} }
...@@ -117,7 +131,7 @@ public class CropController extends BaseController { ...@@ -117,7 +131,7 @@ public class CropController extends BaseController {
return "/crop/edit"; 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, 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) { @RequestParam("blurp") String aboutBody, @RequestParam(value = "summary", required = false) String summary) {
...@@ -132,7 +146,7 @@ public class CropController extends BaseController { ...@@ -132,7 +146,7 @@ public class CropController extends BaseController {
return "redirect:/c/" + shortName; 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) { public String updateOtherNames(ModelMap model, @PathVariable(value = "shortName") String shortName, @RequestParam("otherNames") String otherNames) {
_logger.debug("Updating crop aliases for " + shortName); _logger.debug("Updating crop aliases for " + shortName);
...@@ -147,6 +161,37 @@ public class CropController extends BaseController { ...@@ -147,6 +161,37 @@ public class CropController extends BaseController {
return edit(model, shortName); 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") @RequestMapping("/{shortName}/ajax/taxonomies")
public String ajaxTaxonomies(ModelMap model, @PathVariable(value = "shortName") String shortName, public String ajaxTaxonomies(ModelMap model, @PathVariable(value = "shortName") String shortName,
@RequestParam(value = "page", required = false, defaultValue = "1") int page) { @RequestParam(value = "page", required = false, defaultValue = "1") int page) {
......
...@@ -135,8 +135,7 @@ public class WiewsController extends BaseController { ...@@ -135,8 +135,7 @@ public class WiewsController extends BaseController {
{ {
AppliedFilters instituteFilter = new AppliedFilters(); AppliedFilters instituteFilter = new AppliedFilters();
instituteFilter.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue( instituteFilter.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
try { try {
model.addAttribute("statisticsCrops", elasticService.termStatisticsAuto(instituteFilter, FilterConstants.CROPS, 5)); model.addAttribute("statisticsCrops", elasticService.termStatisticsAuto(instituteFilter, FilterConstants.CROPS, 5));
...@@ -144,6 +143,7 @@ public class WiewsController extends BaseController { ...@@ -144,6 +143,7 @@ public class WiewsController extends BaseController {
_logger.warn(e.getMessage()); _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("statisticsGenus", genesysService.statisticsGenusByInstitute(faoInstitute, new PageRequest(0, 5)));
model.addAttribute("statisticsTaxonomy", genesysService.statisticsSpeciesByInstitute(faoInstitute, new PageRequest(0, 5))); model.addAttribute("statisticsTaxonomy", genesysService.statisticsSpeciesByInstitute(faoInstitute, new PageRequest(0, 5)));
model.addAttribute("statisticsPDCI", statisticsService.statisticsPDCI(faoInstitute)); model.addAttribute("statisticsPDCI", statisticsService.statisticsPDCI(faoInstitute));
...@@ -155,6 +155,16 @@ public class WiewsController extends BaseController { ...@@ -155,6 +155,16 @@ public class WiewsController extends BaseController {
return "/wiews/details"; 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) @RequestMapping(value = "/{wiewsCode}/stat-genus", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody @ResponseBody
public List<Object[]> getGenusStats(@PathVariable(value = "wiewsCode") String wiewsCode) { public List<Object[]> getGenusStats(@PathVariable(value = "wiewsCode") String wiewsCode) {
...@@ -196,9 +206,8 @@ public class WiewsController extends BaseController { ...@@ -196,9 +206,8 @@ public class WiewsController extends BaseController {
@RequestMapping("/{wiewsCode}/update") @RequestMapping("/{wiewsCode}/update")
public String update(ModelMap model, @PathVariable(value = "wiewsCode") String wiewsCode, @RequestParam("blurp") String aboutBody, 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,