Commit d31c19ed authored by Matija Obreza's avatar Matija Obreza

Fix: Allow setting Institute#uniqueAcceNumbs to false

- true will still check existing data
parent 36cffdf9
......@@ -39,6 +39,7 @@ import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys.filerepository.service.ImageGalleryService;
import org.genesys2.server.component.security.AsAdminInvoker;
import org.genesys2.server.exception.NotFoundElement;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.QAccession;
import org.genesys2.server.model.genesys.Taxonomy2;
......@@ -161,6 +162,9 @@ public class CropServiceImpl implements CropService {
LOG.debug("Getting crop details for {}", shortName);
StopWatch stopWatch = StopWatch.createStarted();
Crop crop = getCrop(shortName);
if (crop == null) {
throw new NotFoundElement("No crop: " + shortName);
}
LOG.trace("got crop after {}ms", stopWatch.getTime());
Article article = contentService.getArticle(crop, ContentService.ENTITY_BLURB_SLUG, locale);
LOG.trace("got article after {}ms", stopWatch.getTime());
......
......@@ -122,7 +122,10 @@ public class InstituteServiceImpl implements InstituteService {
copyValues(target, institute);
instituteSettingRepository.save(target.getSettings().values());
if (target.isUniqueAcceNumbs()) {
// Assure existing data has unique accenumbs
target.setUniqueAcceNumbs(0 == accessionRepository.countNonuniqueAccessionNumbers(target.getId()));
}
return instituteRepository.save(target);
}
......@@ -191,7 +194,7 @@ public class InstituteServiceImpl implements InstituteService {
@CacheEvict(value = { "statistics", HIBERNATE_CACHENAME }, allEntries = true)
public List<FaoInstitute> update(final @Valid Collection<FaoInstitute> institutes) {
institutes.forEach(institute -> {
if (institute.getId() != null) {
if (institute.getId() != null && institute.isUniqueAcceNumbs()) {
long uniqueAcceNumbs = accessionRepository.countUniqueAccessionNumbers(institute.getId());
if (uniqueAcceNumbs > 0) {
long nonUniqueAcceNumbs = accessionRepository.countNonuniqueAccessionNumbers(institute.getId());
......@@ -219,7 +222,11 @@ public class InstituteServiceImpl implements InstituteService {
public void setUniqueAcceNumbs(FaoInstitute faoInstitute, boolean uniqueAcceNumbs) {
final FaoInstitute inst = instituteRepository.findOne(faoInstitute.getId());
LOG.info("Setting 'uniqueAcceNumbs' to {} for {}", uniqueAcceNumbs, faoInstitute);
inst.setUniqueAcceNumbs(uniqueAcceNumbs);
if (uniqueAcceNumbs == true) {
// If set to unique, test that current data is unique!
inst.setUniqueAcceNumbs(0 == accessionRepository.countNonuniqueAccessionNumbers(inst.getId()));
}
instituteRepository.save(inst);
}
......
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