Commit bd39b807 authored by Matija Obreza's avatar Matija Obreza

API Fix: accession#taxGenus is still required, accession#crop misbehaving for null

parent 0834c4e8
......@@ -285,6 +285,7 @@ public abstract class AccessionData implements IdUUID, Serializable {
public void setTaxonomy(Taxonomy2 taxonomy2) {
this.taxonomy = taxonomy2;
this.taxGenus = taxonomy2.getTaxGenus();
}
public abstract List<Integer> getStoRage();
......
......@@ -594,18 +594,12 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
final String cropName = StringUtils.trimToNull(value.textValue());
if (!StringUtils.equals(cropName, accession.getCropName()) || accession.getCrop() == null) {
// existing cropName doesn't match or current crop assigned is null
accession.setCropName(cropName);
accession.setCrop(cropService.getCrop(cropName));
return true;
}
accession.setCropName(cropName);
if (StringUtils.isNotBlank(cropName)) {
// has cropName, check if needs updating
Crop newCrop = cropService.getCrop(cropName);
if (accession.getCrop() == null || (newCrop != null && accession.getCrop().getId() != newCrop.getId())) {
if (accession.getCrop() == null || newCrop == null || (newCrop != null && accession.getCrop().getId() != newCrop.getId())) {
accession.setCrop(newCrop);
return true;
}
......
......@@ -81,6 +81,10 @@ public class CropServiceImpl implements CropService {
@Override
@Cacheable(value = CACHE_CROPS, key = "#shortName", unless = "#result == null || #shortName == null")
public Crop getCrop(String shortName) {
if (StringUtils.isBlank(shortName)) {
return null;
}
Crop crop = cropRepository.findByShortName(shortName);
// Find crop by alias when null
......@@ -111,16 +115,15 @@ public class CropServiceImpl implements CropService {
public void updateBlurp(Crop crop, String textBody, String summary, Locale locale) {
contentService.updateArticle(crop, "blurp", null, textBody, summary, locale);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasRole('CONTENTMANAGER') or hasPermission(#crop, 'ADMINISTRATION')")
@Transactional(readOnly = false)
@CacheEvict(value = CACHE_CROPS, allEntries = true)
public Crop updateAliases(Crop crop, List<String> otherNames) {
crop.setOtherNames(otherNames.stream().distinct().map(otherName -> StringUtils.trim(otherName)).filter(otherName -> StringUtils.isNotBlank(otherName))
.sorted().collect(Collectors.toList()));
crop.setOtherNames(otherNames.stream().distinct().map(otherName -> StringUtils.trim(otherName)).filter(otherName -> StringUtils.isNotBlank(otherName)).sorted().collect(Collectors.toList()));
return cropRepository.save(crop);
}
......@@ -135,7 +138,7 @@ public class CropServiceImpl implements CropService {
});
return crops;
}
@Override
public Page<Crop> listCrops(Pageable pageable) {
return cropRepository.findAll(pageable);
......@@ -221,8 +224,7 @@ public class CropServiceImpl implements CropService {
@Override
public boolean evaluate(Taxonomy2 taxonomy) {
if (cr.getSpecies() == null && cr.getSubtaxa() == null) {
return StringUtils.equalsIgnoreCase(taxonomy.getSubtaxa(), cr.getSubtaxa())
&& StringUtils.equalsIgnoreCase(taxonomy.getSpecies(), cr.getSpecies());
return StringUtils.equalsIgnoreCase(taxonomy.getSubtaxa(), cr.getSubtaxa()) && StringUtils.equalsIgnoreCase(taxonomy.getSpecies(), cr.getSpecies());
} else if (cr.getSubtaxa() == null) {
return StringUtils.equalsIgnoreCase(taxonomy.getSpecies(), cr.getSpecies());
} else {
......
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