-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: move assign task to miranum platform (#373)
Move assign task use case to miranum platform
- Loading branch information
Showing
16 changed files
with
275 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="MiranumProcessIntegrationExample" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot" nameIsGenerated="true"> | ||
<module name="miranum-process-integration-example" /> | ||
<option name="SPRING_BOOT_MAIN_CLASS" value="io.miragon.miranum.platform.MiranumProcessIntegrationExample" /> | ||
<extension name="coverage"> | ||
<pattern> | ||
<option name="PATTERN" value="io.miragon.miranum.platform.*" /> | ||
<option name="ENABLED" value="true" /> | ||
</pattern> | ||
</extension> | ||
<extension name="net.ashald.envfile"> | ||
<option name="IS_ENABLED" value="true" /> | ||
<option name="IS_SUBST" value="false" /> | ||
<option name="IS_PATH_MACRO_SUPPORTED" value="false" /> | ||
<option name="IS_IGNORE_MISSING_FILES" value="false" /> | ||
<option name="IS_ENABLE_EXPERIMENTAL_INTEGRATIONS" value="false" /> | ||
<ENTRIES> | ||
<ENTRY IS_ENABLED="true" PARSER="runconfig" IS_EXECUTABLE="false" /> | ||
<ENTRY IS_ENABLED="true" PARSER="env" IS_EXECUTABLE="false" PATH="connect/examples/process-integration-example/local.env" /> | ||
</ENTRIES> | ||
</extension> | ||
<method v="2"> | ||
<option name="Make" enabled="true" /> | ||
</method> | ||
</configuration> | ||
</component> |
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
13 changes: 0 additions & 13 deletions
13
...-example/src/main/java/io/miragon/miranum/platform/adapter/in/task/dto/AssignTaskDto.java
This file was deleted.
Oops, something went wrong.
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
36 changes: 36 additions & 0 deletions
36
...ava/io/miragon/miranum/platform/tasklist/adapter/out/task/miranum/MiranumTaskAdapter.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,36 @@ | ||
package io.miragon.miranum.platform.tasklist.adapter.out.task.miranum; | ||
|
||
import io.miragon.miranum.connect.task.api.command.AssignUserTaskCommand; | ||
import io.miragon.miranum.connect.task.api.command.CompleteTaskCommand; | ||
import io.miragon.miranum.connect.task.api.exception.TaskOperationFailedException; | ||
import io.miragon.miranum.connect.task.impl.TaskOutPort; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.camunda.bpm.engine.TaskService; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MiranumTaskAdapter implements TaskOutPort { | ||
|
||
private final TaskService taskService; | ||
|
||
@Override | ||
public void completeTask(CompleteTaskCommand command) throws TaskOperationFailedException { | ||
throw new NotImplementedException("Not implemented"); | ||
} | ||
|
||
@Override | ||
public void assignUserTask(AssignUserTaskCommand command) throws TaskOperationFailedException { | ||
try { | ||
taskService.claim(command.getTaskId(), command.getAssignee()); | ||
} catch (final RuntimeException e) { | ||
throw new TaskOperationFailedException(e.getMessage()); | ||
} | ||
} | ||
|
||
@Override | ||
public void cancelUserTask(String taskId) throws TaskOperationFailedException { | ||
throw new NotImplementedException("Not implemented"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...main/java/io/miragon/miranum/platform/tasklist/application/port/in/WorkOnTaskUseCase.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,12 @@ | ||
package io.miragon.miranum.platform.tasklist.application.port.in; | ||
|
||
import io.miragon.miranum.platform.tasklist.exception.TaskAccessDeniedException; | ||
|
||
public interface WorkOnTaskUseCase { | ||
|
||
|
||
void assignUserTask(String user, String taskId, String assignee) throws TaskAccessDeniedException; | ||
|
||
void unassignUserTask(String user, String taskId) throws TaskAccessDeniedException; | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...main/java/io/miragon/miranum/platform/tasklist/application/service/AssignTaskService.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,31 @@ | ||
package io.miragon.miranum.platform.tasklist.application.service; | ||
|
||
import io.miragon.miranum.connect.task.api.TaskApi; | ||
import io.miragon.miranum.connect.task.api.command.AssignUserTaskCommand; | ||
import io.miragon.miranum.platform.security.authentication.UserAuthenticationProvider; | ||
import io.miragon.miranum.platform.tasklist.application.port.in.WorkOnTaskUseCase; | ||
import io.miragon.miranum.platform.tasklist.exception.TaskAccessDeniedException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class AssignTaskService implements WorkOnTaskUseCase { | ||
|
||
private final TaskApi connectTaskApi; | ||
private final UserAuthenticationProvider userAuthenticationProvider; | ||
|
||
@Override | ||
public void assignUserTask(String user, String taskId, String assignee) throws TaskAccessDeniedException { | ||
final AssignUserTaskCommand command = AssignUserTaskCommand.builder() | ||
.taskId(taskId) | ||
.assignee(assignee) | ||
.build(); | ||
connectTaskApi.assignUserTask(command, assignee, userAuthenticationProvider.getLoggedInUserRoles()); | ||
} | ||
|
||
@Override | ||
public void unassignUserTask(String user, String taskId) throws TaskAccessDeniedException { | ||
connectTaskApi.unassignUserTask(taskId, null, userAuthenticationProvider.getLoggedInUserRoles()); | ||
} | ||
} |
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
61 changes: 61 additions & 0 deletions
61
...java/io/miragon/miranum/platform/tasklist/adapter/out/miranum/MiranumTaskAdapterTest.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,61 @@ | ||
package io.miragon.miranum.platform.tasklist.adapter.out.miranum; | ||
|
||
import io.miragon.miranum.connect.task.api.command.AssignUserTaskCommand; | ||
import io.miragon.miranum.connect.task.api.exception.TaskOperationFailedException; | ||
import io.miragon.miranum.connect.task.impl.TaskOutPort; | ||
import io.miragon.miranum.platform.tasklist.adapter.out.task.miranum.MiranumTaskAdapter; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.camunda.bpm.engine.ProcessEngineException; | ||
import org.camunda.bpm.engine.TaskService; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.*; | ||
|
||
class MiranumTaskAdapterTest { | ||
|
||
private final TaskService taskService = mock(TaskService.class); | ||
private final TaskOutPort miranumTaskAdapter = new MiranumTaskAdapter(taskService); | ||
|
||
@Test | ||
void testAssignUserTask() { | ||
final AssignUserTaskCommand command = AssignUserTaskCommand.builder() | ||
.taskId("1") | ||
.assignee("testUser") | ||
.build(); | ||
miranumTaskAdapter.assignUserTask(command); | ||
|
||
final ArgumentCaptor<String> taskIdCaptor = ArgumentCaptor.forClass(String.class); | ||
final ArgumentCaptor<String> userCaptor = ArgumentCaptor.forClass(String.class); | ||
verify(taskService).claim(taskIdCaptor.capture(), userCaptor.capture()); | ||
|
||
assertThat(taskIdCaptor.getValue()).isEqualTo("1"); | ||
assertThat(userCaptor.getValue()).isEqualTo("testUser"); | ||
} | ||
|
||
@Test | ||
void testAssignUserTask_ThrowsTaskOperationFailedException() { | ||
doThrow(new ProcessEngineException("Error")).when(taskService).claim(anyString(), anyString()); | ||
assertThrows(TaskOperationFailedException.class, () -> { | ||
final AssignUserTaskCommand command = AssignUserTaskCommand.builder() | ||
.taskId("1") | ||
.assignee("testUser") | ||
.build(); | ||
miranumTaskAdapter.assignUserTask(command); | ||
}); | ||
} | ||
|
||
@Test | ||
void testCompleteTask() { | ||
assertThrows(NotImplementedException.class, () -> miranumTaskAdapter.completeTask(null)); | ||
} | ||
|
||
@Test | ||
void testCancelUserTask() { | ||
assertThrows(NotImplementedException.class, () -> miranumTaskAdapter.cancelUserTask(null)); | ||
} | ||
|
||
} |
Oops, something went wrong.