Package gov.nysenate.openleg.model

Examples of gov.nysenate.openleg.model.SOBIBlock


     * @return
     * @throws IOException if file cannot be opened for reading.
     */
    public List<SOBIBlock> getBlocks(File sobiFile) throws IOException
    {
        SOBIBlock block = null;
        List<SOBIBlock> blocks = new ArrayList<SOBIBlock>();
        List<String> lines = FileUtils.readLines(sobiFile);
        lines.add(""); // Add a trailing line to end the last block and remove edge cases

        for(int lineNum = 0; lineNum < lines.size(); lineNum++) {
            // Replace NULL bytes with spaces to properly format lines.
            String line = lines.get(lineNum).replace('\0', ' ');

            // Source file is not assumed to be 100% SOBI so we filter out other lines
            Matcher headerMatcher = SOBIBlock.blockPattern.matcher(line);

            if (headerMatcher.find()) {
                if (block == null) {
                    // No active block with a new matching line: create new block
                    block = new SOBIBlock(sobiFile, lineNum, line);
                }
                else if (block.getHeader().equals(headerMatcher.group()) && block.isMultiline()) {
                    // active multi-line block with a new matching line: extend block
                    block.extend(line);
                }
                else {
                    // active block does not match new line or can't be extended: create new block
                    blocks.add(block);
                    SOBIBlock newBlock = new SOBIBlock(sobiFile, lineNum, line);

                    // Handle certain SOBI grouping edge cases.
                    if (newBlock.getBillHeader().equals(block.getBillHeader())) {
                        // The law code line can be omitted when blank but it always precedes the 'C' line
                        if (newBlock.getType() == 'C' && block.getType() != 'B') {
                            blocks.add(new SOBIBlock(sobiFile, lineNum, block.getBillHeader()+"B"));
                        }
                    }

                    // Start a new block
                    block = newBlock;
View Full Code Here


    private Bill getBill(Storage storage, String billId, int year, String sponsorName) {
        // This is a crappy situation, all bills on calendars should already exist but sometimes they won't.
        // This almost exclusively because we are missing sobi files. It shouldn't happen in production but
        // does frequently in development.
        BillProcessor processor = new BillProcessor();
        SOBIBlock mockBlock = new SOBIBlock(year+billId+(billId.matches("[A-Z]$") ? "" : " ")+1+"     ");
        Bill bill = processor.getOrCreateBill(mockBlock, modifiedDate, storage);

        if (sponsorName != null) {
            String[] sponsors = sponsorName.trim().split(",");
            bill.setSponsor(new Person(sponsors[0].trim()));
View Full Code Here

    private Bill getBill(Storage storage, String billId, int year, String sponsorName) {
        // This is a crappy situation, all bills on calendars should already exist but sometimes they won't.
        // This almost exclusively because we are missing sobi files. It shouldn't happen in production but
        // does frequently in development.
        BillProcessor processor = new BillProcessor();
        SOBIBlock mockBlock = new SOBIBlock(year+billId+(billId.matches("[A-Z]$") ? "" : " ")+1+"     ");
        Bill bill = processor.getOrCreateBill(mockBlock, modifiedDate, storage);

        if (sponsorName != null) {
            String[] sponsors = sponsorName.trim().split(",");
            bill.setSponsor(new Person(sponsors[0].trim()));
View Full Code Here

    public void testGetBlocks() throws IOException
    {
        BillProcessor processor = new BillProcessor();
        List<SOBIBlock> blocks = processor.getBlocks(new File("src/test/resources/BLOCKTEST.txt"));
        Iterator<SOBIBlock> blockIterator = blocks.iterator();
        assertEquals(new SOBIBlock("2013A03006D1Budget              00000"), blockIterator.next());
        assertEquals(new SOBIBlock("2013A03006D1Budget              00000"), blockIterator.next());
        assertEquals(new SOBIBlock("2013A03006D2Budget Bills"), blockIterator.next());
        assertEquals(new SOBIBlock("2013A03006D2Budget Bills"), blockIterator.next());
        assertEquals(new SOBIBlock("2013A03006D5Same As S04643C"), blockIterator.next());
        assertEquals(new SOBIBlock("2013A03006D5Same As S04643C"), blockIterator.next());
        assertEquals(new SOBIBlock("2013A03006D3Amends various provisions of law relating to implementing the health and mental hygiene budget for\n" +
                                                             "the 2013-2014 state fiscal year"),blockIterator.next());
        assertEquals(new SOBIBlock("2013A03006D401/22/13 referred to ways and means\n" +
            "02/13/13 amend and recommit to ways and means\n" +
            "02/13/13 print number 3006a\n" +
            "02/22/13 amend (t) and recommit to ways and means\n" +
            "02/22/13 print number 3006b\n" +
            "03/08/13 amend (t) and recommit to ways and means"),blockIterator.next());
View Full Code Here

TOP

Related Classes of gov.nysenate.openleg.model.SOBIBlock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.