Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reporting – Sort Orders, Selections, and Related Data TEC02 Brian Ciccolo.

Similar presentations


Presentation on theme: "Reporting – Sort Orders, Selections, and Related Data TEC02 Brian Ciccolo."— Presentation transcript:

1 Reporting – Sort Orders, Selections, and Related Data TEC02 Brian Ciccolo

2 Agenda Navigating the report Java source Determining a report’s “root table” Adding sort order options Adding selection options Adding related data lookup maps

3 Navigating the Report Java Source Before you can customize the Java, you must first understand the Java. Before you can understand the Java, you must first understand its components. ~ Ancient X2 Proverb

4 Copyright Comment /* * ==================================================================== * * X2 Development Corporation * * Copyright (c) 2002-2003 X2 Development Corporation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, is not permitted without a written agreement * from X2 Development Corporation. * * ==================================================================== */

5 Package and Imports package com.x2dev.sis.reports.system; import net.sf.jasperreports.engine.JRDataSource; import org.apache.ojb.broker.query.*; import com.x2dev.sis.model.beans.*; import com.x2dev.sis.model.business.*; import com.x2dev.sis.tools.reports.*; import com.x2dev.sis.web.UserDataContainer;

6 Class Comment /** * Prepares the data for the Student Profile report. This report simple selects * students from the current school (with an optional criteria for YOG or homeroom) * and order the results by YOG, homeroom, or last name. * * @author X2 Development Corporation */

7 Class Definition public class StudentProfileData extends ReportJavaSourceNet { // Bunch of stuff... }

8 Constants /** * Name for the "active only" report parameter. The value is an Boolean. */ public static final String ACTIVE_ONLY_PARAM = "activeOnly"; /** * Name for the enumerated "selection" report parameter. The value is an Integer. */ public static final String QUERY_BY_PARAM = "queryBy"; /** * Name for the "selection value" report parameter. The value is a String. */ public static final String QUERY_STRING_PARAM = "queryString"; /** * Name for the "secondary students" report parameter. The value is a Boolean. */ public static final String SECONDARY_STUDENT_PARAM = "secondaryStudent";

9 Member Variables private Student m_currentStudent;

10 gatherData() /** * @see com.x2dev.sis.tools.reports.ReportJavaSourceDori#gatherData() */ @Override protected JRDataSource gatherData() { // Another bunch of stuff... return new QueryIteratorDataSource(getBroker().getIteratorByQuery(query)); }

11 Other Methods /** * @see com.x2dev.sis.tools.ToolJavaSource# * saveState(com.x2dev.sis.web.UserDataContainer) */ @Override protected void saveState(UserDataContainer userData) { /* * If we're in the context of a single student, print the * report for just that student. */ m_currentStudent = (Student) userData.getCurrentRecord(Student.class); }

12 The gatherData() Formula Declare an instance of the Criteria type Add various filters based on user input Declare an instance of QueryByCriteria Add various sorts based on user input Execute the query and return the results

13 A Report’s “Root Table” Embedded in the “thing” returned at the end of gatherData() Defines what fields are available in the report format Might not be based on an actual table in the database

14 Finding the “Root Table” Guess Become a Java programmer and work at X2 Use heuristics

15 Using Heuristics In the format: Deduce from the fields that have already been defined In the Java source: Examine the return statement in gatherData() o If a QueryIteratorDataSource, find where the query is declared – that’s the root table o If a DataGrid, find where grid.set() is called – those are the fields in the root table

16 Exercise 1: Custom Sort Customize the Student List report by adding an option to sort the results by state ID.

17 Exercise 1, Step 1 <input name="sort" data-type="integer" display-type="select“ display-name="report.shared.sort"> <option value="0" display-name="report.shared.sort.currentSort“ context-dependent="true"/>

18 Exercise 1, Step 2 switch (sort) { case 0: // Current sort applyCurrentSort(query); break; case 1: // Name view query.addOrderByAscending(Student.COL_NAME_VIEW); break; case 2: // YOG query.addOrderByAscending(Student.COL_YOG); query.addOrderByAscending(Student.COL_NAME_VIEW); break; case 3: // Homeroom query.addOrderByAscending(Student.COL_HOMEROOM); query.addOrderByAscending(Student.COL_NAME_VIEW); break; case 4: // State ID query.addOrderByAscending(Student.COL_STATE_ID); query.addOrderByAscending(Student.COL_NAME_VIEW); break; default: // No sort specified break; }

19 Exercise 1, Step 3 Mark custom Compile Java source Save Test

20 Exercise 2: Custom Filter Customize the Student Contacts report by adding an option to filter the results by students’ last name (i.e., only return those students whose last name begins with a user-specified letter).

21 Exercise 2, Step 1 <input name="queryBy" data-type="integer" display-type="select“ display-name="report.shared.query"> <option value="0" display-name="report.shared.query.currentSelection“ context-dependent="true"/>

22 Exercise 2, Step 2 switch (queryBy) { case 0: // Current selection SubQuery subQuery = new SubQuery(Student.class, X2BaseBean.COL_OID, getCurrentCriteria()); criteria.addIn(StudentContact.COL_STUDENT_OID, subQuery); break; case 2: // YOG criteria.addEqualTo(StudentContact.REL_STUDENT + "." + Student.COL_YOG, getParameter(QUERY_STRING_PARAM)); break; case 3: // Homeroom criteria.addEqualTo(Student.COL_HOMEROOM, getParameter(QUERY_STRING_PARAM)); break; case 4: // Last name begins with criteria.addBeginsWithIgnoreCase(Student.COL_NAME_VIEW, getParameter(QUERY_STRING_PARAM)); break; default: // No additional criteria (this is the case for "All") break; }

23 Exercise 2, Step 3 Mark custom Compile Java source Save Test

24 Exercise 3: Related Data Customize the Student List report (again) by displaying the homeroom teacher’s name next to the student’s homeroom number on the format.

25 Adding an Option for “Current Selection” Adding an option to run a report based on the current selection of student records is detailed in knowledge base article K10001099 located in the session folder.

26 Thank you. bciccolo@x2dev.com


Download ppt "Reporting – Sort Orders, Selections, and Related Data TEC02 Brian Ciccolo."

Similar presentations


Ads by Google