Skip to content

Commit

Permalink
AAE-28952 fix QuerySwaggerIt and Sonar issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-dal committed Dec 10, 2024
1 parent 1cc19f2 commit 90e730e
Show file tree
Hide file tree
Showing 8 changed files with 687 additions and 643 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

public class CustomizedJpaSpecificationExecutorImpl<T, ID extends Serializable>
extends SimpleJpaRepository<T, ID>
public class CustomizedJpaSpecificationExecutorImpl<T, I extends Serializable>
extends SimpleJpaRepository<T, I>
implements CustomizedJpaSpecificationExecutor<T> {

private final EntityManager entityManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ public abstract class SpecificationSupport<T, R extends ProcessVariableFilterReq

protected final R searchRequest;
protected List<Predicate> predicates;
public List<VariableValueFilterCondition> filterConditions;

protected List<VariableValueFilterCondition> filterConditions;
private SetJoin<T, ProcessVariableEntity> pvJoin;

protected final Map<VariableType, Class<?>> javaTypeMapping = Map.of(
VariableType.STRING,
String.class,
Expand Down Expand Up @@ -163,14 +161,14 @@ protected void applySorting(
validateSort(sort);
Expression<?> orderByClause;
if (sort.isProcessVariable()) {
From<T, ProcessVariableEntity> pvJoin = joinSupplier.get();
From<T, ProcessVariableEntity> joinRoot = joinSupplier.get();
orderByClause =
new VariableSelectionExpressionImpl<>(
pvJoin,
joinRoot,
Map.of(
pvJoin.get(ProcessVariableEntity_.processDefinitionKey),
joinRoot.get(ProcessVariableEntity_.processDefinitionKey),
sort.processDefinitionKey(),
pvJoin.get(ProcessVariableEntity_.name),
joinRoot.get(ProcessVariableEntity_.name),
sort.field()
),
javaTypeMapping.get(sort.type()),
Expand Down Expand Up @@ -213,7 +211,12 @@ protected void validateSort(CloudRuntimeEntitySort sort) {
* @return Supplier of SetJoin of process variables
*/
protected Supplier<SetJoin<T, ProcessVariableEntity>> joinProcessVariables(Root<T> root) {
return () -> pvJoin == null ? pvJoin = root.join(getProcessVariablesAttribute(), JoinType.LEFT) : pvJoin;
return () -> {
if (pvJoin == null) {
pvJoin = root.join(getProcessVariablesAttribute(), JoinType.LEFT);
}
return pvJoin;
};
}

protected abstract SetAttribute<T, ProcessVariableEntity> getProcessVariablesAttribute();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* Licensed 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.activiti.cloud.services.query.rest.specification;

import jakarta.persistence.criteria.Expression;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* Licensed 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.activiti.cloud.services.query.rest.specification;

import jakarta.persistence.criteria.CriteriaBuilder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2017-2020 Alfresco Software, Ltd.
*
* Licensed 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.activiti.cloud.services.query.rest.specification;

import jakarta.persistence.criteria.Predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2513,13 +2513,13 @@ void should_returnProcessInstances_sortedBy_BooleanProcessVariable() {
);
}

/**
* From Postgres documentation: https://www.postgresql.org/docs/current/queries-order.html
* By default, null values sort as if larger than any non-null value;
* that is, NULLS FIRST is the default for DESC order, and NULLS LAST otherwise.
*/
@Test
void should_returnProcessInstances_paginatedAndSortedByProcessVariables_respectingDefaultNullBehaviour() {
/*
* From Postgres documentation: https://www.postgresql.org/docs/current/queries-order.html
* By default, null values sort as if larger than any non-null value;
* that is, NULLS FIRST is the default for DESC order, and NULLS LAST otherwise.
*/
ProcessInstanceEntity processInstance1 = queryTestUtils
.buildProcessInstance()
.withInitiator(USER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3889,14 +3889,13 @@ void should_returnTasks_sortedBy_BooleanProcessVariable() {
.body(TASK_IDS_JSON_PATH, contains(TASK_ID_1, TASK_ID_2));
}

/**
* From Postgres documentation: https://www.postgresql.org/docs/current/queries-order.html
* By default, null values sort as if larger than any non-null value;
* that is, NULLS FIRST is the default for DESC order, and NULLS LAST otherwise.
*/
@Test
void should_returnTasks_sortedByProcessVariables_respectingDefaultNullBehaviour() {
/*
* From Postgres documentation: https://www.postgresql.org/docs/current/queries-order.html
* By default, null values sort as if larger than any non-null value;
* that is, NULLS FIRST is the default for DESC order, and NULLS LAST otherwise.
*/

for (int i = 0; i < 5; i++) {
queryTestUtils
.buildProcessInstance()
Expand Down
Loading

0 comments on commit 90e730e

Please sign in to comment.