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

Load AccessionAliases once per accession

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