RelationalGroup group = new RelationalGroup(); group.addField( "filename" ); GroupDataBody groupData = new GroupDataBody(); ItemBand itemBand = new ItemBand(); itemBand.setLayout( BandStyleKeys.LAYOUT_AUTO ); groupData.setItemBand( itemBand ); group.setBody( groupData ); report.setRootGroup( group );
/** * Returns the group fields as array. * * @return the fields as string array. */ public String[] getFieldsArray() { final Object o = getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.GROUP_FIELDS ); if ( o instanceof String[] ) { final String[] fields = (String[]) o; return fields.clone(); } return EMPTY_FIELDS; }
@Deprecated public GroupDataBody findGroupDataBody() { final GroupBody body = getBody(); if ( body instanceof GroupDataBody ) { return (GroupDataBody) body; } if ( body instanceof SubGroupBody ) { final SubGroupBody groupBody = (SubGroupBody) body; final Group group = groupBody.getGroup(); if ( group instanceof RelationalGroup ) { final RelationalGroup rg = (RelationalGroup) group; return rg.findGroupDataBody(); } } return null; }
rootGroup = new RelationalGroup(); innerGroup = rootGroup; headerPrinted = false; final RelationalGroup g = new RelationalGroup(); g.addField( groupDefinition.getGroupField() ); g.setName( computeGroupName( groupDefinition ) ); configureGroupHeader( groupDefinition, g, headerPrinted ); configureGroupFooter( groupDefinition, g, headerPrinted ); innerGroup.setBody( new SubGroupBody( g ) ); final GroupDataBody body = (GroupDataBody) innerGroup.getBody(); final ItemBand band = body.getItemBand(); band.setLayout( "row" );
public void testMethods() { final RelationalGroup g = new RelationalGroup(); try { g.setHeader( null ); fail(); } catch ( NullPointerException npe ) { // expected, ignored } try { g.setFooter( null ); fail(); } catch ( NullPointerException npe ) { // expected, ignored } try { g.addField( null ); fail(); } catch ( NullPointerException npe ) { // expected, ignored } }
/** * Starts parsing. * * @param attrs * the attributes. * @throws org.xml.sax.SAXException * if there is a parsing error. */ protected void startParsing( final PropertyAttributes attrs ) throws SAXException { final String groupName = attrs.getValue( getUri(), GroupReadHandler.NAME_ATT ); if ( groupName != null ) { final AbstractReportDefinition report = (AbstractReportDefinition) getRootHandler().getHelperObject( ReportParserUtil.HELPER_OBJ_REPORT_NAME ); final Group maybeDefaultGroup = report.getGroupByName( groupName ); if ( maybeDefaultGroup instanceof RelationalGroup ) { group = (RelationalGroup) maybeDefaultGroup; } else { group = new RelationalGroup(); group.setName( groupName ); group.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.SOURCE, getRootHandler().getSource() ); } } else { group = new RelationalGroup(); group.setAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.SOURCE, getRootHandler().getSource() ); } }
/** * Done parsing. * * @throws SAXException * if there is a parsing error. */ protected void doneParsing() throws SAXException { super.doneParsing(); final RelationalGroup group = getElement(); if ( fieldsReadHandler != null ) { final String[] fields = fieldsReadHandler.getFields(); group.setFields( Arrays.asList( fields ) ); } if ( headerReadHandler != null ) { group.setHeader( headerReadHandler.getElement() ); } if ( footerReadHandler != null ) { group.setFooter( footerReadHandler.getElement() ); } if ( subGroupBodyReadHandler != null ) { group.setBody( subGroupBodyReadHandler.getElement() ); } else if ( dataBodyReadHandler != null ) { group.setBody( dataBodyReadHandler.getElement() ); } }
public ReportElement create() { return new RelationalGroup(); } }
@Before public void setUp() { group = new RelationalGroup(); assertThat( group.getElementType(), is( instanceOf( RelationalGroupType.class ) ) ); assertThat( group.getHeader(), is( notNullValue() ) ); assertThat( group.getFooter(), is( notNullValue() ) ); }
writer.writeTag( ExtParserModule.NAMESPACE, ReportDescriptionWriter.GROUP_TAG, "name", g.getName(), XmlWriterSupport.OPEN ); final List fields = g.getFields(); if ( fields.isEmpty() == false ) { writer.writeTag( ExtParserModule.NAMESPACE, ReportDescriptionWriter.FIELDS_TAG, XmlWriterSupport.OPEN ); writeRootBand( ReportDescriptionWriter.GROUP_HEADER_TAG, g.getHeader() ); writeRootBand( ReportDescriptionWriter.GROUP_FOOTER_TAG, g.getFooter() );
AggregateFieldPreProcessor afpp = Mockito.spy( AggregateFieldPreProcessor.class ); Element element = new Element(); RelationalGroup group = Mockito.spy( new RelationalGroup() ); group.setName( "a" ); GroupDataBody groupBody = new GroupDataBody(); ItemBand ib = new ItemBand(); ib.addElement( element ); groupBody.setElementAt(1, ib ); group.setElementAt(1, groupBody ); section.setElementAt( 2, group ); SubReport result = afpp.performPreProcessing( section, fc ); Mockito.verify( group, Mockito.times( 1 ) ).getGeneratedName(); String name = ( (ItemSumFunction) result.getExpressions().getExpression( 0 ) ).getGroup(); Assert.assertEquals( name, group.getGeneratedName() ); } catch ( Exception e ) { e.printStackTrace();
private static RelationalGroup createGroup( String name, String[] fields ) { final RelationalGroup group = new RelationalGroup(); group.setFields( Arrays.asList( fields ) ); group.setName( name ); return group; }
@Test public void testSetElementAt() { GroupHeader header = mock( GroupHeader.class ); SubGroupBody body = mock( SubGroupBody.class ); GroupFooter footer = mock( GroupFooter.class ); group.setElementAt( 0, header ); group.setElementAt( 1, body ); group.setElementAt( 2, footer ); assertThat( group.getHeader(), is( equalTo( header ) ) ); assertThat( (SubGroupBody) group.getBody(), is( equalTo( body ) ) ); assertThat( group.getFooter(), is( equalTo( footer ) ) ); }
@Test public void testEquals() { assertThat( group.equals( group ), is( equalTo( true ) ) ); assertThat( group.equals( mock( GroupDataBody.class ) ), is( equalTo( false ) ) ); RelationalGroup nextGroup = new RelationalGroup(); assertThat( group.equals( nextGroup ), is( equalTo( true ) ) ); nextGroup.addField( "test_field" ); assertThat( group.equals( nextGroup ), is( equalTo( false ) ) ); }
/** * Returns a string representation of the group (useful for debugging). * * @return A string. */ public String toString() { final StringBuilder b = new StringBuilder( 120 ); b.append( "org.pentaho.reporting.engine.classic.core.RelationalGroup={Name='" ); b.append( getName() ); b.append( "', GeneratedName=" ); b.append( getGeneratedName() ); b.append( "', fields=" ); b.append( getFields() ); b.append( "} " ); return b.toString(); }
@Test public void testSetFields() { List<String> fields = new ArrayList<String>(); fields.add( "test_field" ); group.setFields( fields ); assertThat( (String[]) group.getAttribute( AttributeNames.Core.NAMESPACE, AttributeNames.Core.GROUP_FIELDS ), is( equalTo( new String[] { "test_field" } ) ) ); assertThat( group.getFields(), is( equalTo( fields ) ) ); }
/** * Writes the footer of the current group. * * @param event * the event. */ public void groupFinished( final ReportEvent event ) { if ( event.getState().isPrepareRun() ) { return; } try { final Group g = event.getReport().getGroup( event.getState().getCurrentGroupIndex() ); if ( g instanceof RelationalGroup ) { RelationalGroup rg = (RelationalGroup) g; w.write( "<groupfooter name=\"" ); w.write( entityParser.encodeEntities( g.getName() ) ); w.write( "\">" ); writeBand( rg.getFooter() ); w.write( "</groupfooter>" ); } } catch ( IOException ioe ) { XMLWriter.logger.error( "Error writing the band", ioe ); } }