JasperServer Folders tree customization

0

Hi,

        I am encountering this problem in Jasperserver v3.5. I want the user to see only the reports folder  in the left Folders panel once he logins into Jasper Server but need to use the data sources, images in the reports he is going to view. I need to hide from the user's view all the other folders, and possibly rename/ remove  the root folder. Do I need to edit any of the  flows or beans?

Ane help would be much appreciated.

 

Thanks in advance,

Sasidhar.

 

sasinuth's picture
Joined: Jun 3 2009 - 7:20am
Last seen: 3 months 1 week ago

8 Answers:

0
Any ideas folks? Thanks, Sasidhar.
sasinuth's picture
Joined: Jun 3 2009 - 7:20am
Last seen: 3 months 1 week ago
0

I'm using js 3.1 so this may be diferent in js 3.5.

There's a seperate thread on this see http://jasperforge.org/plugins/espforum/view.php?group_id=112&forumid=10... which talks about marking folders as hidden in the db. The only trouble with this is that they are hidden for all (including administrators) and you can't see them using the ireport plugin.

To get round this I ended up changing the code so I only displayed my resources folder (datasources, images etc) if I was an administrator. I think the problem is that you can't do it applying role based security as your users need access to be able to run the reports which means they will also see the folder in the repository view.

Take a look at com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl getSubFolders method if you have access to the codebase. This method retrieves all the folders for the repository view (these are subsequently restricted based on what role you are by another class which I can't remember the name of). Wrote some extra code to remove folders from the returned list if I wasn't an administrator.

Hope this helps - again i mention that this is based on js 3.1 and there may in fact be an easier way.

 

 

mdjj's picture
35
Joined: Dec 10 2008 - 6:58am
Last seen: 5 years 7 months ago
0
Hello, can you please give me the path to the " jiresourcefolder table in the jasper repository database " where I can set the folders I need to hide? Some details on how to hide the folders but still be able to use the contents would be helpful. Thanks in advance, Sasi.
sasinuth's picture
Joined: Jun 3 2009 - 7:20am
Last seen: 3 months 1 week ago
0

I'm not really sure what you're asking?? The jiresourcefolder table is just a table in the jasperserver database that contains all the metadata for jasperserver to use. The path to the database (if that's what you're asking) is wherever the database was installed to (in my case a local mysql database that can be connected to on localhost port 3306. In this table you can find the folder you want to hide (the uri column) and set the hidden column.


mdjj's picture
35
Joined: Dec 10 2008 - 6:58am
Last seen: 5 years 7 months ago
0

Dear Mdjj,

 

Thanks very much for your useful tip!  I have been thinking along a similar direction, and your tip helped me locate the right code fragment.

 

However, I have a question.  Have you tried using js-export after you made the change?  Would the "suppressed" folders (*) be also  suppressed in the export process?  If so, this would be undesirable because all the datasource, datatype, etc will be missing in the export.

 

(* those filtered out in the returned list of getSubFolders() unless the user is having ROLE_ADMINISTRATOR)

 

Thanks!

leeyuiwah's picture
Joined: Oct 21 2008 - 4:52pm
Last seen: 3 months 2 weeks ago
0

I have exported using js-export successfully and the change I describe has no effect, I am able to export either the resources folder seperately (datasources etc) or a reports folder which picks up all it's dependancies (datasources, images etc).

My guess is that js-export goes directly to the database to export where as my change will only affect what you see in the UI (but I don't claim to know how js-export woks).

mdjj's picture
35
Joined: Dec 10 2008 - 6:58am
Last seen: 5 years 7 months ago
0

Maybe you were implementing your own bean (extending com.jaspersoft.jasperserver.api.metadata.common.service.impl.hibernate.HibernateRepositoryServiceImpl ) ? (i.e. not change HibernateRepositoryServiceImpl directly)

 

JasperServer (the web app) and the js-export util uses their own XML files to wire the beans together. So if you only changed the XML files for JasperServer to use the new bean, then I think the behavior of js-export would not change (to our benefits here).

 

Thanks for your great tip!



Post Edited by leeyuiwah at 06/11/2009 21:39
leeyuiwah's picture
Joined: Oct 21 2008 - 4:52pm
Last seen: 3 months 2 weeks ago
0

 For anyone who wants the code :

 Again I mention that my code is based on JS 3.1 not 3.5 so may be diferent in 3.5.

 I changed the code directly in HibernateRepositoryServiceImpl and injected my own bean into this.
 There's no reason why you couldn't extend this though.
 
 At the end of getSubFolders method (just before the SortingUtils.sortFoldersByName(getCollator(context), subfolders);
 line ) remove the folders you want from the returned list :
 
 Note I'm removing both the resources folder (datasources etc) and the adhoc folder from anyone who is not an
 administrator :
 
 
 
 
                     Folder resourceFolder = null;
                     Folder adhocFolder = null;
                    
                     for (Iterator it = subfolders.iterator(); it.hasNext();) {
                             Folder repoFolder = (Folder) it.next();
 
                             if ((Name of your resources folder).equalsIgnoreCase(repoFolder.getName())) {
                                 resourceFolder = repoFolder;
                             }
                             if (("adhoc").equalsIgnoreCase(repoFolder.getName())) {
                                 adhocFolder = repoFolder;
                             }
 
                     }
                     if (resourceFolder != null) {
                         if (!myBean.isAdministrator()) {
                             subfolders.remove(resourceFolder);
                         }
                     }
                     if (adhocFolder != null) {
                         if (!myBean.isAdministrator()) {
                             subfolders.remove(adhocFolder);
                         }
                    }
                   
                   

Essentially MyBean isAdministrator method is checking the roles of the user via the security principal to see if
they are an administrator. You probably don't need to inject your own bean to do this it's just that our method
of getting the user is slightly more complicated and it was easier to delegate this to another class. If you're storing
your users internally to jasper server you can probably just do something like :

        MetadataUserDetails user = null;
        Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();

        if(currentUser.getPrincipal() instanceof MetadataUserDetails){
            user = (MetadataUserDetails)currentUser.getPrincipal();
            user.getRoles();
            //iterate around the roles checking for role name of ROLE_ADMINISTRATOR
        }


 

mdjj's picture
35
Joined: Dec 10 2008 - 6:58am
Last seen: 5 years 7 months ago
Feedback
randomness