def install_side_effect_var(root): side_effect_var = etree.Element(JR + 'parameter', name=_SIDE_EFFECT_VAR_NAME, isForPrompting='false') side_effect_var.set('class', 'java.util.List') var_expr = etree.SubElement(side_effect_var, JR + 'defaultValueExpression') var_expr.text = etree.CDATA('[]') insert_element(root, side_effect_var) crosstab_propagator = etree.Element(JR + 'crosstabParameter', name=_SIDE_EFFECT_VAR_NAME) crosstab_propagator.set('class', 'java.util.List') expr = etree.SubElement(crosstab_propagator, JR + 'parameterValueExpression') expr.text = etree.CDATA('$P{%s}' % _SIDE_EFFECT_VAR_NAME) for crosstab in root.xpath("//jr:crosstab", namespaces=JRXML_NS): insert_element(crosstab, deepcopy(crosstab_propagator))
def transform_jrxml_make_crosstab(jrxml, jrxml_opts): if not jrxml_opts.transform_to_crosstab: return root = jrxml.getroot() crosstab_ids = set( map( lambda prop_el: int( re.sub(PROPERTY_KEY + r'(\d+).+', r'\1', prop_el.get('name'))), root.xpath("./jr:property[starts-with(@name, '" + PROPERTY_KEY + "')]", namespaces=JRXML_NS))) if len(crosstab_ids) == 0: return crosstabs = [] for crosstab_id in crosstab_ids: crosstabs.append(Crosstab(crosstab_id, root)) # Set the stage for query_string in root.xpath("./jr:queryString", namespaces=JRXML_NS): root.remove(query_string) for field in root.xpath("./jr:field", namespaces=JRXML_NS): root.remove(field) for column_header in root.xpath("./jr:columnHeader", namespaces=JRXML_NS): root.remove(column_header) for detail in root.xpath("./jr:detail", namespaces=JRXML_NS): root.remove(detail) query_string = etree.Element(JR + 'queryString') query_string.text = etree.CDATA( 'SELECT * FROM UNNEST(ARRAY[0]) database_connection_opener') insert_element(root, query_string) detail = etree.Element(JR + 'detail') insert_element(root, detail) # Insert the crosstabs for crosstab in crosstabs: insert_element(root, crosstab.crosstab_dataset) band = etree.SubElement(detail, JR + 'band', height=('%d' % crosstab.crosstab_header_height), splitType='Immediate') if crosstab.crosstab_print_when_expr: print_when_expr = etree.SubElement(band, JR + 'printWhenExpression') print_when_expr.text = etree.CDATA( crosstab.crosstab_print_when_expr) band.append(crosstab.crosstab)
def transform_jrxml_make_crosstab(jrxml, jrxml_opts): if not jrxml_opts.transform_to_crosstab: return root = jrxml.getroot() crosstab_ids = set(map(lambda prop_el: int(re.sub(PROPERTY_KEY + r'(\d+).+', r'\1', prop_el.get('name'))), root.xpath("./jr:property[starts-with(@name, '" + PROPERTY_KEY + "')]", namespaces=JRXML_NS))) if len(crosstab_ids) == 0: return crosstabs = [] for crosstab_id in crosstab_ids: crosstabs.append(Crosstab(crosstab_id, root)) # Set the stage for query_string in root.xpath("./jr:queryString", namespaces=JRXML_NS): root.remove(query_string) for field in root.xpath("./jr:field", namespaces=JRXML_NS): root.remove(field) for column_header in root.xpath("./jr:columnHeader", namespaces=JRXML_NS): root.remove(column_header) for detail in root.xpath("./jr:detail", namespaces=JRXML_NS): root.remove(detail) query_string = etree.Element(JR + 'queryString') query_string.text = etree.CDATA('SELECT * FROM UNNEST(ARRAY[0]) database_connection_opener') insert_element(root, query_string) detail = etree.Element(JR + 'detail') insert_element(root, detail) # Insert the crosstabs for crosstab in crosstabs: insert_element(root, crosstab.crosstab_dataset) band = etree.SubElement(detail, JR + 'band', height=('%d' % crosstab.crosstab_header_height), splitType='Immediate') if crosstab.crosstab_print_when_expr: print_when_expr = etree.SubElement(band, JR + 'printWhenExpression') print_when_expr.text = etree.CDATA(crosstab.crosstab_print_when_expr) band.append(crosstab.crosstab)