public void applyVoteMemo(String data, Bill bill, Date date) throws ParseError
{
// TODO: Parse out sequence number once LBDC (maybe) includes it, #6531
// Because sometimes votes are back to back we need to check for headers
// Example of a double vote entry: SOBI.D110119.T140802.TXT:390
Vote vote = null;
for(String line : data.split("\n")) {
Matcher voteHeader = voteHeaderPattern.matcher(line);
if (voteHeader.find()) {
// TODO: this assumes they are the same vote sent twice, what else could happen?
//Start over if we hit a header, sometimes we get back to back entries.
try {
// Use the old vote if we can find it, otherwise make a new one using now as the publish date
vote = new Vote(bill, voteDateFormat.parse(voteHeader.group(2)), Vote.VOTE_TYPE_FLOOR, "1");
vote.setPublishDate(date);
for (Vote oldVote : bill.getVotes()) {
if (oldVote.equals(vote)) {
// If we've received this vote before, use the old publish date
vote.setPublishDate(oldVote.getPublishDate());
break;
}
}
vote.setModifiedDate(date);
} catch (ParseException e) {
throw new ParseError("voteDateFormat not matched: "+line);
}
}
else if (vote!=null){
//Otherwise, build the existing vote
Matcher voteLine = votePattern.matcher(line);
while(voteLine.find()) {
String type = voteLine.group(1).trim();
Person voter = new Person(voteLine.group(2).trim());
if (type.equals("Aye")) {
vote.addAye(voter);
}
else if (type.equals("Nay")) {
vote.addNay(voter);
}
else if (type.equals("Abs")) {
vote.addAbsent(voter);
}
else if (type.equals("Abd")) {
vote.addAbstain(voter);
}
else if (type.equals("Exc")) {
vote.addExcused(voter);
}
else {
throw new ParseError("Unknown vote type found: "+line);
}
}