Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Added a check to MetalotServiceImpl to see if newly generated parent …
Browse files Browse the repository at this point in the history
…corpName already exists. If the corpName already exists, the service will now keep generating corpNames and re-checking until it finds a unique one. This replaces logic that only re-tried once and then errored out.
  • Loading branch information
bffrost committed Jan 6, 2018
1 parent 0c6dbe4 commit 8f7a098
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/main/java/com/labsynch/cmpdreg/service/MetalotServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,13 @@ public MetalotReturn processAndSave(Metalot metaLot, MetalotReturn mr, ArrayList

parent.setMolFormula(chemService.getMolFormula(parent.getMolStructure()));
//add unique constraint to parent corp name as well (parent and lot)
try {
logger.debug("Saving new parent with corp name "+parent.getCorpName()+" and parent number "+parent.getParentNumber());
parent.persist();
} catch (Exception e){
logger.error("Caught an exception saving the parent: " + e);
//get a new corp name and try saving again
boolean corpNameAlreadyExists = checkCorpNameAlreadyExists(parent.getCorpName());
while (corpNameAlreadyExists) {
generateAndSetCorpName(parent);
parent.persist();
corpNameAlreadyExists = checkCorpNameAlreadyExists(parent.getCorpName());
}
logger.debug("Saving new parent with corp name "+parent.getCorpName()+" and parent number "+parent.getParentNumber());
parent.persist();
}
}

Expand Down Expand Up @@ -816,6 +814,14 @@ private void generateAndSetCorpName(Parent parent) throws MalformedURLException,
parent.setParentNumber(corpName.getCorpNumber());
}
}

private boolean checkCorpNameAlreadyExists(String corpName) {
if (Parent.countFindParentsByCorpNameEquals(corpName) > 0L){
return true;
}else {
return false;
}
}


}

0 comments on commit 8f7a098

Please sign in to comment.