Skip to content

Commit

Permalink
KOGITO-9665 Deffer the injection of Processes in the Process Manageme…
Browse files Browse the repository at this point in the history
…nt Addon
  • Loading branch information
tiagodolphine committed Aug 1, 2023
1 parent acfb6ca commit 9030966
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,21 @@ public abstract class BaseProcessInstanceManagementResource<T> implements Proces
private static final String PROCESS_INSTANCE_NOT_FOUND = "Process instance with id %s not found";
private static final String PROCESS_INSTANCE_NOT_IN_ERROR = "Process instance with id %s is not in error state";

private Processes processes;
private Supplier<Processes> processes;

private Application application;

public BaseProcessInstanceManagementResource(Processes processes, Application application) {
this(() -> processes, application);
}

public BaseProcessInstanceManagementResource(Supplier<Processes> processes, Application application) {
this.processes = processes;
this.application = application;
}

public T doGetProcesses() {
return buildOkResponse(processes.processIds());
return buildOkResponse(processes.get().processIds());
}

public T doGetProcessInfo(String processId) {
Expand Down Expand Up @@ -209,7 +213,7 @@ private T executeOnInstanceInError(String processId, String processInstanceId, F
return badRequestResponse(PROCESS_AND_INSTANCE_REQUIRED);
}

Process<?> process = processes.processById(processId);
Process<?> process = processes.get().processById(processId);
if (process == null) {
return notFoundResponse(String.format(PROCESS_NOT_FOUND, processId));
}
Expand All @@ -235,7 +239,7 @@ private T executeOnProcessInstance(String processId, String processInstanceId, F
return badRequestResponse(PROCESS_AND_INSTANCE_REQUIRED);
}

Process<?> process = processes.processById(processId);
Process<?> process = processes.get().processById(processId);
if (process == null) {
return notFoundResponse(String.format(PROCESS_NOT_FOUND, processId));
}
Expand All @@ -256,7 +260,7 @@ private T executeOnProcess(String processId, Function<Process<?>, T> supplier) {
return badRequestResponse(PROCESS_REQUIRED);
}

Process<?> process = processes.processById(processId);
Process<?> process = processes.get().processById(processId);
if (process == null) {
return notFoundResponse(String.format(PROCESS_NOT_FOUND, processId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.kie.kogito.process.management;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
Expand All @@ -38,8 +39,8 @@ public ProcessInstanceManagementResource() {
}

@Inject
public ProcessInstanceManagementResource(Processes processes, Application application) {
super(processes, application);
public ProcessInstanceManagementResource(Instance<Processes> processes, Application application) {
super(processes::get, application);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Optional;

import javax.enterprise.inject.Instance;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
Expand Down Expand Up @@ -95,7 +96,9 @@ public void setup() {
processInstance = mock(ProcessInstance.class);
error = mock(ProcessError.class);

Instance<Processes> processesInstance = mock(Instance.class);
lenient().when(processes.processById(anyString())).thenReturn(process);
lenient().when(processesInstance.get()).thenReturn(processes);
lenient().when(process.instances()).thenReturn(instances);
lenient().when(instances.findById(anyString())).thenReturn(Optional.of(processInstance));
lenient().when(processInstance.error()).thenReturn(Optional.of(error));
Expand All @@ -106,7 +109,7 @@ public void setup() {
lenient().when(process.get()).thenReturn(mock(KogitoWorkflowProcess.class));

lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
resource = spy(new ProcessInstanceManagementResource(processes, application));
resource = spy(new ProcessInstanceManagementResource(processesInstance, application));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.kie.kogito.Application;
import org.kie.kogito.process.Processes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -34,6 +35,7 @@
public class ProcessInstanceManagementRestController extends BaseProcessInstanceManagementResource<ResponseEntity> {

@Autowired
@Lazy
public ProcessInstanceManagementRestController(Processes processes, Application application) {
super(processes, application);
}
Expand Down

0 comments on commit 9030966

Please sign in to comment.