Jump to content
Changes to the Jaspersoft community edition download ×

eongaro

Members
  • Posts

    51
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

eongaro's Achievements

Enthusiast

Enthusiast (6/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Collaborator Rare

Recent Badges

0

Reputation

  1. Link to view our Visualize.js API live samples We have developed a new documentation integration with GitHub for our JSFiddles that we hope developers will find useful. Enjoy! Download to view. Visualize.js is a JavaScript API framework used to embed JasperReport Server reports & visualizations inside web applications. It comes bundled with the commercial editions of JasperReports® Server, specifically Jaspersoft AWS, Enterprise or Professional (and as an add-on with Jaspersoft Reporting). Visualize.js currently does not support JasperReports Server Community Edition or the JasperReports® Library. With Visualize.js, developers can embed interactive HTML5 visualizations, dashboards or multi-element reports using standard JavaScript. Developers can quickly and easily call backend JasperReports Server services using REST calls for common functions such as user authentication, data connectivity, repository services and more. About these Examples The source code for these fiddles are hosted on Github. main_1.html main_2.html
  2. IntroductionThis article applies to iReport Designer v5.6.1 and previous versions. It will not work in any version of Jaspersoft Studio or in iReport Designer v6.0.x. The purpose of this article is to describe how to use parameters in queries when using iReport to design a report from a Domain datasource. The article is written for an advanced user of iReport and JasperReports Server to use, it's meant to be more of a primer than a complete document. QueryDomain based queries use the DomEL language to query data. It's not SQL and therefore you can not use the same syntax for parameters, for example, parameters do not need the $P{syntax}, instead the field name is referenced. In the following example, we have a parameter declared in the JRXML called $P{prev_year}, the way to use that parameter is shown below: <query> <queryfields><queryfield id="total_apps"></queryfield></queryfields> <queryfilterstring>newSet2.Year == prev_year</queryfilterstring></query>[/code]CollectionsCollections or sets can be used as well. You can create a parameter that is a collection and put it in the query with the "in" operator. Refer to section 8.2.3 of the JasperReports Server User Guide Also, multi-select input controls can be populated by a Domain based query Populating from the ServerIt is also possible to populate the values of an import control from a query. Typically I would recommend prototyping this using the ad-hoc editor - create a ad-hoc view with a filter on the column you want to use. Create a report from the view and then in iReport you can see how it's set up. Here's one example: <!--?xml version="1.0" encoding="UTF-8"?--><query xmlns="http://www.jaspersoft.com/2007/SL/XMLSchema"> <grouplist> <group columnname="newSet1.region"></group> </grouplist> <queryfields> <queryfield id="newSet1.region"></queryfield> </queryfields></query>[/code]Here's the example in iReport: The "value" and "name field" would come from newSet1.region in this case See AlsoSection 8.2 of the JasperReports Server User Guide discussed the DomEL language in full detailOther Articles about the Domain Expression Language (DomEL)
  3. Issue:[toc on_off::hide=1] Your are trying to add calculated fields to a domain. The calculation involves assessment of another field's value based on a condition or set of conditions. Typically (in code), this is done using if/else format, or ternary statements (condition ? 'value if true' : 'value if false'). How can this be achieved in a domain's calculated field? What is the syntax? Resolution:Conditions can be evaluated in calculated fields using the "if(condition,value if true,value if false)" function in DomEL. In the following example, I am determining the value of the field by evaluating another field's value (currentsuboppts.Amount). If currentsuboppts.Amount is less than or equal to 5000, the value of my field is the string '<=$5k'. Otherwise, it is '>$5k'. if(currentsuboppts.Amount <= 5000,'<=$5k','>$5k') another example using dates: if(time_by_day1.the_date == d'2013-01-07', null, time_by_day1.the_date) NOTE: When entering a string value into a calculated field formula, you must use single quotes ('), NOT double quotes ("). Note on Using GroovyAll expressions should be written in the DomEL language. If you want to use Groovy you will need to wrap the code into the groovy() function. But you can't mix DomEL statements and Groovy statements. If so you need to create a separate calculated constant field. Here's an example where we want to show the values of a tenantID and hide the rest. So for that we need to create two fields: Field1 (tenant) - Gets the tenant ID using groovy, expression: groovy('authentication.getPrincipal().getTenantId()') Field2 (anyName) - Based on tenant ID shows one field or another: if((mt_test.tenant == constant_fields_level.tenantID), mt_test.tenant, mt_test.hidden) 21:24, 16 July 2012 (UTC)
  4. SummaryThis article descries how to use xpath2 to retrieve a remote XML web-service and publish it on JasperReports Server. This article assumes you are using JasperReports Server 4.7 or above iReportiReport already contains support for xpath2 and remote XML datasources. To configure a new remote XML datasource just create a new "Remote XML File Datasource" and set the query executor as xpath2. Writing the xpath2 query is beyond the scope of this document, however, you can take a look at this related article: Declare a field for XML datasource JasperReports Server PreparationBy default JasperReports Server does not ship with the xpath2 query executer, for this we'll need a jar file that comes with iReport. Copy jasperreports-extensions-3.5.3.jar from /ireport/modules/ext to JasperReports Server/jasperserver-pro/WEB-INF/lib/jasperreports-extensions-3.5.3.jar (or if using Jaspersoft Studio plugins/com.jaspersoft.studio.data_5.6.0.final.jar and plugins/com.jaspersoft.studio_5.6.0.final.jar)Add the following line to /jasperserver-pro/WEB-INF/classes/jasperreports.properties net.sf.jasperreports.query.executer.factory.xpath2=com.jaspersoft.jrx.query.JRXPathQueryExecuterFactory Restart TomcatReport UnitNow you can upload your report unit containing a valid xpath2 query. The key is uploading the report and setting it to Do not link a data source - the remote XML data source is easy enough to use, you simply need a parameter called $P{XML_URL} which contains the URL of an XML feed, for example: https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=jaspersoft&count=200" ParametersYou can parametrize the xpath2 query as you wish, this is simple within iReport. If you want to parametrize the URL that you are calling, for example, changing the screen_name then you need to declare two parameters (note that the order in which they are declared is critical) Parameter 1: $P{twitter_account} Used for asking the user, in my example asking them the user name Parameter2: $P{XML_URL} Used for passing the URL to the report, in my example the default value expression is set to concatenate $P{twitter_account} to the URL like this: https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=" + $P{twitter_account} + "&count=200 SubReportThis example contains a sub-report as well. You can upload the sub-report as usual and keep this in mind: You will want to "Use a datasource expression" that looks like this one: ((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).dataSource("//statuses/status[id=" + $F{id} + "]/entities/user_mentions/user_mention") No need to declare any special parameters in the sub-report, it just works! DebuggingYou can add net.sf.jasperreports.engine as DEBUG (as superuser) to http://localhost:8080/jasperserver-pro/log_settings.html - you should get some stats about the datasource if it fails. Sample ReportsIMPORTANT NOTE: Twitter has deprecated their 1.0 API which this sample was built upon, unfortunately the sample will need to be re-written to work with the 1.1+ API and this report does not currently work. (written February 2014)ThisJRXML_Files.zip contains two JRXML files, you will need to create Input Controls to get them to work, I suggest getting the Complete Sample instead Note that the sub-report expression is set to repo: report67.jrxml - change this as you wishComplete Sample (repository export):This is arepo_output.zip and uses parametrization. The sample should execute upon being imported with the js-import.sh tool, for example, run the command: ./js-import.sh --input-zip /path/to/remote_xml_sample.zip - remember to install the xpath2 query executor first! The sample will be found in /Reports/Samples/Remote XML Sample ScreenshotWhat's a sample without a of good screenshot?
  5. The Jaspersoft MongoDB ConnectorThe Jaspersoft MongoDB Connector works with iReport, JasperReports, and JasperReports Server. In previous versions (4.7 and below) the MongoDB driver needed to be installed seprately, you can find instructions on installation for older versions are here: MongoDB Install Target AudienceUsers who want to integrate Jaspersoft's JasperReports Server with MongoDB. This document assumes that the user already has familiarity with MongoDB and already has data in MongoDB collections. Getting StartedAdd a new datasource of type "MongoDB Connection" Set an appropriate url and test the connection 3. Create a reportThe simplest way for a new user to create a new report is with the Report Wizard. File → New...Choose any template and click "Launch Report Wizard".Set the report name and location.Create a query to retrieve data.There is no visual query editor, so the button "Design query" is inactive.The Jaspersoft query language for MongoDB is documented here: Jaspersoft MongoDB Query Language Sample queries Minimal: { 'collectionName' : 'accounts' }[/code]Specify the fields returned and sort the results: { 'collectionName' : 'accounts', 'findFields' : {'name':1,'phone_office':1,'billing_address_city':1,'billing_address_street':1,'billing_address_country':1}, 'sort' : {'billing_address_country':-1,'billing_address_city':1}}[/code]Filtered and parameterized: { 'collectionName' : 'accounts', 'findQuery' : { 'status_date' : { '$gte' : $P{StartDate} }, 'name' : { '$regex' : '^N', '$options' : '' } }}[/code]MapReduce job: { 'collectionName' : 'zips', 'sort' : { 'value.population' : -1, }, 'mapReduce' : { 'map' : 'function () { emit (this.state, {population : this.pop}); }', 'reduce' : 'function (key, values) { var total = 0; for( var index = 0; index < values.length; index ++) { total += valuesindex.population; } return {population : total} }', 'out' : 'totalPopulation' }}[/code]4. Deploy the query executer to JasperReports ServerImport note: These steps are only required if you have JasperReports Server version 4.5.1 or below Copy the files in WEB-INF from step 1 into /webapps/jasperserver-pro/WEB-INF Be sure to keep the folder structure when copying the files.Start or restart JasperReports Server.5. Deploy the report to JasperReports ServerCreate the Data SourceDefine the data source in JasperReports Server Right-click a folder, add a Data Source Set the Data Source properties Create and Run the ReportUse either the JasperReports Server web interface or the iReport Repository Navigator to deploy the report. Deploying from iReport is simpler in most cases. Run the report Search for the report or browse to the report in the JasperReports Server repository. Related LinksRead the query referenceDownload JasperReports Server: Community Edition or Commercial Edition.Download the Jaspersoft MongoDB Connector.MongoDB ResourcesMongoDB Website: http://www.mongodb.org/MongoDB Documentation: http://docs.mongodb.org/manual/MongoDB Training: http://education.mongodb.orgThe Jaspersoft MongoDB Query LanguageGeospatial Queries Example
  6. In Ad-Hoc editor mode, there's a button for Sample Data and one for Full Data. Traditionally these would only limit the amount of data loaded into the server's memory, however the full query would always be executed against the database. Starting in Version 4.7 of JasperReports Server there are options, to issue LIMIT BY, ROWNUM or TOP queries against the database when using Domains. In Version 5.0 this behavior is supported for more database vendors and the limiting behavior is enabled by default. The configuration file controlling this behavior is tomcat/webapps/jasperserver-pro/applicationContext-semanticLayer.xml. In Version 5.0 and above, to peruse the keywords and positions of the limiting clauses, first find your database vendor's sqlGenerator 'ref' within serverTypes of the dbServerTypeConfigFactory bean. Second, within your specific sqlGenerator bean, like oracleSQLGenerator, inspect the limitSQLMap property. In 4.7.0, to add this behavior for Postgres and MS Sql Server only, you will need to edit tomcat/webapps/jasperserver-pro/applicationContext-semanticLayer.xml - make sure to restart Tomcat after this change. Using the pre-existing mysqlSQLGenerator bean as your example, find the bean specific to your database, like postgreSQLGenerator and modify the entries corresponding to the limitPosition and limitKeyword in the table below. IMPORTANT NOTE: This feature is still considered experimental in 4.7.0, make sure to test your database before rolling this into production MySQL Bean ID mysqlSQLGenerator limitPosition AT_END limitKeyword limit Postgres Bean ID postgreSQLGenerator limitPosition AT_END limitKeyword limit Microsoft SQL Server Bean ID sqlserverGenerator limitPosition BEFORE_FIELD_LIST limitKeyword top
  7. Got a little further with 1.1.1 but at the "Test" button got the following error. The report didn't work either, same error. I verified the schema worked in iReport. Looks like were closing the JDBC connection too fast? mondrian.olap.MondrianException: Mondrian Error:Internal error: while building member cache; sql=[select "time_by_day"."the_year" as "c0" from "time_by_day" as "time_by_day" where "time_by_day"."the_year" = 2006 group by "time_by_day"."the_year" order by "time_by_day"."the_year" ASC] at mondrian.resource.MondrianResource$_Def0.ex(MondrianResource.java:811) at mondrian.olap.Util.newInternal(Util.java:1472) at mondrian.olap.Util.newError(Util.java:1488) at mondrian.rolap.SqlStatement.handle(SqlStatement.java:211) at mondrian.rolap.SqlStatement.execute(SqlStatement.java:142) at mondrian.rolap.RolapUtil.executeQuery(RolapUtil.java:242) at mondrian.rolap.RolapUtil.executeQuery(RolapUtil.java:203) at mondrian.rolap.SqlMemberSource.getMemberChildren2(SqlMemberSource.java:858) at mondrian.rolap.SqlMemberSource.getMemberChildren(SqlMemberSource.java:788) at mondrian.rolap.SqlMemberSource.getMemberChildren(SqlMemberSource.java:763) at mondrian.rolap.SmartMemberReader.readMemberChildren(SmartMemberReader.java:246) at mondrian.rolap.SmartMemberReader.getMemberChildren(SmartMemberReader.java:209) at mondrian.rolap.SmartMemberReader.getMemberChildren(SmartMemberReader.java:175) at mondrian.rolap.RolapSchemaReader.internalGetMemberChildren(RolapSchemaReader.java:169) at mondrian.rolap.RolapSchemaReader.lookupMemberChildByName(RolapSchemaReader.java:397) at mondrian.olap.MemberBase.lookupChild(MemberBase.java:170) at mondrian.rolap.RolapSchemaReader.getElementChild(RolapSchemaReader.java:341) at mondrian.olap.Util.lookupCompound(Util.java:573) at mondrian.rolap.RolapHierarchy.init(RolapHierarchy.java:281) at mondrian.rolap.RolapCubeHierarchy.init(RolapCubeHierarchy.java:334) at mondrian.rolap.RolapDimension.init(RolapDimension.java:168) at mondrian.rolap.RolapCube.init(RolapCube.java:1034) at mondrian.rolap.RolapCube.(RolapCube.java:296) at mondrian.rolap.RolapSchema.load(RolapSchema.java:420) at mondrian.rolap.RolapSchema.load(RolapSchema.java:314) at mondrian.rolap.RolapSchema.(RolapSchema.java:232) at mondrian.rolap.RolapSchema.(RolapSchema.java:72) at mondrian.rolap.RolapSchema$Pool.get(RolapSchema.java:953) at mondrian.rolap.RolapSchema$Pool.get(RolapSchema.java:769) at mondrian.rolap.RolapConnection.(RolapConnection.java:183) at mondrian.rolap.RolapConnection.(RolapConnection.java:106) at mondrian.olap.DriverManager.getConnection(DriverManager.java:110) at net.sf.jasperreports.data.mondrian.MondrianDataAdapterService.contributeParameters(MondrianDataAdapterService.java:82) at net.sf.jasperreports.data.AbstractDataAdapterService.test(AbstractDataAdapterService.java:128) at com.jaspersoft.studio.data.wizard.DataAdapterWizard.widgetSelected(Unknown Source) at com.jaspersoft.studio.data.wizard.DataAdapterWizardDialog.fireTestPressed(Unknown Source) at com.jaspersoft.studio.data.wizard.DataAdapterWizardDialog.access$0(Unknown Source) at com.jaspersoft.studio.data.wizard.DataAdapterWizardDialog$1.widgetSelected(Unknown Source) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4128) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1457) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1480) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1465) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1270) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3974) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3613) at org.eclipse.jface.window.Window.runEventLoop(Window.java:825) at org.eclipse.jface.window.Window.open(Window.java:801) at com.jaspersoft.studio.data.actions.EditDataAdapterAction.run(Unknown Source) at org.eclipse.jface.action.Action.runWithEvent(Action.java:498) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584) at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501) at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4128) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1457) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1480) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1465) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1270) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3974) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3613) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701) at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665) at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499) at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149) at com.jaspersoft.studio.rcp.intro.Application.start(Unknown Source) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577) at org.eclipse.equinox.launcher.Main.run(Main.java:1410) Caused by: org.postgresql.util.PSQLException: This connection has been closed. at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:714) at org.postgresql.jdbc3.AbstractJdbc3Connection.createStatement(AbstractJdbc3Connection.java:230) at org.postgresql.jdbc2.AbstractJdbc2Connection.createStatement(AbstractJdbc2Connection.java:191) at mondrian.rolap.SqlStatement.execute(SqlStatement.java:119) ... 77 more
  8. Problem[toc on_off::hide=1] You get an error when launching Jaspersoft ETL 4.2.3 on a Mac The JETL_Express-macosx-carbon executable launcher was unable to locate its companion shared library SolutionFind the file <JETL Install Path>/JETL_Express-macosx-carbon.app/Contents/MacOS/JETL_Express-macosx-carbon.ini Replace the contents of that file with this one: -startup ../../../plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar --launcher.library ../../../plugins/org.eclipse.equinox.launcher.carbon.macosx_1.1.0.v20100503 --launcher.XXMaxPermSize 256m -vmargs -Xms40m -Xmx256m -Xdock:icon=../Resources/Eclipse.icns -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts -Dosgi.instance.area.default=../../../workspace
  9. When defining subreports that use a domain datasource within iReport, there are a few parameters that must be defined to pass the appropriate connection details to the subreport. Parameters to add to main report and subreport filesIn main report and every subreport JRXML file, declare the following parameters: [toc]<parameter class="com.jaspersoft.commons.semantic.Schema" isforprompting="false" name="slSchema" /><parameter class="com.jaspersoft.commons.semantic.datasource.SemanticLayerFactory" isforprompting="false" name="slFactory" />[/code]Declaring paramters to pass from between the main report and subreportIn main report, declare the above parameters to pass to subreport (This is done within the tag): <subreportparameter name="slSchema"> <subreportparameterexpression> <!--[CDATA[$P{slSchema}]]--> </subreportparameterexpression></subreportparameter><subreportparameter name="slFactory"> <subreportparameterexpression> <!--[CDATA[$P{slFactory}]]--> </subreportparameterexpression></subreportparameter>[/code]Note: Note that these parameters can be added through the iReport UI even though they are represented as the resulting xml. How To: Domain based Sub-Reports with JasperReports Server
  10. Here are the steps for adding "Standard Deviation" to the Adhoc Crosstab Designer Open "actionModel-adhocCrosstab.xml". Add the following into the measureColumn and measureRow sections: <option action="selectFunction" actionargs="StandardDeviation" clienttest="isSelectedMeasureNumeric" isselectedtest="isSelectedSummaryFunction" isselectedtestargs="StandardDeviation" labelkey="Standard Deviation" /> Then open "applicationContext-adhoc.xml". And add the following lines in aggregatedConfigs section: <bean class="com.jaspersoft.ji.adhoc.strategy.AggregateConfig"> <property name="name" value="StandardDeviation" /> <property name="functionName" value="stddev" /> <property name="calcMethod" value="sqlUnionAll" /></bean>
  11. Configuring JasperReports Server with the Cassandra ConnectorSummaryDeploy the connectorDefine a connectionDeploy reportsDetailsDeploy the connectorDownload the Cassandra Connector. Unzip it. Copy the files in WEB-INF into your JasperReports Server instance. Be sure to keep the folder structure when copying the files. In connector version 0.5.1 these are the files: Special fix: remove the Hive libraries which ship with JasperReports Server since these conflict with Cassandra (clashing Thrift versions). Here are the scripted changes for a Linux instance, but you can just delete (or rename) the files manually: Restart JasperReports Server. Define a connectionRight-click on a folder in the Repository View in JasperReports Server. Use the context menu to add a data source. The data source definion should follow the model shown below. Deploy reportsUse either the JasperReports Server web interface or iReport to deploy the report to JasperReports Server.
  12. You can design standard reports to use column based security with the following features: Parameters: LoggedInUsername and/or LoggedInUserRolesJasperReports element: Print When ExpressionJasperReports element: Remove Line When Blank[toc]Run-Time Examples using TIBCO JasperReports® ServerIn the example below, four text fields and labels are configured to display only when the logged-in user's roles include ROLE_ADMINISTRATOR: Here is the same report run by a user whose roles do not include ROLE_ADMINISTRATOR: Quick View of the Layout in iReportThis is a brief look at a some of the field attributes in the iReport Designer. Column based security will be enforced at runtime when JasperServer matches the logged-in user's credentials with the LoggedInUsername and/or LoggedInUserRoles parameters. Define the Parameter(s)TIBCO JasperReports Server 3.7 and above include parameters that reference the logged-in user's credentials. The two most commonly used for column based security are: LoggedInUsername (class = java.lang.String)LoggedInUserRoles(class = java.util.Collection)These parameters are built-in and known to JasperServer at runtime. However, you need to define them in the JRXML using iReport) in order to reference them in expressions.Note that case is important: the n is lower case in LoggedInUsername and the R is uppercase in LoggedInUserRoles. Set Print When Expression ElementsPosition the field you want to optionally display onto the report layout. With the field select click the ... button to the right of the Print When Expression element in the Properties box. Enter an expression that tests for a match on username or role. If the expression results in "true" the field will display; otherwise it will not display. Here are two examples: Security based on user name (these are for Groovy as the report language): ($P{LoggedInUsername}.contains("jasperadmin")) Security based on role: $P{LoggedInUserRoles}.contains("ROLE_ADMINISTRATOR") Do this for every field you wish to protect. Removing Blank SpaceRemoving blank space only eliminates vertical space. Refer to "Removing Blank Space" in the JasperReports Ultimate Guide for specifics. To take advantage of this feature, select the field and click Remove Line When Blank in the Properties panel. Report JRXMLJasperReports Server Ultimate Guide - this is the finished JRXML file for this tutorialSee AlsoDesigning Row-Based Security into Standard Reports - similar concept but using Attributes vs Roles and Rows vs ColumnsBuilt-in_Parameters_for_Logged_In_User - A list of all built-in paramters for Logged in UsersAccessing_the_Logged_In_User_within_a_ Query-based_Input_Control - Query Based input controls with LoggedInUserSection 4.11.4 of the JasperReports Server Ultimate Guide: Built-in Parameters for Query-based Input Controls (pp 63-64, version 0311-JUG40-8)
  13. [toc on_off::hide=1] Session timeouts dictate how long a user is allowed to be inactive before being automatically logged out of JasperReports Server. TomcatEdit <tomcat>webappsjasperserver-proWEB-INFweb.xml and change the sesssion-timeout. The default is 20 minutes. <session-config> <session-timeout>20</session-timeout> </session-config> Restart the application server to make the setting take effect. TipsIf you're trying to run a very slow report, make sure that the database timeout is shorter than the session timeout. See AlsoJasperReports Server Configuration File - Web.xml
  14. OverviewThis how-to will explain how to create a report that displays data for stores that the currently logged in user has access to. The concept has been simplified using the SuperMart sample data that ships with JasperReports Server. The scenario is that you have two managers: NameTitleStoresMax FlowersCA DirectorAlameda,Beverly Hills,Los Angeles,San Francisco,San DiegoJoe MartsStore DirectorLos Angeles[toc]The most robust way to handle row and column level data security in JasperReports Server is to utilize a Domain and a security file. This is covered in Chapter 6 of the JasperReports Ultimate Guide (SECURING DATA IN A DOMAIN). The how-to in this page utilizes some of the same techniques but at the SQL level without the need for a domain. Again, the recommended way to achieve data security is via a domain, this is another less-robust method. That said, let's get started with the example. Creating UsersLet's create our two users: Max and Joe. Log in as the jasperadmin and create the two users. Once the users are created, add some attributes to the JiProfileAttribute table. This is covered in depth in the JasperReports Server Ultimate Guide, Section 6.2.5.5 "Inserting Attributes into the Profile Attribute Table in SQL". Note that in version 5.0 and above, you can now manage these in the UI, as in the example below: Note: the example above is for PostgresSQL syntax For older version of the product or if you prefer to do it programatically (or through API): For Max (in my case user id #10): INSERT INTO JIProfileAttribute( attrName ,attrValue ,principalobjectclass ,principalobjectid) values( "Cities" ,"'Alameda','Beverly Hills','Los Angeles','San Francisco','San Diego'" ,"com.jaspersoft.jasperserver.api.metadata.user.domain.impl.hibernate.RepoUser" ,10);[/code]For Joe (in my case user id #11): INSERT INTO JIProfileAttribute( attrName ,attrValue ,principalobjectclass ,principalobjectid) values( "Cities" ,"'Los Angeles'" ,"com.jaspersoft.jasperserver.api.metadata.user.domain.impl.hibernate.RepoUser" ,11);[/code]NOTE: this is for MySQL syntax You should see the Profile Attributes in JasperReports Server's User Interface now: Creating the ReportNow a report can be created. There's a few special things needed to take advantage of the Profile Attributes. QueryIn this example the query is structured something like this: SELECT sum(store_sales) store_city FROM stores WHERE store_city IN ($P!{LoggedInUserAttribute_Cities})[/code]So for example, what JasperReports Server will do when Max runs this report is to expand the WHERE clause to: ... WHERE store_city IN ( 'Alameda&' ,'Beverly Hills&' ,'Los Angeles' ,'San Francisco' ,'San Diego&')[/code]ParameterIn order for the report to be aware of the Logged In User Attributes you will need to declare them in the form of Parameters in your report. NOTE: Make sure there is no default value for the parameter, sometimes iReport will fill in a blank default value, clear it out in the XML file ResultsSo when Joe runs the report he only sees the cities he's allowed to see: And when Max runs the report he sees the cities he's allowed to see: Other ConsiderationsInput ControlsThe same logic can be applied to Query based Input Controls so that the user only sees applicable fiels. An example Query for an Input Control might look like this: SELECT store_city FROM stores WHERE store_city IN ($P!{LoggedInUserAttribute_Cities})[/code]LimitationsNot every user has the Profile Attribute of Cities, for example running this report as jasperadmin caused errors. An additional parameter was added to the example report. The parameter LoggedInCheck was added to generate valid SQL even when $P{LoggedInUserAttribute_Cities} is empty. This was acheived via the default value expression of LoggedInCheck, like so: $P{ LoggedInUserAttribute_Cities}.isEmpty() ? "'dummy'" : $P{LoggedInUserAttribute_Cities }[/code]In addition the chart in the example report is dependant on getting data back from SQL so there's a Print When Expression on the chart to only print if the $P{LoggedInUserAttribute_Cities} is not empty, here is that expression: $P{LoggedInUserAttribute_Cities}.length() > 0[/code]Example ReportSample.zip - this file contains the JRXML necessary to deploy to Jasperserver. It is not necessary to create input controls on the JasperReports Server side.Choose /analysis/datasources/FoodmartDataSourceJNDI as this report's data sourceSee AlsoDesigning_Column-Based_Security_into_Standard_Reports - similar concept but using Roles vs Attributes and Columns vs Rows.Built-in_Parameters_for_Logged_In_User - A list of all built-in paramters for Logged in UsersAccessing_the_Logged_In_User_within_a_Query-based_Input_Control - Query Based input controls with LoggedInUserJasperReports Server Administration Guide: Built-in Parameters for Query-based Input Controls
  15. This article provides information about calling stored procedures in iReport Designer with Microsoft SQL. Create a Stored Procedure on Micrsoft SQL-- =============================================-- Author: author name-- Create date: created-- Description: description-- =============================================CREATE PROCEDURE ireport @parameter1 INTAS BEGIN SELECT 125 * @parameter1 AS somefield ENDGO[/code]This particular dummy stored procedure simply takes a parameter and multiplies it by 125. Not very useful but a good proof of concept. Chose plsql as the query language Create Parameters and Simply call the Stored Procedure by Name In this case, the name of the stored procedure is 'ireport' and it takes exactly one parameter. The parameter was defined with a default value expression of "2" which simply multiplies 125 by 2. That's it, simply use the fields in your report and the user will be prompted via parameter, the parameters might also come from LoggedinUser/role/attribute which helps tie into security models. It is also possible to save this report in the Topics folder of JasperReports server to take advantage of the Ad-Hoc engine and stored procedures. Note: You should disable the rows() affected message by running SET NOCOUNT ON on the SQL server It may be necessary to add an exclamation point after the $P, for example $P!{parameter1}.
×
×
  • Create New...