Skip to content

Commit

Permalink
Parse the chamber of bills in calendar supplementals
Browse files Browse the repository at this point in the history
refs #12431
  • Loading branch information
KevinCaseiras committed Mar 6, 2019
1 parent 08b6069 commit a69ab87
Showing 1 changed file with 37 additions and 1 deletion.
@@ -1,10 +1,19 @@
package gov.nysenate.openleg.processor.spotcheck.calendar;

import gov.nysenate.openleg.dao.base.LimitOffset;
import gov.nysenate.openleg.model.base.SessionYear;
import gov.nysenate.openleg.model.bill.BillId;
import gov.nysenate.openleg.model.calendar.CalendarSectionType;
import gov.nysenate.openleg.model.calendar.CalendarSupplemental;
import gov.nysenate.openleg.model.calendar.CalendarSupplementalEntry;
import gov.nysenate.openleg.model.calendar.alert.CalendarAlertFile;
import gov.nysenate.openleg.model.entity.Chamber;
import gov.nysenate.openleg.model.entity.Member;
import gov.nysenate.openleg.model.entity.SessionMember;
import gov.nysenate.openleg.model.search.SearchException;
import gov.nysenate.openleg.model.search.SearchResults;
import gov.nysenate.openleg.service.entity.member.data.MemberService;
import gov.nysenate.openleg.service.entity.member.search.MemberSearchService;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
Expand All @@ -13,6 +22,7 @@
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
Expand All @@ -27,6 +37,9 @@
@Service
public class CalendarAlertSupplementalParser extends BaseCalendarAlertParser {

@Autowired
private MemberService memberService;

private static final Logger logger = LoggerFactory.getLogger(CalendarAlertSupplementalParser.class);

protected CalendarSupplemental parseSupplemental(CalendarAlertFile calFile) throws IOException {
Expand Down Expand Up @@ -66,14 +79,37 @@ private Map<Element, Elements> mapSectionTypeToEntryRows(Elements sectionTypes,
private CalendarSupplementalEntry createSupplementalEntry(CalendarSupplemental supplemental, CalendarSectionType calendarSectionType, Element entryTable) {
Elements columns = entryTable.select("td");
int billCalNo = Integer.valueOf(columns.get(0).text());
String printNo = "S" + columns.get(2).text();
String sponsor = columns.get(1).text();
String billNo = columns.get(2).text();

Chamber chamber = getChamber(supplemental.getSession(), sponsor);
String printNo = chamber.getAbbreviation() + billNo;

BillId billId = new BillId(printNo, supplemental.getSession());
// TODO find examples of these
// BillId subBillId;
// boolean high; // high status is not available in alert emails.
return new CalendarSupplementalEntry(billCalNo, calendarSectionType, billId, null, null);
}

/**
* Attempt to determine the chamber of a supplemental entry bill.
* <p>
* Checks if the sponsor is in the Assembly, if not, or if any errors occur, assume its a Senate bill.
*
* @param sessionYear
* @param sponsor
* @return
*/
private Chamber getChamber(SessionYear sessionYear, String sponsor) {
try {
memberService.getMemberByShortName(sponsor, sessionYear, Chamber.ASSEMBLY);
return Chamber.ASSEMBLY;
} catch (Exception ex) {
return Chamber.SENATE;
}
}

private LocalDate parseCalendarDate(File file) {
try {
String html = FileUtils.readFileToString(file);
Expand Down

0 comments on commit a69ab87

Please sign in to comment.