// cast here is unsafe really
ManageableSecurity loaded = (ManageableSecurity) entry.getValue();
ManageableSecurity original = (ManageableSecurity) originalIds.get(entry.getKey());
if (original == null) {
// security is brand new
SecurityDocument doc = new SecurityDocument(loaded);
SecurityDocument added = _securityMaster.add(doc);
result.put(entry.getKey(), added.getSecurity());
} else {
loaded.setUniqueId(original.getUniqueId()); // normalize IDs for comparison
if (loaded.equals(original)) {
// no change since last loaded, return original with uniqueId
result.put(entry.getKey(), original);
} else {
// loaded is updated from original
SecurityDocument doc = new SecurityDocument(loaded);
SecurityDocument updated = _securityMaster.update(doc);
result.put(entry.getKey(), updated.getSecurity());
}
}
}
return result;
}