-
Notifications
You must be signed in to change notification settings - Fork 6
[NAE-2229] Action API #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
renczesstefan
wants to merge
19
commits into
release/7.0.0-rev9
Choose a base branch
from
NAE-2229
base: release/7.0.0-rev9
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
35b953e
- simplified AbstractActionAPI
renczesstefan c50012b
Add Action API implementation and related configurations
renczesstefan 78de22f
Refactor ActionApi methods to enhance type safety and clarity
renczesstefan 8cb4abc
Refactor Action API to use AuthPrincipalDto for user context
renczesstefan 111827a
Add searchUsers, findCase, and findTask methods to Action API
renczesstefan 582f418
Refactor Querydsl dependencies and package structure.
renczesstefan 95e084d
Refactor to use Map instead of HashMap and add method resolution logic
renczesstefan cf80649
Refactor ActionApiImpl and enhance exception class.
renczesstefan 42ec6b4
Refine ConditionalOnMissingBean annotation for ActionApi
renczesstefan a1f164d
Add annotations to exclude sessionId from toString and equals
renczesstefan 9eacdd0
Fix typo in enum constant name from SEARCH_USER to SEARCH_USERS
renczesstefan 6642234
- removed duplicate dependency
renczesstefan 9e726d1
- removed unused import
renczesstefan 905a142
Remove redundant Serializable implementation in exception class
renczesstefan c497aba
Remove redundant Serializable implementation in exception class
renczesstefan f5df0dc
Enhance method handling and enforce non-null constraints
renczesstefan e1dad6c
Remove @NonNull annotations from AuthPrincipalDto fields
renczesstefan fffff2d
Merge branch 'release/7.0.0-rev9' into NAE-2229
renczesstefan 50a4fb9
Improve null handling, performance, and serialization
renczesstefan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...n-engine/src/main/java/com/netgrif/application/engine/actions/ActionApiConfiguration.java
This file contains hidden or 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,16 @@ | ||
| package com.netgrif.application.engine.actions; | ||
|
|
||
| import com.netgrif.application.engine.adapter.spring.actions.ActionApi; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class ActionApiConfiguration { | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean(ActionApi.class) | ||
| public ActionApi actionApi() { | ||
| return new ActionApiImpl(); | ||
| } | ||
| } |
187 changes: 187 additions & 0 deletions
187
application-engine/src/main/java/com/netgrif/application/engine/actions/ActionApiImpl.java
This file contains hidden or 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,187 @@ | ||
| package com.netgrif.application.engine.actions; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| import com.netgrif.application.engine.adapter.spring.actions.ActionApi; | ||
| import com.netgrif.application.engine.auth.service.UserService; | ||
| import com.netgrif.application.engine.elastic.service.interfaces.IElasticCaseService; | ||
| import com.netgrif.application.engine.elastic.service.interfaces.IElasticTaskService; | ||
| import com.netgrif.application.engine.elastic.web.requestbodies.CaseSearchRequest; | ||
| import com.netgrif.application.engine.elastic.web.requestbodies.ElasticTaskSearchRequest; | ||
| import com.netgrif.application.engine.objects.auth.domain.AbstractUser; | ||
| import com.netgrif.application.engine.objects.auth.domain.ActorTransformer; | ||
| import com.netgrif.application.engine.objects.auth.domain.LoggedUser; | ||
| import com.netgrif.application.engine.objects.auth.domain.User; | ||
| import com.netgrif.application.engine.objects.auth.dto.AuthPrincipalDto; | ||
| import com.netgrif.application.engine.objects.petrinet.domain.throwable.TransitionNotExecutableException; | ||
| import com.netgrif.application.engine.objects.workflow.domain.Case; | ||
| import com.netgrif.application.engine.objects.workflow.domain.Task; | ||
| import com.netgrif.application.engine.objects.workflow.domain.eventoutcomes.caseoutcomes.CreateCaseEventOutcome; | ||
| import com.netgrif.application.engine.objects.workflow.domain.eventoutcomes.caseoutcomes.DeleteCaseEventOutcome; | ||
| import com.netgrif.application.engine.objects.workflow.domain.eventoutcomes.dataoutcomes.GetDataEventOutcome; | ||
| import com.netgrif.application.engine.objects.workflow.domain.eventoutcomes.dataoutcomes.SetDataEventOutcome; | ||
| import com.netgrif.application.engine.objects.workflow.domain.eventoutcomes.taskoutcomes.AssignTaskEventOutcome; | ||
| import com.netgrif.application.engine.objects.workflow.domain.eventoutcomes.taskoutcomes.CancelTaskEventOutcome; | ||
| import com.netgrif.application.engine.objects.workflow.domain.eventoutcomes.taskoutcomes.FinishTaskEventOutcome; | ||
| import com.netgrif.application.engine.workflow.service.interfaces.IDataService; | ||
| import com.netgrif.application.engine.workflow.service.interfaces.ITaskService; | ||
| import com.netgrif.application.engine.workflow.service.interfaces.IWorkflowService; | ||
| import com.querydsl.core.types.Predicate; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.context.i18n.LocaleContextHolder; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| @Slf4j | ||
| public class ActionApiImpl implements ActionApi { | ||
|
|
||
| private UserService userService; | ||
|
|
||
| private IDataService dataService; | ||
|
|
||
| private ITaskService taskService; | ||
|
|
||
| private IWorkflowService workflowService; | ||
|
|
||
| private IElasticCaseService elasticCaseService; | ||
|
|
||
| private IElasticTaskService elasticTaskService; | ||
|
|
||
| private ObjectMapper objectMapper; | ||
|
|
||
| @Autowired | ||
| public void setDataService(IDataService dataService) { | ||
| this.dataService = dataService; | ||
| } | ||
|
|
||
| @Autowired | ||
| public void setTaskService(ITaskService taskService) { | ||
| this.taskService = taskService; | ||
| } | ||
|
|
||
| @Autowired | ||
| public void setWorkflowService(IWorkflowService workflowService) { | ||
| this.workflowService = workflowService; | ||
| } | ||
|
|
||
| @Autowired | ||
| public void setElasticCaseService(IElasticCaseService elasticCaseService) { | ||
| this.elasticCaseService = elasticCaseService; | ||
| } | ||
|
|
||
| @Autowired | ||
| public void setUserService(UserService userService) { | ||
| this.userService = userService; | ||
| } | ||
|
|
||
| @Autowired | ||
| public void setElasticTaskService(IElasticTaskService elasticTaskService) { | ||
| this.elasticTaskService = elasticTaskService; | ||
| } | ||
|
|
||
| @Autowired | ||
| public void setObjectMapper(ObjectMapper objectMapper) { | ||
| this.objectMapper = objectMapper; | ||
| } | ||
|
|
||
| @Override | ||
| public GetDataEventOutcome getData(String taskId, Map<String, String> params) { | ||
| return dataService.getData(taskId, params); | ||
| } | ||
|
|
||
| @Override | ||
| public SetDataEventOutcome setData(String taskId, Map<String, Map<String, String>> dataSet, Map<String, String> params) throws JsonProcessingException { | ||
| ObjectMapper mapper = new ObjectMapper(); | ||
| String json = mapper.writeValueAsString(dataSet); | ||
| ObjectNode values = (ObjectNode) mapper.readTree(json); | ||
| return dataService.setData(taskId, values, params); | ||
| } | ||
renczesstefan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public Page<Case> searchCases(String processIdentifier, Predicate predicate, Pageable pageable) { | ||
| return workflowService.search(predicate, pageable); | ||
| } | ||
renczesstefan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public Page<Case> searchCases(List<String> elasticStringQueries, AuthPrincipalDto authPrincipalDto, Pageable pageable, Boolean isIntersection) { | ||
| boolean intersect = Boolean.TRUE.equals(isIntersection); | ||
| List<CaseSearchRequest> caseSearchRequests = elasticStringQueries.stream().map(query -> CaseSearchRequest.builder().query(query).build()).toList(); | ||
| LoggedUser loggedUser = ActorTransformer.toLoggedUser(resolveAbstractUser(authPrincipalDto)); | ||
| Locale locale = LocaleContextHolder.getLocale(); | ||
| return elasticCaseService.search(caseSearchRequests, loggedUser, pageable, locale, intersect); | ||
| } | ||
|
|
||
| @Override | ||
| public CreateCaseEventOutcome createCaseByIdentifier(String identifier, String title, String color, AuthPrincipalDto authPrincipalDto, Map<String, String> params) { | ||
| LoggedUser loggedUser = ActorTransformer.toLoggedUser(resolveAbstractUser(authPrincipalDto)); | ||
| Locale locale = LocaleContextHolder.getLocale(); | ||
| return workflowService.createCaseByIdentifier(identifier, title, color, loggedUser, locale, params); | ||
| } | ||
|
|
||
| @Override | ||
| public DeleteCaseEventOutcome deleteCase(String caseId, Map<String, String> params) { | ||
| return workflowService.deleteCase(caseId, params); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<Task> searchTasks(String processIdentifier, Predicate predicate, Pageable pageable) { | ||
| return taskService.search(predicate, pageable); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<Task> searchTasks(List<String> elasticStringQueries, AuthPrincipalDto authPrincipalDto, Pageable pageable, Boolean isIntersection) { | ||
| boolean intersect = Boolean.TRUE.equals(isIntersection); | ||
| List<ElasticTaskSearchRequest> taskSearchRequests = elasticStringQueries.stream().map(query -> ElasticTaskSearchRequest.builder().query(query).build()).toList(); | ||
| LoggedUser loggedUser = ActorTransformer.toLoggedUser(resolveAbstractUser(authPrincipalDto)); | ||
| Locale locale = LocaleContextHolder.getLocale(); | ||
| return elasticTaskService.search(taskSearchRequests, loggedUser, pageable, locale, intersect); | ||
| } | ||
|
|
||
| @Override | ||
| public AssignTaskEventOutcome assignTask(String taskId, AuthPrincipalDto authPrincipalDto, Map<String, String> params) throws TransitionNotExecutableException { | ||
| Task task = taskService.findOne(taskId); | ||
| AbstractUser user = resolveAbstractUser(authPrincipalDto); | ||
| return taskService.assignTask(task, user, params); | ||
| } | ||
|
|
||
| @Override | ||
| public CancelTaskEventOutcome cancelTask(String taskId, AuthPrincipalDto authPrincipalDto, Map<String, String> params) { | ||
| Task task = taskService.findOne(taskId); | ||
| AbstractUser user = resolveAbstractUser(authPrincipalDto); | ||
| return taskService.cancelTask(task, user, params); | ||
| } | ||
|
|
||
| @Override | ||
| public FinishTaskEventOutcome finishTask(String taskId, AuthPrincipalDto authPrincipalDto, Map<String, String> params) throws TransitionNotExecutableException { | ||
| Task task = taskService.findOne(taskId); | ||
| AbstractUser user = resolveAbstractUser(authPrincipalDto); | ||
| return taskService.finishTask(task, user, params); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public Case findCase(String caseId) { | ||
| return workflowService.findOne(caseId); | ||
| } | ||
|
|
||
| @Override | ||
| public Task findTask(String taskId) { | ||
| return taskService.findOne(taskId); | ||
| } | ||
|
|
||
| @Override | ||
| public Page<User> searchUsers(Predicate predicate, Pageable pageable, String realmId) { | ||
| return userService.search(predicate, pageable, realmId); | ||
| } | ||
|
|
||
| private AbstractUser resolveAbstractUser(AuthPrincipalDto authPrincipalDto) { | ||
| if (authPrincipalDto == null) { | ||
| throw new IllegalArgumentException("AuthPrincipalDto cannot be null."); | ||
| } | ||
| Optional<AbstractUser> userOptional = userService.findUserByUsername(authPrincipalDto.getUsername(), authPrincipalDto.getRealmId()); | ||
| return userOptional.orElseThrow(() -> new IllegalArgumentException("User with username [%s] and realm ID [%s] not found".formatted(authPrincipalDto.getUsername(), authPrincipalDto.getRealmId()))); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
25 changes: 25 additions & 0 deletions
25
...brary/src/main/java/com/netgrif/application/engine/objects/auth/dto/AuthPrincipalDto.java
This file contains hidden or 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,25 @@ | ||
| package com.netgrif.application.engine.objects.auth.dto; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnore; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.ToString; | ||
|
|
||
| import java.io.Serial; | ||
| import java.io.Serializable; | ||
|
|
||
| @Data | ||
| public class AuthPrincipalDto implements Serializable { | ||
|
|
||
| @Serial | ||
| private static final long serialVersionUID = 6725518942728316525L; | ||
|
|
||
| private String username; | ||
|
|
||
| private String realmId; | ||
|
|
||
| @ToString.Exclude | ||
| @EqualsAndHashCode.Exclude | ||
| @JsonIgnore | ||
| private String sessionId; | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.