Commit 13d20ec6 authored by Matija Obreza's avatar Matija Obreza

FaoInstitute#uniqueAcceNumbs: assume false when no records exist in Genesys

parent 1d9532bb
......@@ -163,6 +163,9 @@ public interface AccessionRepository extends JpaRepository<Accession, Long>, Acc
@Modifying
void removeDOIs();
@Query("select count(distinct a.accessionNumber) from Accession a where a.institute.id = ?1")
public long countUniqueAccessionNumbers(long instituteId);
@Query("select count(a.id) - count(distinct a.accessionNumber) from Accession a where a.institute.id = ?1")
public long countNonuniqueAccessionNumbers(long instituteId);
}
......@@ -184,7 +184,14 @@ public class InstituteServiceImpl implements InstituteService {
public List<FaoInstitute> update(final @Valid Collection<FaoInstitute> institutes) {
institutes.forEach(institute -> {
if (institute.getId() != null) {
institute.setUniqueAcceNumbs(0 == accessionRepository.countNonuniqueAccessionNumbers(institute.getId()));
long uniqueAcceNumbs = accessionRepository.countUniqueAccessionNumbers(institute.getId());
if (uniqueAcceNumbs > 0) {
long nonUniqueAcceNumbs = accessionRepository.countNonuniqueAccessionNumbers(institute.getId());
institute.setUniqueAcceNumbs(0 == nonUniqueAcceNumbs);
} else {
// Assume first insert into Genesys may contain duplicates
institute.setUniqueAcceNumbs(false);
}
}
});
return instituteRepository.save(institutes);
......
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