I am using multitenancy 1.3.* and studio 7. I have entity with multitenancy. The chart and table component works fine and show data for log in tenant only but report show all data (data from other tenant also)
I have not extended report as same report should be available to all tenants and using jpql as under in reports
select
e.date as “date”,
e.requirement as “requirement”,
e.complex.name as “complex”,
e.details as “details”,
assignedTo.name as “assignedTo.name”,
assignedTo.login as “assignedTo.login”,
e.dueDate as “dueDate”
from sheelcompliance_ComplianceMonitoring e
left join e.assignedTo assignedTo
where (e.status = ‘Assigned’)
and (e.dueDate < CURRENT_DATE)
Same jpql works fine in charts with keyvaluecollection but not in reports.
Thanks in advance
Umesh
Hi @umeshhodwala,
we will check this issue and reply on next week
Regards,
Evgeny
Hi @umeshhodwala,
Currently reports JPQL query bands do not filter data by tenants. In your case, you can add explicit tenant id parameter to your query and enter this parameter on each report run or you can create Groovy dataset where you can load data.
Please check the example:
import com.haulmont.cuba.core.global.AppBeans
import com.haulmont.cuba.core.global.DataManager
import com.haulmont.cuba.core.global.LoadContext
return AppBeans.get(DataManager.class).secure()
.loadList(new LoadContext(TenantUser.class)
.setQuery(LoadContext.createQuery(
'select u from cubasdbmt$TenantUser u where u.active = :active')
.setParameter("active", true))
)
Regards,
Evgeny
Dear @evgeny.zaharchenko,
Thanks for reply. When this issue will be resolved?
Secondly, I can use tenantid in jpql query and can calculate it but how to supply it to report (not pragmatically) but in existing report edit screen (image below), so as /tenant admin/user don’t have to input it.
Thirdly, where should I put my code to save tenantid in user session (best location just after login, some other post say in app class??).
Regards
Umesh
How can i pass the external parameter tenantid to report without user input.
regards
Umesh
Hi @umeshhodwala,
Current tenant id already contains in the user session attributes in tenant_id
attribute.
To have current tenant id in your reports you can try to extend com.haulmont.reports.ReportingBean
in your project and override
createReportDocument(Report report, ReportTemplate template, ReportOutputType outputType, Map<String, Object> params)
method where you can add current tenant id to report parameters (params
).
In this case all of your reports will have tenant id parameter.
You can find more info how to extend business logic in the CUBA Platform documentation Extending Business Logic - CUBA Platform. Developer’s Manual
Regards,
Evgeny
I am trying as suggested. What is bean identifier for com.haulmont.reports.ReportingBean for registration in spring.xml. I searched on github but in vein.
<bean id="WHAT IS THIS" class="com.company.sheelcompliance.core.ExtReportBean"/>
regards
Umesh
Hi @umeshhodwala,
bean id will be report_ReportingApi
.
Regards,
Evgeny
Hi @evgeny.zaharchenko,
As suggested I have extended the createreportdocument and this code seems working prima facie.
public class ExtReportBean extends ReportingBean {
@Override
protected ReportOutputDocument createReportDocument(Report report, ReportTemplate template, ReportOutputType outputType, Map<String, Object> params) {
params.put("tenant", userSessionSource.getUserSession().getAttribute("tenant_id"));
return super.createReportDocument(report, template, outputType, params);
}
}
I will check and will come back, if there is any issue. However your advice is most welcome.
Secondly when I made the bean it was visible in middleware but now it is not visible there
I have to open it from project files.
Am i doing anything wrong.