Commit 67e3f2ae authored by Matija Obreza's avatar Matija Obreza
Browse files

Triggers: Accession trigger should not register a conflicting AccessionInvName

- Added check if the name exists before creating a new entry
parent 8a3fa934
......@@ -250,20 +250,38 @@ public class AccessionTriggers implements InitializingBean {
private void recordAccessionNumber(long accessionId, String accessionNumber, String accessionNumberPart1) {
LOG.debug("Registering accession number: {}", accessionNumber);
AccessionInvName invName = new AccessionInvName();
invName.setPlantName(accessionNumber);
invName.setPlantNameRank(1080);
invName.setCategoryCode(CommunityCodeValues.ACCESSION_NAME_TYPE_SITE.value);
invName.setInventory(inventoryRepository.getSystemInventory(new Accession(accessionId)));
var systemInventory = inventoryRepository.getSystemInventory(new Accession(accessionId));
NameGroup nameGroup = null;
if (StringUtils.isNotBlank(accessionNumberPart1)) {
// link it with the name group
NameGroup groupName = nameGroupRepository.findByGroupName(accessionNumberPart1);
LOG.trace("Name group {} {}", accessionNumberPart1, groupName);
invName.setNameGroup(groupName);
nameGroup = nameGroupRepository.findByGroupName(accessionNumberPart1);
LOG.trace("Name group {} {}", accessionNumberPart1, nameGroup);
}
// Check if the name exists
var qAIN = QAccessionInvName.accessionInvName;
var predicate =
// inventory
qAIN.inventory.eq(systemInventory)
// plant name
.and(qAIN.plantName.eq(accessionNumber))
// category code
.and(qAIN.categoryCode.eq(CommunityCodeValues.ACCESSION_NAME_TYPE_SITE.value))
// name group
.and(nameGroup == null ? qAIN.nameGroup.isNull() : qAIN.nameGroup.eq(nameGroup));
if (! accessionInvNameRepository.exists(predicate)) {
AccessionInvName invName = new AccessionInvName();
invName.setPlantName(accessionNumber);
invName.setPlantNameRank(1080);
invName.setCategoryCode(CommunityCodeValues.ACCESSION_NAME_TYPE_SITE.value);
invName.setInventory(systemInventory);
invName.setNameGroup(nameGroup);
var ain = accessionInvNameService.create(invName);
assert(ain != null);
} else {
LOG.trace("Name already exists");
}
var ain = accessionInvNameService.create(invName);
assert(ain != null);
}
private void recordAccessionSpeciesChangesIfNeeded(long accessionId, TaxonomySpecies oldTs, TaxonomySpecies newTs) {
......
Supports Markdown
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