Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.netgrif.application.engine.adapter.spring.actions.ActionApi;
import com.netgrif.application.engine.adapter.spring.actions.ActionFileHolder;
import com.netgrif.application.engine.adapter.spring.actions.ProcessAvailabilities;
import com.netgrif.application.engine.adapter.spring.actions.ProcessAvailability;
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;
Expand All @@ -15,6 +17,7 @@
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.PetriNet;
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;
Expand All @@ -25,6 +28,7 @@
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.petrinet.service.interfaces.IPetriNetService;
import com.netgrif.application.engine.workflow.params.CreateCaseParams;
import com.netgrif.application.engine.workflow.params.DeleteCaseParams;
import com.netgrif.application.engine.workflow.params.TaskParams;
Expand All @@ -40,12 +44,15 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Component
public class ActionApiImpl implements ActionApi {

private UserService userService;
Expand All @@ -60,6 +67,8 @@ public class ActionApiImpl implements ActionApi {

private IElasticTaskService elasticTaskService;

private IPetriNetService petriNetService;

@Autowired
public void setDataService(IDataService dataService) {
this.dataService = dataService;
Expand Down Expand Up @@ -90,6 +99,11 @@ public void setElasticTaskService(IElasticTaskService elasticTaskService) {
this.elasticTaskService = elasticTaskService;
}

@Autowired
public void setPetriNetService(IPetriNetService petriNetService) {
this.petriNetService = petriNetService;
}

@Override
public GetDataEventOutcome getData(String taskId, Map<String, String> params) {
log.debug("Getting data for task [{}] with params: [{}]", taskId, params == null ? "null" : params.toString());
Expand Down Expand Up @@ -269,6 +283,12 @@ public AbstractUser getSystemUser() {
return userService.getSystem();
}

@Override
public AuthPrincipalDto getSystemUserDto() {
AbstractUser systemUser = getSystemUser();
return new AuthPrincipalDto(systemUser.getUsername(), systemUser.getRealmId(), null);
}

@Override
public SetDataEventOutcome saveFile(String taskId, String fieldId, ActionFileHolder file, Map<String, String> params) {
log.debug("Saving file [{}] for task [{}] and field [{}] with params [{}]", file.getFileName(), taskId, fieldId, params);
Expand Down Expand Up @@ -325,6 +345,41 @@ public ActionFileHolder getFileByCaseAndName(String caseId, String fieldId, Stri
}
}

@Override
public boolean isProcessUp(String processIdentifier) {
return getProcessAvailability(processIdentifier).isUp();
}

@Override
public boolean isProcessDown(String processIdentifier) {
return getProcessAvailability(processIdentifier).isDown();
}

@Override
public ProcessAvailability getProcessAvailability(String processIdentifier) {
PetriNet petriNet = petriNetService.getDefaultVersionByIdentifier(processIdentifier);
if (petriNet == null) {
return ProcessAvailability.notFound(processIdentifier);
}
return ProcessAvailability.from(processIdentifier, true);
}
Comment thread
machacjozef marked this conversation as resolved.

@Override
public ProcessAvailabilities getProcessAvailability(List<String> processIdentifiers) {
Objects.requireNonNull(processIdentifiers, "processIdentifiers cannot be null");
return new ProcessAvailabilities(processIdentifiers.stream()
.map(this::getProcessAvailability)
.collect(Collectors.toList()));
}

@Override
public ProcessAvailabilities getProcessAvailability(String... processIdentifiers) {
Objects.requireNonNull(processIdentifiers, "processIdentifiers cannot be null");
return new ProcessAvailabilities(Arrays.stream(processIdentifiers)
.map(this::getProcessAvailability)
.collect(Collectors.toList()));
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

private AbstractUser resolveAbstractUser(AuthPrincipalDto authPrincipalDto) {
if (authPrincipalDto == null) {
throw new IllegalArgumentException("AuthPrincipalDto cannot be null.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ public interface ActionApi {
*/
AbstractUser getSystemUser();

AuthPrincipalDto getSystemUserDto();

SetDataEventOutcome saveFile(String taskId, String fieldId, ActionFileHolder file, Map<String, String> params);

SetDataEventOutcome saveFiles(String taskId, String fieldId, ActionFileHolder[] files, Map<String, String> params);
Expand All @@ -283,4 +285,14 @@ public interface ActionApi {
ActionFileHolder getFile(String caseId, String fieldId, Boolean forPreview, Map<String, String> params) throws IOException;

ActionFileHolder getFileByCaseAndName(String caseId, String fieldId, String name, Map<String, String> params) throws IOException;

boolean isProcessUp(String processIdentifier);

boolean isProcessDown(String processIdentifier);

ProcessAvailability getProcessAvailability(String processIdentifier);

ProcessAvailabilities getProcessAvailability(List<String> processIdentifiers);

ProcessAvailabilities getProcessAvailability(String... processIdentifiers);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.netgrif.application.engine.adapter.spring.actions;

import java.util.List;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
import java.util.Objects;

/**
* Wrapper for list of {@link ProcessAvailability}
* Use for convenient check of process availability
*
* @param availabilities
*/
public record ProcessAvailabilities(List<ProcessAvailability> availabilities) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.

public ProcessAvailabilities {
availabilities = List.copyOf(availabilities);
}

/**
* Checks if a process with the given identifier is in the "up" state.
* @param processIdentifier process identifier
* @return true if a process is up, false otherwise
*/
public boolean isUp(String processIdentifier) {
return is(processIdentifier, ProcessAvailability.Status.UP);
}


/**
* Checks if a process with the given identifier is in the "down" state.
*
* @param processIdentifier the unique identifier of the process to check
* @return true if the process is down, false otherwise
*/
public boolean isDown(String processIdentifier) {
return is(processIdentifier, ProcessAvailability.Status.DOWN);
}

/**
* Determines if a process with the specified process ID has a status of "not found."
*
* @param processIdentifier the identifier of the process to check
* @return true if the process with the given ID has a status of "not found," false otherwise
*/
public boolean isNotFound(String processIdentifier) {
return is(processIdentifier, ProcessAvailability.Status.NOT_FOUND);
}

/**
* Checks if any of the processes in the list are in the "up" status.
*
* @return true if at least one process has a status of "up"; false otherwise
*/
public boolean isAnyUp() {
return isAny(ProcessAvailability.Status.UP);
}

/**
* Checks if any of the processes in the list are in the "DOWN" status.
*
* @return true if at least one process has a status of "DOWN", false otherwise
*/
public boolean isAnyDown() {
return isAny(ProcessAvailability.Status.DOWN);
}

/**
* Checks if any process in the list of {@link ProcessAvailability} instances is in the "not found" state.
*
* @return true if at least one process has a status of "NOT_FOUND", false otherwise
*/
public boolean isAnyNotFound() {
return isAny(ProcessAvailability.Status.NOT_FOUND);
}

/**
* Checks if all processes in the list are in the "UP" state.
*
* @return true if all processes are in the "UP" state, false otherwise
*/
public boolean isAllUp() {
return isAll(ProcessAvailability.Status.UP);
}

/**
* Checks if all processes in the list are in the "down" state.
*
* @return true if all processes are in the "down" state, false otherwise
*/
public boolean isAllDown() {
return isAll(ProcessAvailability.Status.DOWN);
}

/**
* Determines if all processes in the list are in the "Not Found" state.
*
* @return true if all processes have a status of "Not Found," false otherwise
*/
public boolean isAllNotFound() {
return isAll(ProcessAvailability.Status.NOT_FOUND);
}

private boolean is(String processIdentifier, ProcessAvailability.Status status) {
return availabilities.stream()
.anyMatch(processAvailability -> Objects.equals(processIdentifier, processAvailability.processIdentifier()) && processAvailability.status() == status);
}

private boolean isAny(ProcessAvailability.Status status) {
return availabilities.stream().anyMatch(processAvailability -> processAvailability.status() == status);
}

private boolean isAll(ProcessAvailability.Status status) {
return availabilities != null && !availabilities.isEmpty() && availabilities.stream().allMatch(processAvailability -> processAvailability.status() == status);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.netgrif.application.engine.adapter.spring.actions;

/**
* Represents the availability status of a process.
* This class encapsulates information about a process's identifier and its status.
* It provides utility methods to interpret and construct instances based on different inputs.
*/
public record ProcessAvailability(String processIdentifier, Status status) {

public static ProcessAvailability from(String processIdentifier, Boolean status) {
return new ProcessAvailability(processIdentifier, Status.from(status));
}

public static ProcessAvailability notFound(String processIdentifier) {
return new ProcessAvailability(processIdentifier, Status.NOT_FOUND);
}

/**
* Checks if the process is in the "UP" state.
*
* @return true if the process status is "UP"; false otherwise
*/
public boolean isUp() {
return status == Status.UP;
}

/**
* Checks if the current status is "DOWN".
*
* @return true if the status is "DOWN", false otherwise
*/
public boolean isDown() {
return status == Status.DOWN;
}

/**
* Checks if the status of the process is "not found."
*
* @return true if the status is "NOT_FOUND," false otherwise
*/
public boolean isNotFound() {
return status == Status.NOT_FOUND;
}

public enum Status {
UP, DOWN, NOT_FOUND;

public static Status from(Boolean isUp) {
if (isUp == null) {
return NOT_FOUND;
}
return isUp ? UP : DOWN;
}
}
}
Loading