Skip to content
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

[NAE-1947] HistoryService findAllSetDataEventLogs is not working #242

Merged
merged 2 commits into from
Feb 12, 2024
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
@@ -1,5 +1,6 @@
package com.netgrif.application.engine.petrinet.domain.dataset.logic


import com.netgrif.application.engine.workflow.domain.Task
import com.querydsl.core.annotations.QueryExclude
import lombok.Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.netgrif.application.engine.petrinet.domain.dataset.logic;

import com.netgrif.application.engine.petrinet.domain.I18nString;
import com.netgrif.application.engine.workflow.domain.Task;
import com.querydsl.core.annotations.QueryExclude;
import lombok.Data;

import java.io.Serializable;
import java.util.*;

@Data
@QueryExclude
public class ChangedField implements Serializable {

private static final long serialVersionUID = 5299918326436828485L;

private String id;
private List<TaskPair> changedOn;
private Map<String, Object> attributes;

public ChangedField() {
attributes = new HashMap<>();
changedOn = new ArrayList<>();
}

public ChangedField(String id) {
this();
this.id = id;
}

public void wasChangedOn(Task task) {
wasChangedOn(task.getStringId(), task.getTransitionId());
}

public void wasChangedOn(String taskId, String transition) {
if (!isChangedOn(taskId)) {
changedOn.add(new TaskPair(taskId, transition));
}
}

public boolean isChangedOn(String taskId) {
return changedOn.stream().anyMatch(taskPair -> Objects.equals(taskPair.taskId, taskId));
}

public void addAttribute(String name, Object value) {
if (value instanceof I18nString)
attributes.put(name, ((I18nString) value).getDefaultValue());
else
attributes.put(name, value);
}

public void addBehavior(Map<String, Set<FieldBehavior>> behavior) {
Map<String, Map<String, Boolean>> behs = new HashMap<>();
behavior.forEach((trans, fieldBehaviors) -> {
Map<String, Boolean> b = new HashMap<>();
fieldBehaviors.forEach(fieldBehavior -> b.put(fieldBehavior.toString(), true));
behs.put(trans, b);
});
attributes.put("behavior", behs);
}

public void merge(ChangedField changedField) {
changedField.changedOn.forEach(taskPair -> wasChangedOn(taskPair.taskId, taskPair.transition));
this.attributes.putAll(changedField.attributes);
}

public Map<String, Object> getAttributes() {
return attributes;
}

public boolean equals(Object o) {
if (getClass() != o.getClass()) {
return false;
}
ChangedField that = (ChangedField) o;
return Objects.equals(id, that.id);
}

public int hashCode() {
return id.hashCode();
}

@Override
public String toString() {
return attributes.toString();
}

static class TaskPair implements Serializable {

private static final long serialVersionUID = 5299918326444428485L;

public String taskId;
public String transition;

public TaskPair() {
}

public TaskPair(String taskId, String transition) {
this.taskId = taskId;
this.transition = transition;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.netgrif.application.engine.workflow.domain.eventoutcomes.EventOutcome;
import com.netgrif.application.engine.workflow.domain.eventoutcomes.taskoutcomes.TaskEventOutcome;
import lombok.Data;
import lombok.Getter;

import java.util.HashMap;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import com.netgrif.application.engine.history.service.IHistoryService
import com.netgrif.application.engine.petrinet.domain.PetriNet
import com.netgrif.application.engine.petrinet.domain.VersionType
import com.netgrif.application.engine.petrinet.service.interfaces.IPetriNetService
import com.netgrif.application.engine.startup.ImportHelper
import com.netgrif.application.engine.startup.SuperCreator
import com.netgrif.application.engine.workflow.domain.Case
import com.netgrif.application.engine.workflow.domain.eventoutcomes.petrinetoutcomes.ImportPetriNetEventOutcome
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 org.junit.jupiter.api.BeforeEach
Expand Down Expand Up @@ -38,6 +40,9 @@ class HistoryServiceTest {
@Autowired
private ITaskService taskService

@Autowired
private IDataService dataService

@Autowired
private SuperCreator superCreator

Expand Down Expand Up @@ -76,4 +81,16 @@ class HistoryServiceTest {
assert historyService.findAllFinishTaskEventLogsByCaseId(caze.getStringId()).size() == count + 2 // 2 PRE POST
}

@Test
void findAllSetDataEventLogsByCaseId() {
Case caze = workflowService.createCase(net.getStringId(), "Test set data", "", superCreator.getLoggedSuper()).getCase()
int count = historyService.findAllSetDataEventLogsByCaseId(caze.getStringId()).size()
assert count == 0
String task = caze.tasks.find { it.transition == "1" }.task
Map dataToSet = ["number": ["value":"110101116103114105102","type":"number"]]
dataService.setData(task, ImportHelper.populateDataset(dataToSet))
Thread.sleep(1000) // HistoryService::save is @Async
assert historyService.findAllSetDataEventLogsByCaseId(caze.getStringId()).size() == count + 2 // 2 PRE POST
}

}
Loading