Solution - LoggedInUser and Input Control

Hello All,

So far JasperReports has been an excellent tool.

I'm interested in finding out if it is possible to use LoggedInUser within a Single Select Query input control.

Please see the attached image, this may give you an idea of what I'm trying to accomplish.

Thanks in advance,
Ben
Post edited by: bpienig, at: 2007/10/01 15:34
bpienig's picture
87
Joined: Jul 31 2007 - 7:40am
Last seen: 16 years 2 months ago

17 Answers:

Oops...

Here's the file, that I was trying to attach. [file name=loggedinuser.jpg size=51669]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/log...
bpienig's picture
87
Joined: Jul 31 2007 - 7:40am
Last seen: 16 years 2 months ago
As you've observed, this is not yet supported. Please post a feature request for it [url=http://jasperforge.org/sf/tracker/do/listArtifacts/projects.jasperintell... so that we can properly track it.

Regards,
Lucian
lucianc's picture
87143
Joined: Jul 17 2006 - 1:10am
Last seen: 20 hours 6 min ago
I see now that there already exists a feature request for this (see [url=http://jasperforge.org/sf/go/artf2176?nav=1]artf2176).

Regards,
Lucian
lucianc's picture
87143
Joined: Jul 17 2006 - 1:10am
Last seen: 20 hours 6 min ago
Ah, sounds good.

Thanks for the info Lucian.

Ben

lucianc wrote:
I see now that there already exists a feature request for this (see [url=http://jasperforge.org/sf/go/artf2176?nav=1]artf2176).

Regards,
Lucian
bpienig's picture
87
Joined: Jul 31 2007 - 7:40am
Last seen: 16 years 2 months ago
Hi all,

I have created a patchy implementation for this feature with no needs for recompiling the code - just modifying DefaultParametersForm.jsp file.

Let me post my approach for those interested...

Step 1: Create a non-visible inputControl (SingleValue - string) called USER.
Step 2: Add reference to acegi taglib at the beginning of DefaultParametersForm.jsp file.
<%@ taglib uri="http://acegisecurity.org/authz" prefix="authz"%>
Step 3: Search this file for this code...

<c:if test="${!control.visible}">
<input type="hidden" name="${inputName}" value="${wrapper.formattedValue}"/>
</c:if>

...and substitute it with this fragment...

<c:if test="${!control.visible}">
<c:choose>
<c:when test="${control.name=='USER'}">
<input type="hidden" name="${inputName}" value="<authz:authentication operation="username"/>"/>
</c:when>
<c:otherwise>
<input type="hidden" name="${inputName}" value="${wrapper.formattedValue}"/>
</c:otherwise>
</c:choose>
</c:if>


I hope this is useful for those in a hurry...
It would be great to have an official implementation for this feature in the future.

Best regards,

P.S.- I'll be out of office for two weeks. Read you in September.
sergioOrtiz's picture
Joined: Mar 1 2007 - 7:27pm
Last seen: 16 years 7 months ago
I have created a patchy implementation for this feature with no needs for recompiling the code - just modifying DefaultParametersForm.jsp file.


Hey sergio,

That's not quite what I was looking for, I'm looking at being able to use the LoggedInUser in the SQL of the multiple-input control.

If you want to use the LoggedInUser in the report, just take a look at the SalesByMonth sample report. It uses the LoggedInUser as a parameter.

Thanks,
Ben
bpienig's picture
87
Joined: Jul 31 2007 - 7:40am
Last seen: 16 years 2 months ago
Hi Ben,

Absolutely right! :)

I was in a hurry and didn't have time to check the forums - I hardwired a solution.

I've just tested the $P{LoggedInUser} option and works perfectly.

Thanks for your info!
sergioOrtiz's picture
Joined: Mar 1 2007 - 7:27pm
Last seen: 16 years 7 months ago
I've got a fix for this problem.

It involved editing the EngineServiceImpl.java file.


Previous Code

Code:
	public OrderedMap executeQuery(ExecutionContext context, <br />
			ResourceReference queryReference, String keyColumn, String[] resultColumns, <br />
			ResourceReference defaultDataSourceReference) {<br />
		Query query = (Query) getFinalResource(context, queryReference);<br />
<br />
		ResourceReference dataSourceReference = query.getDataSource();<br />
		if (dataSourceReference == null) {<br />
			dataSourceReference = defaultDataSourceReference;<br />
		}</td></tr></tbody></table><br />
<br />
<br />
Edited Code<br />
<br />
<table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr><td><b>Code:</b></td></tr><tr><td><pre>	public OrderedMap executeQuery(ExecutionContext context, <br />
			ResourceReference queryReference, String keyColumn, String[] resultColumns, <br />
			ResourceReference defaultDataSourceReference) {<br />
		Query query = (Query) getFinalResource(context, queryReference);<br />
<br />
		String userName = getSecurityContextProvider().getContextUser().getUsername();<br />
		String queryStr = query.getSql().replace("$P{LoggedInUsername}",userName);<br />
		query.setSql( queryStr );<br />
<br />
		ResourceReference dataSourceReference = query.getDataSource();<br />
		if (dataSourceReference == null) {<br />
			dataSourceReference = defaultDataSourceReference;<br />
		}</td></tr></tbody></table><br />
<br />
If you add $P{LoggedInUsername} to an input control query, it will replace it with the current logged in user name.<br />
<br />
It's a hack, but at least it works for now.<br>Post edited by: bpienig, at: 2007/09/27 22:42
bpienig's picture
87
Joined: Jul 31 2007 - 7:40am
Last seen: 16 years 2 months ago
Hello! I can't find this file EngineServiceImpl.java, where is it situated?
zt_trox's picture
Joined: Oct 21 2007 - 5:08pm
Last seen: 15 years 11 months ago
It is found in:

com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl;

Which is within the jasperserver-api-impl source

Ben
bpienig's picture
87
Joined: Jul 31 2007 - 7:40am
Last seen: 16 years 2 months ago

Does you hack require a re-compile of the project?  If so, can you check in the change?

Because this is working.  I can not wait on the enhancement to make $P{LoggedInUsername} to work in the SQL where clause.

huw@trimet.org's picture
Joined: Feb 8 2007 - 9:24am
Last seen: 5 years 5 months ago

Are there any updates if Jasper Server 3.1 release supports the LoggedInUser within a Single Select Query input control?

jojopaderes's picture
Joined: Jul 23 2008 - 9:50am
Last seen: 15 years 2 months ago

Duplicate post. See next entry instead.




Post Edited by Jojo Paderes at 01/29/09 10:03
jojopaderes's picture
Joined: Jul 23 2008 - 9:50am
Last seen: 15 years 2 months ago

lucianc
Wrote:

I see now that there already exists a feature request for this (see [url=http://jasperforge.org/sf/go/artf2176?nav=1]artf2176).

Regards,
Lucian

The link you gave seems to be broken. Can you provide the working link that would point to the feature request? Thanks!

jojopaderes's picture
Joined: Jul 23 2008 - 9:50am
Last seen: 15 years 2 months ago

The updated link is http://jasperforge.org/tracker/index.php?func=detail&aid=1315&group_id=112&atid=376&action=edit.

This has not been implemented in 3.1, but we plan to include in the next release.

Regards,

Lucian

lucianc's picture
87143
Joined: Jul 17 2006 - 1:10am
Last seen: 20 hours 6 min ago

 I wonder if I someone could give me the resulting compiled .jar file and then I could just drop it into my server lib files - I'm having no luck whatsoever in building jasperserver after making the changes to the java file. Maven2 , POMs, repos, getting that all to work will take (me) weeks.

Thanks in advance. 

And, why not just add it to the next release - the workaround seems quite useful and its only a few lines. Why has this request been sitting there so long (since 3.1?)

pjsmith's picture
48
Joined: Jul 22 2009 - 11:27am
Last seen: 8 years 1 month ago

$P{LoggedInUsername} can be used in input control queries starting with JasperServer 3.5.

Regards,

Lucian

PS: Please post any further queries related to JasperServer on the JasperServer forum.

lucianc's picture
87143
Joined: Jul 17 2006 - 1:10am
Last seen: 20 hours 6 min ago
Feedback
randomness