TSK-1107 Use userId-parameter in contructor of TaskanaHistoryEvent

-Prevents unwanted INTERNAL access
This commit is contained in:
Jörg Heffner 2020-02-11 12:05:24 +01:00
parent 38d5c8535c
commit 448d4fb8fc
15 changed files with 45 additions and 46 deletions

View File

@ -5,7 +5,7 @@ import pro.taskana.spi.history.api.events.TaskanaHistoryEvent;
/** This entity contains the most important information about a history event. */
public class HistoryEventImpl extends TaskanaHistoryEvent {
public HistoryEventImpl() {
super();
public HistoryEventImpl(String userId) {
super(userId);
}
}

View File

@ -596,7 +596,7 @@ public class HistoryQueryImpl implements HistoryQuery {
@Override
public HistoryEventImpl single() {
LOGGER.debug("entry to list(), this = {}", this);
HistoryEventImpl result = new HistoryEventImpl();
HistoryEventImpl result = null;
try {
taskanaHistoryEngine.openConnection();
this.maxRows = 1;

View File

@ -112,8 +112,9 @@ public class AbstractAccTest {
String taskId,
String type,
String comment,
String previousWorkbasketId) {
HistoryEventImpl historyEvent = new HistoryEventImpl();
String previousWorkbasketId,
String userid) {
HistoryEventImpl historyEvent = new HistoryEventImpl(userid);
historyEvent.setWorkbasketKey(workbasketKey);
historyEvent.setTaskId(taskId);
historyEvent.setEventType(type);

View File

@ -37,7 +37,7 @@ public class TaskanaEngineConfigurationTest extends AbstractAccTest {
getHistoryService()
.create(
AbstractAccTest.createHistoryEvent(
"wbKey1", "taskId1", "type1", "Some comment", "wbKey2"));
"wbKey1", "taskId1", "type1", "Some comment", "wbKey2","someUserId"));
count = getHistoryService().createHistoryQuery().workbasketKeyIn("wbKey1").count();
assertEquals(1, count);
}

View File

@ -68,11 +68,10 @@ public class HistoryQueryImplTest {
String userId,
String comment,
Instant created) {
HistoryEventImpl he = new HistoryEventImpl();
HistoryEventImpl he = new HistoryEventImpl(userId);
he.setTaskId(taskId);
he.setWorkbasketKey(workbasketKey);
he.setEventType(type);
he.setUserId(userId);
he.setComment(comment);
he.setCreated(created);
return he;

View File

@ -96,7 +96,8 @@ public class SimpleHistoryServiceImplTest {
@Test
public void testCreateEvent() throws SQLException {
HistoryEventImpl expectedWb =
AbstractAccTest.createHistoryEvent("wbKey1", "taskId1", "type1", "Some comment", "wbKey2");
AbstractAccTest.createHistoryEvent(
"wbKey1", "taskId1", "type1", "Some comment", "wbKey2", "someUserId");
doNothing().when(historyEventMapperMock).insert(expectedWb);
cutSpy.create(expectedWb);
@ -110,7 +111,8 @@ public class SimpleHistoryServiceImplTest {
public void testQueryEvent() throws SQLException {
List<HistoryEventImpl> returnList = new ArrayList<>();
returnList.add(
AbstractAccTest.createHistoryEvent("wbKey1", "taskId1", "type1", "Some comment", "wbKey2"));
AbstractAccTest.createHistoryEvent(
"wbKey1", "taskId1", "type1", "Some comment", "wbKey2", "someUserId"));
doReturn(returnList).when(historyQueryMapperMock).queryHistoryEvent(any());
final List<HistoryEventImpl> result = cutSpy.createHistoryQuery().taskIdIn("taskId1").list();

View File

@ -2,8 +2,6 @@ package pro.taskana.spi.history.api.events;
import java.time.Instant;
import pro.taskana.common.internal.security.CurrentUserContext;
/** Super class for all specific events from the TASKANA engine. */
public class TaskanaHistoryEvent {
@ -34,8 +32,8 @@ public class TaskanaHistoryEvent {
protected String oldData;
protected String newData;
public TaskanaHistoryEvent() {
userId = CurrentUserContext.getUserid();
public TaskanaHistoryEvent(String userId) {
this.userId = userId;
}
public long getId() {

View File

@ -5,8 +5,8 @@ import pro.taskana.task.api.Task;
/** Event fired if a task is cancelled to be claimed. */
public class ClaimCancelledEvent extends TaskEvent {
public ClaimCancelledEvent(Task task) {
super(task);
public ClaimCancelledEvent(Task task, String userId) {
super(task, userId);
eventType = "TASK_CLAIM_CANCELLED";
created = task.getModified();
}

View File

@ -5,8 +5,8 @@ import pro.taskana.task.api.Task;
/** Event fired if a task is claimed. */
public class ClaimedEvent extends TaskEvent {
public ClaimedEvent(Task task) {
super(task);
public ClaimedEvent(Task task, String userId) {
super(task, userId);
setEventType("TASK_CLAIMED");
created = task.getClaimed();
}

View File

@ -6,14 +6,14 @@ import pro.taskana.task.api.TaskSummary;
/** Event fired if a task is completed. */
public class CompletedEvent extends TaskEvent {
public CompletedEvent(Task completedTask) {
super(completedTask);
public CompletedEvent(Task completedTask, String userId) {
super(completedTask, userId);
eventType = "TASK_COMPLETED";
created = completedTask.getCompleted();
}
public CompletedEvent(TaskSummary completedTask) {
super(completedTask);
public CompletedEvent(TaskSummary completedTask, String userId) {
super(completedTask, userId);
eventType = "TASK_COMPLETED";
created = completedTask.getCompleted();
}

View File

@ -5,8 +5,8 @@ import pro.taskana.task.api.Task;
/** Event fired if a task is created. */
public class CreatedEvent extends TaskEvent {
public CreatedEvent(Task task) {
super(task);
public CreatedEvent(Task task, String userId) {
super(task, userId);
eventType = "TASK_CREATED";
created = task.getCreated();
}

View File

@ -7,8 +7,8 @@ import pro.taskana.task.api.TaskSummary;
/** Super class for all task related events. */
public class TaskEvent extends TaskanaHistoryEvent {
public TaskEvent(Task task) {
super();
public TaskEvent(Task task, String userId) {
super(userId);
taskId = task.getId();
businessProcessId = task.getBusinessProcessId();
parentBusinessProcessId = task.getParentBusinessProcessId();
@ -31,8 +31,8 @@ public class TaskEvent extends TaskanaHistoryEvent {
}
}
public TaskEvent(TaskSummary task) {
super();
public TaskEvent(TaskSummary task, String userId) {
super(userId);
taskId = task.getId();
businessProcessId = task.getBusinessProcessId();
parentBusinessProcessId = task.getParentBusinessProcessId();

View File

@ -12,8 +12,8 @@ public class TransferredEvent extends TaskEvent {
private static final Logger LOGGER = LoggerFactory.getLogger(TransferredEvent.class);
public TransferredEvent(
Task task, WorkbasketSummary oldWorkbasket, WorkbasketSummary newWorkbasket) {
super(task);
Task task, WorkbasketSummary oldWorkbasket, WorkbasketSummary newWorkbasket, String userId) {
super(task, userId);
eventType = "TASK_TRANSFERRED";
created = task.getModified();
this.oldValue = oldWorkbasket.getId();

View File

@ -212,7 +212,7 @@ public class TaskServiceImpl implements TaskService {
this.taskMapper.insert(task);
LOGGER.debug("Method createTask() created Task '{}'.", task.getId());
if (HistoryEventProducer.isHistoryEnabled()) {
historyEventProducer.createEvent(new CreatedEvent(task));
historyEventProducer.createEvent(new CreatedEvent(task, CurrentUserContext.getUserid()));
}
} catch (PersistenceException e) {
// Error messages:
@ -521,8 +521,7 @@ public class TaskServiceImpl implements TaskService {
List<String> changedTasks = new ArrayList<>();
if (!taskSummaries.isEmpty()) {
changedTasks =
taskSummaries.stream().map(TaskSummary::getId).collect(Collectors.toList());
changedTasks = taskSummaries.stream().map(TaskSummary::getId).collect(Collectors.toList());
taskMapper.updateTasks(changedTasks, updated, fieldSelector);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
@ -562,8 +561,7 @@ public class TaskServiceImpl implements TaskService {
List<String> changedTasks = new ArrayList<>();
if (!taskSummaries.isEmpty()) {
changedTasks =
taskSummaries.stream().map(TaskSummary::getId).collect(Collectors.toList());
changedTasks = taskSummaries.stream().map(TaskSummary::getId).collect(Collectors.toList());
taskMapper.updateTasks(changedTasks, updatedTask, fieldSelector);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(
@ -781,7 +779,7 @@ public class TaskServiceImpl implements TaskService {
taskMapper.update(task);
LOGGER.debug("Task '{}' claimed by user '{}'.", taskId, userId);
if (HistoryEventProducer.isHistoryEnabled()) {
historyEventProducer.createEvent(new ClaimedEvent(task));
historyEventProducer.createEvent(new ClaimedEvent(task, CurrentUserContext.getUserid()));
}
} finally {
taskanaEngine.returnConnection();
@ -820,7 +818,8 @@ public class TaskServiceImpl implements TaskService {
taskMapper.update(task);
LOGGER.debug("Task '{}' unclaimed by user '{}'.", taskId, userId);
if (HistoryEventProducer.isHistoryEnabled()) {
historyEventProducer.createEvent(new ClaimCancelledEvent(task));
historyEventProducer.createEvent(
new ClaimCancelledEvent(task, CurrentUserContext.getUserid()));
}
} finally {
taskanaEngine.returnConnection();
@ -871,7 +870,7 @@ public class TaskServiceImpl implements TaskService {
taskMapper.update(task);
LOGGER.debug("Task '{}' completed by user '{}'.", taskId, userId);
if (HistoryEventProducer.isHistoryEnabled()) {
historyEventProducer.createEvent(new CompletedEvent(task));
historyEventProducer.createEvent(new CompletedEvent(task, CurrentUserContext.getUserid()));
}
} finally {
taskanaEngine.returnConnection();
@ -1001,9 +1000,7 @@ public class TaskServiceImpl implements TaskService {
}
private void standardSettings(
TaskImpl task,
Classification classification,
PrioDurationHolder prioDurationFromAttachments)
TaskImpl task, Classification classification, PrioDurationHolder prioDurationFromAttachments)
throws InvalidArgumentException {
LOGGER.debug("entry to standardSettings()");
final Instant now = Instant.now();
@ -1581,9 +1578,7 @@ public class TaskServiceImpl implements TaskService {
}
private void updateClassificationRelatedProperties(
TaskImpl oldTaskImpl,
TaskImpl newTaskImpl,
PrioDurationHolder prioDurationFromAttachments)
TaskImpl oldTaskImpl, TaskImpl newTaskImpl, PrioDurationHolder prioDurationFromAttachments)
throws ClassificationNotFoundException {
LOGGER.debug("entry to updateClassificationRelatedProperties()");
// insert Classification specifications if Classification is given.
@ -1967,7 +1962,10 @@ public class TaskServiceImpl implements TaskService {
}
private void createTasksCompletedEvents(List<TaskSummary> taskSummaries) {
taskSummaries.forEach(task -> historyEventProducer.createEvent(new CompletedEvent(task)));
taskSummaries.forEach(
task ->
historyEventProducer.createEvent(
new CompletedEvent(task, CurrentUserContext.getUserid())));
}
private static class PrioDurationHolder extends Pair<Duration, Integer> {

View File

@ -363,7 +363,8 @@ public class TaskTransferrer {
private void createTaskTransferredEvent(
Task task, WorkbasketSummary oldWorkbasketSummary, WorkbasketSummary newWorkbasketSummary) {
historyEventProducer.createEvent(
new TransferredEvent(task, oldWorkbasketSummary, newWorkbasketSummary));
new TransferredEvent(
task, oldWorkbasketSummary, newWorkbasketSummary, CurrentUserContext.getUserid()));
}
private void updateTasksToBeTransferred(