diff --git a/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/main/java/org/activiti/cloud/services/audit/events/ProcessEngineEventEntity.java b/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/main/java/org/activiti/cloud/services/audit/events/ProcessEngineEventEntity.java index 4138f0e5..778fff04 100644 --- a/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/main/java/org/activiti/cloud/services/audit/events/ProcessEngineEventEntity.java +++ b/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/main/java/org/activiti/cloud/services/audit/events/ProcessEngineEventEntity.java @@ -47,6 +47,7 @@ @JsonSubTypes.Type(value = TaskCreatedEventEntity.class, name = TaskCreatedEventEntity.TASK_CREATED_EVENT), @JsonSubTypes.Type(value = TaskAssignedEventEntity.class, name = TaskAssignedEventEntity.TASK_ASSIGNED_EVENT), @JsonSubTypes.Type(value = TaskCompletedEventEntity.class, name = TaskCompletedEventEntity.TASK_COMPLETED_EVENT), + @JsonSubTypes.Type(value = TaskCancelledEventEntity.class, name = TaskCancelledEventEntity.TASK_CANCELLED_EVENT), @JsonSubTypes.Type(value = VariableCreatedEventEntity.class, name = VariableCreatedEventEntity.VARIABLE_CREATED_EVENT), @JsonSubTypes.Type(value = VariableUpdatedEventEntity.class, name = VariableUpdatedEventEntity.VARIABLE_UPDATED_EVENT), @JsonSubTypes.Type(value = VariableDeletedEventEntity.class, name = VariableDeletedEventEntity.VARIABLE_DELETED_EVENT), diff --git a/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/main/java/org/activiti/cloud/services/audit/events/TaskCancelledEventEntity.java b/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/main/java/org/activiti/cloud/services/audit/events/TaskCancelledEventEntity.java new file mode 100644 index 00000000..540003fa --- /dev/null +++ b/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/main/java/org/activiti/cloud/services/audit/events/TaskCancelledEventEntity.java @@ -0,0 +1,42 @@ +/* + * Copyright 2018 Alfresco, Inc. and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.activiti.cloud.services.audit.events; + +import javax.persistence.Column; +import javax.persistence.Convert; +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.Lob; + +import org.activiti.cloud.services.audit.converter.TaskJpaJsonConverter; +import org.activiti.cloud.services.audit.events.model.Task; + +@Entity +@DiscriminatorValue(value = TaskCancelledEventEntity.TASK_CANCELLED_EVENT) +public class TaskCancelledEventEntity extends ProcessEngineEventEntity { + + protected static final String TASK_CANCELLED_EVENT = "TaskCancelledEvent"; + + @Convert(converter = TaskJpaJsonConverter.class) + @Lob + @Column + private Task task; + + public Task getTask() { + return task; + } +} diff --git a/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/test/java/org/activiti/cloud/services/audit/channel/AuditConsumerChannelHandlerTest.java b/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/test/java/org/activiti/cloud/services/audit/channel/AuditConsumerChannelHandlerTest.java index 415abd10..3c479212 100644 --- a/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/test/java/org/activiti/cloud/services/audit/channel/AuditConsumerChannelHandlerTest.java +++ b/activiti-cloud-services-audit/activiti-cloud-services-audit-jpa/src/test/java/org/activiti/cloud/services/audit/channel/AuditConsumerChannelHandlerTest.java @@ -16,14 +16,19 @@ package org.activiti.cloud.services.audit.channel; +import org.activiti.cloud.services.audit.converter.TaskJpaJsonConverter; import org.activiti.cloud.services.audit.events.IgnoredProcessEngineEvent; -import org.activiti.cloud.services.audit.repository.EventsRepository; import org.activiti.cloud.services.audit.events.ProcessEngineEventEntity; +import org.activiti.cloud.services.audit.events.TaskCancelledEventEntity; +import org.activiti.cloud.services.audit.events.model.Task; +import org.activiti.cloud.services.audit.repository.EventsRepository; +import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; +import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; import static org.mockito.MockitoAnnotations.initMocks; @@ -56,4 +61,24 @@ public void receiveShouldStoreAllReceivedEventsThatAreNotIgnored() throws Except verify(eventsRepository).save(secondEvent); verify(eventsRepository, never()).save(ignoredProcessEngineEvent); } + + @Test + public void testReceiveTaskCancelledEvent() throws Exception { + //GIVEN + + TaskCancelledEventEntity taskCancelledEventEntity = new TaskCancelledEventEntity(); + Task task = new TaskJpaJsonConverter().convertToEntityAttribute( + "{\"id\":\"1\",\"createdDate\":1523945813114,\"priority\":50,\"status\":\"CANCELLED\"}"); + FieldUtils.writeField(taskCancelledEventEntity, "task", task, true); + ProcessEngineEventEntity[] events = new ProcessEngineEventEntity[] {taskCancelledEventEntity}; + + //WHEN + handler.receive(events); + + //THEN + assertThat(taskCancelledEventEntity.isIgnored()).isFalse(); + assertThat(taskCancelledEventEntity.getTask()).isNotNull(); + assertThat(taskCancelledEventEntity.getTask().getStatus()).isEqualTo("CANCELLED"); + verify(eventsRepository).save(taskCancelledEventEntity); + } } \ No newline at end of file