Apply JPQL filter condition after runtime user filter

Hello,

I have a Jmix 1.5+ project with the following screen xml descriptor:

<loader id="userEntitiesDl">
      <query>
          <![CDATA[select e from UserEntity e order by e.createdDate desc]]>
          <condition>
              <and>
                  <c:jpql>
                      <c:where>e.manager = :manager</c:where>
                  </c:jpql>
              </and>
          </condition>
      </query>
 </loader>

And the Java class that handles it:

@Override
	protected void initActions(InitEvent event) {

		super.initActions(event);

		if (event.getOptions() instanceof UsersForManagerScreenOptions options) {

			this.usersForManagerScreenOptions = options;
			this.userEntitiesDl.setParameter(PARAM_MANAGER, usersForManagerScreenOptions.getManager());
		}
	}

In the same screen I have a filter which allows a manager to apply all sorts of filters against the users that they manage (the users are displayed in a GroupTable):

<filter id="filter" dataLoader="userEntitiesDl">
    <properties include="username"/>
    <configurations>
        <configuration id="filterUserNameConfiguration"
                       default="true"
                       name="Filter-User-By-Username">
            <propertyFilter id="pfUsername" property="username"
                            operation="CONTAINS"
                            operationEditable="false"
                            caption="Search User By Username"/>
            <propertyFilter id="pfFirstName" property="firstName"
                            operation="CONTAINS"
                            operationEditable="false"
                            caption="Search User By First Name"/>
         .........
        </configuration>
    </configurations>
</filter>

Once the screen is opened the global JPQL where clause gets applied and the manager user sees only the employees they manage. As soon as they apply any filtering on the result set though, the JPQL condition gets ignored and the filter is applied on all users in the DB. Thus, after filtering they actually get a bigger dataset and they can see users that they don’t manage / are not supposed to view.

My question is - How can I apply the global JPQL where clause AFTER each application of the user filter at runtime?

Looking forward to any help or advice.

Hello,

I dont see errors in your JPQL filter, i also asked Jmix team developer who developed the filter, so best way to solve your problem is to enable logging jpql and sql and interpret the result and only then change something.

Best regards,
Dmitry

I see, but just to confirm if I understand the framework right - when I do this line:

this.userEntitiesDl.setParameter(PARAM_MANAGER, usersForManagerScreenOptions.getManager());

and then at runtime the user applies some additional filters from the UI, the runtime filter will also take into account the MANAGER param? So in theory the runtime filter is applied on the already filtered by manager dataset?