Commit b4cb5c55 authored by Matija Obreza's avatar Matija Obreza

Hot fixes for production

- Fixed error handling blank filter array in AppliedFiltersConverter
- Accession: Trim #cropName and update #crop
- Institute details: Crop statistics using active accessions
parent 6e69fe21
......@@ -95,6 +95,7 @@ import org.springframework.web.util.UriUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.collect.Sets;
@Controller
@Scope("request")
......@@ -184,11 +185,12 @@ public class WiewsController extends BaseController {
model.addAttribute("datasetCount", datasetCount);
{
AppliedFilters instituteFilter = new AppliedFilters();
instituteFilter.add(new AppliedFilter().setFilterName(FilterConstants.INSTCODE).addFilterValue(new FilterHandler.LiteralValueFilter(faoInstitute.getCode())));
AccessionFilter af=new AccessionFilter();
af.holder().code = Sets.newHashSet(faoInstitute.getCode());
af.historic = false;
try {
model.addAttribute("statisticsCrops", elasticService.termStatisticsAuto(Accession.class, AccessionFilter.convert(instituteFilter), 5, AppliedFiltersConverter
model.addAttribute("statisticsCrops", elasticService.termStatisticsAuto(Accession.class, af, 5, AppliedFiltersConverter
.convertTerm(FilterConstants.CROPS)));
} catch (SearchException e) {
LOG.warn(e.getMessage());
......
......@@ -8,6 +8,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
......@@ -240,11 +241,19 @@ public class AppliedFiltersConverter {
}
private static String take1String(AppliedFilter af) {
return (String) ((LiteralValueFilter) af.getValues().iterator().next()).getValue();
try {
return (String) ((LiteralValueFilter) af.getValues().iterator().next()).getValue();
} catch (NoSuchElementException e) {
return null;
}
}
private static Number take1Number(AppliedFilter af) {
return (Number) ((LiteralValueFilter) af.getValues().iterator().next()).getValue();
try {
return (Number) ((LiteralValueFilter) af.getValues().iterator().next()).getValue();
} catch (NoSuchElementException e) {
return null;
}
}
private static Set<Integer> toIntegerSet(AppliedFilter af) {
......
......@@ -45,6 +45,7 @@ import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionRepository;
import org.genesys2.server.persistence.FaoInstituteRepository;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.worker.AccessionOpResponse.UpsertResult;
......@@ -94,6 +95,9 @@ public class AccessionUploader implements InitializingBean {
@Autowired
private GeoService geoService;
@Autowired
private CropService cropService;
private static final String[] ACCESSIONID_FIELDS = { "breederCode", "storage", "duplSite" };
@Override
......@@ -247,6 +251,9 @@ public class AccessionUploader implements InitializingBean {
} else if ("acceName".equals(fieldName) || "otherNumb".equals(fieldName)) {
updateAliases(fieldName, update.get(fieldName), accession.getAccessionId());
} else if ("cropName".equals(fieldName)) {
updateCrop(update.get(fieldName), accession);
} else if (ArrayUtils.contains(ACCESSIONID_FIELDS, fieldName)) {
try {
copy(AccessionId.class, updateA.getAccessionId(), accession.getAccessionId(), Iterators.forArray(fieldName));
......@@ -265,6 +272,16 @@ public class AccessionUploader implements InitializingBean {
return accession;
}
private void updateCrop(JsonNode jsonNode, Accession accession) {
if (jsonNode.isNull()) {
accession.setCropName(null);
accession.setCrop(null);
} else if (jsonNode.isTextual()) {
accession.setCropName(StringUtils.abbreviate(jsonNode.asText(), 100));
accession.setCrop(cropService.getCrop(accession.getCropName()));
}
}
private void updateAliases(String fieldName, JsonNode jsonNode, AccessionId accession) {
if (jsonNode == null) {
return;
......
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