Skip to content

Commit fc14a7a

Browse files
committed
Refactor query construction to use QueryDSL predicates
Replaced string-based query construction with QueryDSL predicates for improved type safety and readability. Added a new `findCase` method to handle `Predicate` inputs, streamlining case search functionality. This change enhances maintainability and reduces the risk of query syntax errors.
1 parent ce6d954 commit fc14a7a

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

application-engine/src/main/java/com/netgrif/application/engine/menu/services/MenuItemService.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.netgrif.application.engine.workflow.service.interfaces.IDataService;
2929
import com.netgrif.application.engine.workflow.service.interfaces.ITaskService;
3030
import com.netgrif.application.engine.workflow.service.interfaces.IWorkflowService;
31+
import com.querydsl.core.types.Predicate;
3132
import lombok.RequiredArgsConstructor;
3233
import lombok.extern.slf4j.Slf4j;
3334
import org.springframework.data.domain.Page;
@@ -194,9 +195,9 @@ public Case findMenuItem(String identifier) {
194195

195196
@Override
196197
public Case findMenuItem(String identifier, boolean retry) {
197-
String query = String.format("processIdentifier:%s AND dataSet.%s.textValue.keyword:\"%s\"",
198-
MenuProcessRunner.MENU_NET_IDENTIFIER, MenuItemConstants.FIELD_IDENTIFIER, identifier);
199-
return findCase(MenuProcessRunner.MENU_NET_IDENTIFIER, query);
198+
return findCase(QCase.case$.processIdentifier
199+
.eq(MenuProcessRunner.MENU_NET_IDENTIFIER)
200+
.and(QCase.case$.dataSet.get(MenuItemConstants.FIELD_IDENTIFIER).value.eq(identifier)));
200201
}
201202

202203
/**
@@ -208,10 +209,10 @@ public Case findMenuItem(String identifier, boolean retry) {
208209
*/
209210
@Override
210211
public Case findMenuItem(String path, String name) {
211-
// TODO retry
212-
String query = String.format("processIdentifier:%s AND title.keyword:\"%s\" AND nodePath:\"%s\"",
213-
MenuProcessRunner.MENU_NET_IDENTIFIER, name, path);
214-
return findCase(MenuProcessRunner.MENU_NET_IDENTIFIER, query);
212+
return findCase(QCase.case$.processIdentifier
213+
.eq(MenuProcessRunner.MENU_NET_IDENTIFIER)
214+
.and(QCase.case$.title.eq(name))
215+
.and(QCase.case$.dataSet.get(MenuItemConstants.FIELD_NODE_PATH).value.eq(path)));
215216
}
216217

217218
/**
@@ -223,9 +224,9 @@ public Case findMenuItem(String path, String name) {
223224
@Override
224225
public Case findFolderCase(String path) {
225226
// TODO
226-
String query = String.format("processIdentifier:%s AND dataSet.%s.textValue.keyword:\"%s\"",
227-
MenuProcessRunner.MENU_NET_IDENTIFIER, MenuItemConstants.FIELD_NODE_PATH, path);
228-
return findCase(MenuProcessRunner.MENU_NET_IDENTIFIER, query);
227+
return findCase(QCase.case$.processIdentifier
228+
.eq(MenuProcessRunner.MENU_NET_IDENTIFIER)
229+
.and(QCase.case$.dataSet.get(MenuItemConstants.FIELD_NODE_PATH).value.eq(path)));
229230
}
230231

231232
/**
@@ -384,6 +385,10 @@ public Case removeChildItemFromParent(String folderId, Case childItem) {
384385
return workflowService.save(parentFolder);
385386
}
386387

388+
protected Case findCase(Predicate predicate) {
389+
return workflowService.searchOne(predicate);
390+
}
391+
387392
protected Case findCase(String processIdentifier, String query) {
388393
CaseSearchRequest request = CaseSearchRequest.builder()
389394
.process(Collections.singletonList(new CaseSearchRequest.PetriNet(processIdentifier)))

0 commit comments

Comments
 (0)