Axon.ivy 7.0 - the Digital Business Platform - is out now...

I have a Task Query as json to filter tasks by states: SUSPENDED, RESUMED, PARKED and order by priority:

TaskQuery stateQuery = TaskQuery.create().where().state().isEqual(TaskState.SUSPENDED).or().state().isEqual(TaskState.RESUMED).or().state().isEqual(TaskState.PARKED).orderBy().priority();

After that, I would like to extend this query: filtering by ((suspended or resumed or parked states) and applicationId) order by priority but it is not as my expectation:

Way 1: TaskQuery.fromJson(stateQueryJson).where().and().applicationId().isEqual(1);

The result: SELECT * FROM IWA_Task WHERE (Column(IWA_TaskQuery.State) = 4 || Column(IWA_TaskQuery.State) = 5 || (Column(IWA_TaskQuery.State) = 8 && Column(IWA_TaskQuery.ApplicationId) = 1)) ORDER BY Column(CurrentPriority) ASCENDING

==> Tasks with Suspended state and Resumed state are not filtered by applicationId

Way 2: TaskQuery.create().where().and(TaskQuery.fromJson(stateQuery.asJson())).and().applicationId().isEqual(1)

The result: SELECT * FROM IWA_Task WHERE ((Column(IWA_TaskQuery.State) = 4 || Column(IWA_TaskQuery.State) = 5 || Column(IWA_TaskQuery.State) = 8) && Column(IWA_TaskQuery.ApplicationId) = 1)

==> Priority order is lost

Do you have any suggestions? Or is it a bug of task json query?

asked 18.05 at 02:59

lttung's gravatar image

lttung
1125
accept rate: 0%


The following snipped creates your expected query:

TaskQuery orConditions = TaskQuery.create()
   .where().state().isEqual(TaskState.SUSPENDED)
      .or().state().isEqual(TaskState.RESUMED)
      .or().state().isEqual(TaskState.PARKED);

TaskQuery query = TaskQuery.create()
   .where().and(orConditions)
   .orderBy().priority();

query.where().applicationId().isEqual(1);

Resulting Query:

SELECT *  
  FROM IWA_Task  
  WHERE
  (
      (  Column(IWA_TaskQuery.State) = 4 
      || Column(IWA_TaskQuery.State) = 5 
      || Column(IWA_TaskQuery.State) = 8
      ) 
      && 
      Column(IWA_TaskQuery.ApplicationId) = 1
  ) 
  ORDER BY Column(CurrentPriority) ASCENDING

Way 1: The first 'operator' is a OR-operator. As a result, the root-operator is a or-operator and therefore any further operators are attached to this root-(or-)operator, which results in your written condition.

Way 2: The method and(TaskQuery q) doesn only take the filter (the where-condition) from the passed query.

I would say: the TaskQuery API is a perfect fluent API. When using it to combine multiple condition is is a bit tricky...

link

answered 18.05 at 09:33

Flavio%20Sadeghi's gravatar image

Flavio Sadeghi ♦♦
1.8k5722
accept rate: 75%

edited 18.05 at 09:37

Hi Flavio,

The problem is from Json:

TaskQuery orConditions = TaskQuery.create()
  .where().state().isEqual(TaskState.SUSPENDED)
  .or().state().isEqual(TaskState.RESUMED)
  .or().state().isEqual(TaskState.PARKED);

TaskQuery query1 = TaskQuery.create()
  .where().and(orConditions)
  .orderBy().priority();

TaskQuery query2 = TaskQuery.fromJson(query1.asJson()); //The result queries of 1 and 2 are the same.

query1.where().applicationId().isEqual(1); // Correct as expected.
query2.where().applicationId().isEqual(1); // Wrong, the same as Way 1.

Why is query2 the same as query1 before filtering by app but different after that?

link

answered 18.05 at 23:31

lttung's gravatar image

lttung
1125
accept rate: 0%

edited 19.05 at 00:04

Hi @lttung, thanks for pointing out the deserialization bug. We will analyze it. Here the link to the issue: https://jira.axonivy.com/jira/browse/XIVY-1923: CaseQuey / TaskQuery json deserialization removes AND-condition when it has only one condition

(22.05 at 04:10) Flavio Sadeghi ♦♦ Flavio%20Sadeghi's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×68
×9

Asked: 18.05 at 02:59

Seen: 215 times

Last updated: 22.05 at 04:10