-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix #2158] Adding support for querying workflow variables
- Loading branch information
Showing
12 changed files
with
280 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...rage-postgresql/src/main/java/org/kie/kogito/index/postgresql/PostgresqlJsonJPAQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.index.postgresql; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.kie.kogito.index.jpa.model.AbstractEntity; | ||
import org.kie.kogito.index.jpa.storage.JPAQuery; | ||
import org.kie.kogito.persistence.api.query.AttributeFilter; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; | ||
|
||
import jakarta.persistence.criteria.CriteriaBuilder; | ||
import jakarta.persistence.criteria.Predicate; | ||
import jakarta.persistence.criteria.Root; | ||
|
||
public class PostgresqlJsonJPAQuery<K, E extends AbstractEntity, T> extends JPAQuery<K, E, T> { | ||
|
||
public PostgresqlJsonJPAQuery(PanacheRepositoryBase<E, K> repository, Function<E, T> mapper, Class<E> entityClass) { | ||
super(repository, mapper, entityClass); | ||
} | ||
|
||
protected Function<AttributeFilter<?>, Predicate> filterPredicateFunction(Root<E> root, CriteriaBuilder builder) { | ||
return filter -> filter.isJson() ? PostgresqlJsonNavigator.buildPredicate(filter, root, builder) : buildPredicateFunction(filter, root, builder); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...age-postgresql/src/main/java/org/kie/kogito/index/postgresql/PostgresqlJsonNavigator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.index.postgresql; | ||
|
||
import org.kie.kogito.persistence.api.query.AttributeFilter; | ||
|
||
import jakarta.persistence.criteria.CriteriaBuilder; | ||
import jakarta.persistence.criteria.Expression; | ||
import jakarta.persistence.criteria.Predicate; | ||
import jakarta.persistence.criteria.Root; | ||
|
||
public class PostgresqlJsonNavigator { | ||
|
||
private PostgresqlJsonNavigator() { | ||
} | ||
|
||
public static Predicate buildPredicate(AttributeFilter<?> filter, Root<?> root, | ||
CriteriaBuilder builder) { | ||
switch (filter.getCondition()) { | ||
case EQUAL: | ||
boolean isString = filter.getValue() instanceof String; | ||
return builder.equal(buildPathExpression(builder, root, filter.getAttribute(), isString), buildObjectExpression(builder, filter.getValue(), isString)); | ||
} | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
private static Expression<?> buildObjectExpression(CriteriaBuilder builder, Object value, boolean isString) { | ||
return isString ? builder.literal(value) : builder.function("to_jsonb", Object.class, builder.literal(value)); | ||
} | ||
|
||
private static Expression<?> buildPathExpression(CriteriaBuilder builder, Root<?> root, String attributeName, boolean isStr) { | ||
String[] attributes = attributeName.split("\\."); | ||
Expression<?>[] arguments = new Expression[attributes.length]; | ||
arguments[0] = root.get(attributes[0]); | ||
for (int i = 1; i < attributes.length; i++) { | ||
arguments[i] = builder.literal(attributes[i]); | ||
} | ||
return isStr ? builder.function("jsonb_extract_path_text", String.class, arguments) : builder.function("jsonb_extract_path", Object.class, arguments); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...src/main/java/org/kie/kogito/index/postgresql/PostgresqlProcessInstanceEntityStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.kie.kogito.index.postgresql; | ||
|
||
import org.kie.kogito.index.jpa.mapper.ProcessInstanceEntityMapper; | ||
import org.kie.kogito.index.jpa.model.ProcessInstanceEntityRepository; | ||
import org.kie.kogito.index.jpa.storage.ProcessInstanceEntityStorage; | ||
import org.kie.kogito.index.model.ProcessInstance; | ||
import org.kie.kogito.persistence.api.query.Query; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class PostgresqlProcessInstanceEntityStorage extends ProcessInstanceEntityStorage { | ||
|
||
@Inject | ||
public PostgresqlProcessInstanceEntityStorage(ProcessInstanceEntityRepository repository, ProcessInstanceEntityMapper mapper) { | ||
super(repository, mapper); | ||
} | ||
|
||
@Override | ||
public Query<ProcessInstance> query() { | ||
return new PostgresqlJsonJPAQuery<>(repository, mapToModel, entityClass); | ||
} | ||
} |
Oops, something went wrong.