logger.error("unable to parse addendum date/time format", pe);
}
}
// Try to retrieve existing addendum and update it
Addendum addendum = new Addendum(addendumId, weekOf, publishDate, agenda.getNumber(), agenda.getYear());
addendum.setAgenda(agenda);
for (Addendum oldAddendum : agenda.getAddendums()) {
if (oldAddendum.getOid().equals(addendum.getOid())) {
addendum = oldAddendum;
addendum.setAgenda(agenda); // Nulled out during serialization.
addendum.setWeekOf(weekOf);
addendum.setPublishDate(publishDate);
break;
}
}
List<Meeting> listMeetings = addendum.getMeetings();
for( XMLCommittee xmlCommMeeting : xmlAddendum.getCommittees().getCommittee()) {
String action = xmlCommMeeting.getAction();
String commName = xmlCommMeeting.getName().getContent();
if (commName == null) {
continue;
}
if (action != null && action.equals("remove")) {
for (Meeting meeting : new ArrayList<Meeting>(listMeetings)) {
if (meeting.getCommitteeName().equals(commName)) {
logger.info("removing meeting: " + meeting.getOid());
// Delete the meeting and save the agenda
String key = storage.key(meeting);
storage.del(key);
ChangeLogger.delete(key, storage);
listMeetings.remove(meeting);
storage.set(agenda);
ChangeLogger.record(storage.key(agenda), storage);
break;
}
}
continue;
}
// If action isn't remove, we should have a date time.
Date meetDateTime = null;
try {
meetDateTime = LRS_DATETIME_FORMAT.parse(xmlCommMeeting.getMeetdate().getContent() + xmlCommMeeting.getMeettime().getContent());
} catch (ParseException e) {
logger.error("Could not parse meeting date", e);
continue;
}
Meeting meeting = new Meeting(commName, meetDateTime);
meeting.setPublishDate(modifiedDate);
String key = storage.key(meeting);
Meeting oldMeeting = (Meeting)storage.get(key, Meeting.class);
if (oldMeeting != null) {
// If we have an old meeting, either use it or delete it if we are replacing.
// This is wrong just like the rest of the meeting stuff. The replace is for
// the addendum entry, you don't know how much to replace.
if (action != null && action.equals("replace")) {
// If we are replacing votes it'll be handled in handleXmlBill
if (!isVote) {
logger.info("removing meeting: " + oldMeeting.getOid());
storage.del(key);
agenda.removeCommitteeMeeting(oldMeeting);
}
}
else {
// Use the old meeting of since it is not null or replaced.
meeting = oldMeeting;
}
}
meeting.setModifiedDate(modifiedDate);
// Add a bunch of meeting meta data
if (xmlCommMeeting.getLocation() != null && xmlCommMeeting.getLocation().getContent().length() > 0) {
meeting.setLocation(xmlCommMeeting.getLocation().getContent());
}
if (xmlCommMeeting.getMeetday() != null && xmlCommMeeting.getMeetday().getContent().length() > 0) {
meeting.setMeetday(xmlCommMeeting.getMeetday().getContent());
}
if (xmlCommMeeting.getNotes() != null && xmlCommMeeting.getNotes().getContent().length() > 0) {
// latin1 encoded
String notes = xmlCommMeeting.getNotes().getContent();
notes = new String(notes.getBytes("CP850"), "latin1");
meeting.setNotes(notes);
}
if (xmlCommMeeting.getChair() != null && xmlCommMeeting.getChair().getContent().length() > 0) {
meeting.setCommitteeChair(xmlCommMeeting.getChair().getContent());
}
if (!listMeetings.contains(meeting)) {
listMeetings.add(meeting);
}
if (xmlCommMeeting.getBills() != null) {
List<Bill> listBills = meeting.getBills();
if (listBills == null) {
listBills = new ArrayList<Bill>();
meeting.setBills(listBills);
}
for(XMLBill xmlBill : xmlCommMeeting.getBills().getBill()) {
Bill bill = handleXMLBill(storage, meeting, xmlBill, addendum.getAgenda().getSession());
if (!listBills.contains(bill)) {
logger.debug("adding bill:" + bill.getBillId() + " to meeting:" + meeting.getOid());
listBills.add(bill);
}
else {
// Since we already have a reference don't do anything. handleXMLBill will update the bill details
}
}
}
storage.set(meeting);
ChangeLogger.record(storage.key(meeting), storage);
}
addendum.setMeetings(listMeetings);
return addendum;
}