Skip to content

Commit

Permalink
Issue #547: adds findConnection by parent predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk-vi committed Aug 30, 2023
1 parent 9b2a707 commit 0259c25
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package io.openk9.datasource.service;

import io.openk9.common.graphql.util.relay.Connection;
import io.openk9.common.graphql.util.relay.GraphqlId;
import io.openk9.common.util.SortBy;
import io.openk9.datasource.mapper.DocTypeFieldMapper;
import io.openk9.datasource.model.Analyzer;
Expand All @@ -32,6 +33,10 @@

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
Expand All @@ -40,9 +45,6 @@
import java.util.Set;
import java.util.stream.Collectors;

;


@ApplicationScoped
public class DocTypeFieldService extends BaseK9EntityService<DocTypeField, DocTypeFieldDTO> {
DocTypeFieldService(DocTypeFieldMapper mapper) {
Expand Down Expand Up @@ -259,9 +261,32 @@ public Uni<Set<DocTypeField>> expandDocTypeFields(Collection<DocTypeField> docTy
});



}

public Uni<Connection<DocTypeField>> findConnection(
long parentId, String after, String before, Integer first, Integer last,
String searchText, Set<SortBy> sortByList) {


CriteriaBuilder criteriaBuilder = getCriteriaBuilder();

CriteriaQuery<DocTypeField> query =
criteriaBuilder.createQuery(getEntityClass());

Path<DocTypeField> root = query.from(getEntityClass());

Path<DocTypeField> parentField = root.get(DocTypeField_.parentDocTypeField);

return findConnection(
query, root,
parentId > 0
? criteriaBuilder.equal(parentField, parentId)
: criteriaBuilder.isNull(parentField),
getSearchFields(),
after, before, first, last, searchText, sortByList
);
}

public Uni<Void> loadDocTypeField(Set<DocTypeField> typeFields) {

return em.withTransaction(s -> {
Expand Down

0 comments on commit 0259c25

Please sign in to comment.