// Normally it is always sent to the base bill and broadcasted to amendments
// In our 2009 data set we are missing tons of base amendments and it actually
// needs to be broadcasted backwards to the original bill.
// Make sure we are in the amendment list and that if we are active, that no one else is
for (String versionKey : bill.getAmendments()) {
Bill billVersion = storage.getBill(versionKey);
if (!billVersion.getAmendments().contains(bill.getBillId())) {
billVersion.addAmendment(bill.getBillId());
}
if (bill.isActive()) {
billVersion.setActive(false);
}
billVersion.setSponsor(bill.getSponsor());
billVersion.setCoSponsors(bill.getCoSponsors());
billVersion.setOtherSponsors(bill.getOtherSponsors());
billVersion.setMultiSponsors(bill.getMultiSponsors());
billVersion.setLawSection(bill.getLawSection());
billVersion.setLaw(bill.getLaw());
billVersion.setSummary(bill.getSummary());
storage.set(billVersion);
ChangeLogger.record(storage.key(billVersion), storage);
}
if (bill.isUniBill()) {
// Uni bills share text, always sent to the senate bill.
Bill uniBill = storage.getBill(bill.getSameAs());
if (uniBill != null) {
String billText = bill.getFulltext();
String uniBillText = uniBill.getFulltext();
if (billText.isEmpty()) {
if (!uniBillText.isEmpty()) {
// if we are empty then we must need their text
bill.setFulltext(uniBillText);
}
}
else if (!billText.equals(uniBillText)) {
// If we differ, then we must have just changed, share the text
uniBill.setFulltext(bill.getFulltext());
}
storage.set(uniBill);
}
}
storage.set(bill);
ChangeLogger.record(storage.key(bill), storage);
}
else {
// When saving an unpublished bill make sure that references to it are removed
// from other bills and find a new bill to make active.
List<String> amendments = bill.getAmendments();
if (amendments.size() > 0) {
// This assumes that the last amendment on the list is the most recent one.
// TODO: In rare cases with multiple substitutions this might not be the right thing to do!
String newActiveBill = amendments.get(amendments.size()-1);
// Remove all references to the unpublished bill from other versions.
for (String versionKey : bill.getAmendments()) {
Bill billVersion = storage.getBill(versionKey);
billVersion.removeAmendment(bill.getBillId());
if (bill.isActive() && versionKey.equals(newActiveBill)) {
billVersion.setActive(true);
}
storage.set(billVersion);
ChangeLogger.record(storage.key(billVersion), storage);
}
}