Commit 2753976a authored by Matija Obreza's avatar Matija Obreza

Load AccessionAliases once per accession

parent 49722744
......@@ -483,6 +483,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updateAccessionAliases(donorNumbs, AliasType.DONORNUMB, true);
updateAccessionAliases(collNumbs, AliasType.COLLNUMB, false);
LOG.info("Done saving data");
return toSave.size() > 0 || toSaveColl.size() > 0 || toSaveGeo.size() > 0 || toSaveBreed.size() > 0 || toSaveExch.size() > 0;
}
......@@ -803,12 +804,15 @@ public class BatchRESTServiceImpl implements BatchRESTService {
* Convert to {@link AccessionAlias}
*
* @param acceNames
* @param existingAliases
*/
private void updateAccessionAliases(Map<Accession, ArrayNode> acceNames, AliasType aliasType, boolean splitInstCode) {
final List<AccessionAlias> toSave = new ArrayList<AccessionAlias>();
final List<AccessionAlias> toRemove = new ArrayList<AccessionAlias>();
for (final Accession accession : acceNames.keySet()) {
final List<AccessionAlias> existingAliases = genesysService.listAccessionAliases(accession);
final ArrayNode acceName = acceNames.get(accession);
final List<AccessionAliasJson> aliases = new ArrayList<AccessionAliasJson>();
if (acceName != null) {
......@@ -829,7 +833,8 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
}
upsertAccessionAliases(accession, aliases, aliasType, toRemove, toSave);
// upsert aliases (send in a copy of the existing aliases list)
upsertAccessionAliases(accession, aliases, aliasType, toRemove, toSave, new ArrayList<AccessionAlias>(existingAliases));
}
if (toSave.size() > 0) {
......@@ -872,7 +877,8 @@ public class BatchRESTServiceImpl implements BatchRESTService {
// LOG.info("Updating " + dataJson + " with=" + dataJson.aliases);
final List<AccessionAliasJson> aliases = dataJson.aliases;
upsertAccessionAliases(accession, aliases, null, toRemove, toSave);
final List<AccessionAlias> existingAliases = genesysService.listAccessionAliases(accession);
upsertAccessionAliases(accession, aliases, null, toRemove, toSave, existingAliases);
}
if (toSave.size() > 0) {
......@@ -887,8 +893,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
private void upsertAccessionAliases(Accession accession, List<AccessionAliasJson> aliases, final AliasType aliasType, List<AccessionAlias> toRemove,
List<AccessionAlias> toSave) {
final List<AccessionAlias> existingAliases = genesysService.listAccessionAliases(accession);
List<AccessionAlias> toSave, Iterable<AccessionAlias> existingAliases) {
// Allows us to focus only on a particular alias type
if (aliasType != null) {
......
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