Skip to content

Commit

Permalink
[AAE-785] Add application version field to processes and tasks in Act…
Browse files Browse the repository at this point in the history
…iviti Core (Activiti#3001)

* AAE-785: Added appVersion, refactor, tests

* AAE-785: Fixed schema version number

* AAE-785: Increased value column size

* AAE-785: Addressed CRs
  • Loading branch information
miguelruizdev authored and mergify[bot] committed Dec 2, 2019
1 parent d51a9c6 commit 93d4b93
Show file tree
Hide file tree
Showing 45 changed files with 1,646 additions and 1,387 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.activiti.runtime.api.model.impl;

import java.util.Objects;

import org.activiti.api.process.model.ProcessDefinition;
import org.activiti.api.runtime.model.impl.ProcessDefinitionImpl;
import org.activiti.bpmn.model.BpmnModel;
Expand All @@ -37,6 +39,7 @@ public ProcessDefinition from(org.activiti.engine.repository.ProcessDefinition i
processDefinition.setDescription(internalProcessDefinition.getDescription());
processDefinition.setVersion(internalProcessDefinition.getVersion());
processDefinition.setKey(internalProcessDefinition.getKey());
processDefinition.setAppVersion(Objects.toString(internalProcessDefinition.getAppVersion(), null));
BpmnModel model = repositoryService.getBpmnModel(internalProcessDefinition.getId());
processDefinition.setFormKey(model.getStartFormKey(internalProcessDefinition.getKey()));
return processDefinition;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright 2018 Alfresco, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,6 +16,8 @@

package org.activiti.runtime.api.model.impl;

import java.util.Objects;

import org.activiti.api.process.model.ProcessInstance;
import org.activiti.api.runtime.model.impl.ProcessInstanceImpl;

Expand All @@ -37,6 +39,7 @@ public ProcessInstance from(org.activiti.engine.runtime.ProcessInstance internal
processInstance.setBusinessKey(internalProcessInstance.getBusinessKey());
processInstance.setStatus(calculateStatus(internalProcessInstance));
processInstance.setProcessDefinitionVersion(internalProcessInstance.getProcessDefinitionVersion());
processInstance.setAppVersion(Objects.toString(internalProcessInstance.getAppVersion(), null));
return processInstance;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

import static org.activiti.runtime.api.model.impl.MockProcessDefinitionBuilder.processDefinitionBuilderBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.MockitoAnnotations.initMocks;

public class APIProcessDefinitionConverterTest {
Expand All @@ -53,36 +54,52 @@ public void setUp() {
BpmnModel model = new BpmnModel();
model.addProcess(process);

when(repositoryService.getBpmnModel("anId")).thenReturn(model);
given(repositoryService.getBpmnModel(any())).willReturn(model);
}

@Test
public void convertFromProcessDefinitionShouldSetAllFieldsInTheConvertedProcessDefinition() {
public void should_convertFromProcessDefinition_when_allFieldsAreSet() {
ProcessDefinition convertedProcessDefinition = processDefinitionConverter.from(
processDefinitionBuilderBuilder()
.withId("anId")
.withKey("processKey")
.withName("Process Name")
.withDescription("process description")
.withVersion(3)
.withAppVersion(1)
.build()
);

//THEN
assertThat(convertedProcessDefinition)
.isNotNull()
.extracting(ProcessDefinition::getId,
ProcessDefinition::getKey,
ProcessDefinition::getName,
ProcessDefinition::getDescription,
ProcessDefinition::getVersion,
ProcessDefinition::getAppVersion,
ProcessDefinition::getFormKey)
.containsExactly(
"anId",
"processKey",
"Process Name",
"process description",
3,
"1",
"AFormKey");
}

@Test
public void should_convertProcessDefinition_when_appVersionNull() {
ProcessDefinition convertedProcessDefinition = processDefinitionConverter.from(
processDefinitionBuilderBuilder()
.withKey("processKey")
.withAppVersion(null)
.build());

assertThat(convertedProcessDefinition)
.isNotNull()
.extracting(ProcessDefinition::getAppVersion)
.isNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,56 +38,60 @@ public class APIProcessInstanceConverterTest {
private static final String PROCESS_DEFINITION_KEY = "processDefinitionKey";
private static final String PROCESS_DEFINITION_ID = "processDefinitionId";
private static final String PROCESS_INSTANCE_ID = "processInstanceId";
public static final int APP_VERSION = 1;
private static final String APP_VERSION_STRING = "1";
private static final Date START_TIME = new Date();

private APIProcessInstanceConverter subject = new APIProcessInstanceConverter();
private Date startTime = new Date();

@Test
public void shouldConvertFromInternalProcessInstanceWithRunningStatus() {
//given
ExecutionEntity internalProcessInstance = anInternalProcessInstance(startTime);
public void should_convertFromInternalProcessInstance_when_withRunningStatus() {
ExecutionEntity internalProcessInstance = anInternalProcessInstance(APP_VERSION);

internalProcessInstance.setActive(true);

//when
ProcessInstance result = subject.from(internalProcessInstance);

//then
assertValidProcessInstanceResult(result);
assertThat(result.getStatus()).isEqualTo(ProcessInstanceStatus.RUNNING);
}

@Test
public void shouldConvertFromInternalProcessInstanceWithSuspendedStatus() {
//given
ExecutionEntity internalProcessInstance = anInternalProcessInstance(startTime);
public void should_convertFromInternalProcessInstance_when_withSuspendedStatus() {
ExecutionEntity internalProcessInstance = anInternalProcessInstance(APP_VERSION);

internalProcessInstance.setSuspensionState(SuspensionState.SUSPENDED.getStateCode());

//when
ProcessInstance result = subject.from(internalProcessInstance);

//then
assertValidProcessInstanceResult(result);
assertThat(result.getStatus()).isEqualTo(ProcessInstanceStatus.SUSPENDED);
}

@Test
public void shouldConvertFromInternalProcessInstanceWithCompletedStatus() {
//given
ExecutionEntity internalProcessInstance = anInternalProcessInstance(startTime);
public void should_convertFromInternalProcessInstance_when_withCompletedStatus() {
ExecutionEntity internalProcessInstance = anInternalProcessInstance(APP_VERSION);

internalProcessInstance.setEnded(true);

//when
ProcessInstance result = subject.from(internalProcessInstance);

//then
assertValidProcessInstanceResult(result);
assertThat(result.getStatus()).isEqualTo(ProcessInstanceStatus.COMPLETED);
}

private void assertValidProcessInstanceResult(ProcessInstance result) {
@Test
public void should_convertFromInternalProcessInstance_when_appVersionIsNotSet() {
ExecutionEntity internalProcessInstance = anInternalProcessInstance(null);

ProcessInstance result = subject.from(internalProcessInstance);

assertValidProcessInstanceResult(result, null);
}

private static void assertValidProcessInstanceResult(ProcessInstance result) {
assertValidProcessInstanceResult(result, APP_VERSION_STRING);
}

private static void assertValidProcessInstanceResult(ProcessInstance result, String appVersionString) {
assertThat(result).isNotNull();
assertThat(result.getId()).isEqualTo(PROCESS_INSTANCE_ID);
assertThat(result.getBusinessKey()).isEqualTo(BUSINESS_KEY);
Expand All @@ -98,10 +102,11 @@ private void assertValidProcessInstanceResult(ProcessInstance result) {
assertThat(result.getName()).isEqualTo(NAME);
assertThat(result.getParentId()).isEqualTo(PARENT_PROCESS_INSTANCE_ID);
assertThat(result.getInitiator()).isEqualTo(START_USER_ID);
assertThat(result.getStartDate()).isEqualTo(startTime);
assertThat(result.getStartDate()).isEqualTo(START_TIME);
assertThat(result.getAppVersion()).isEqualTo(appVersionString);
}

private ExecutionEntity anInternalProcessInstance(Date startTime) {
private ExecutionEntity anInternalProcessInstance(Integer appVersion) {
ExecutionEntity internalProcessInstance = new ExecutionEntityImpl();

internalProcessInstance.setId(PROCESS_INSTANCE_ID);
Expand All @@ -113,8 +118,9 @@ private ExecutionEntity anInternalProcessInstance(Date startTime) {
internalProcessInstance.setName(NAME);
internalProcessInstance.setDescription(DESCRIPTION);
internalProcessInstance.setStartUserId(START_USER_ID);
internalProcessInstance.setStartTime(startTime);
internalProcessInstance.setStartTime(START_TIME);
internalProcessInstance.setActive(true);
internalProcessInstance.setAppVersion(appVersion);

return internalProcessInstance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public MockProcessDefinitionBuilder withVersion(int version) {
return this;
}

public MockProcessDefinitionBuilder withAppVersion(Integer appVersion) {
when(processDefinition.getAppVersion()).thenReturn(appVersion);
return this;
}

public ProcessDefinition build() {
return processDefinition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.activiti.runtime.api.model.impl;

import java.util.Objects;

import org.activiti.api.task.model.Task;
import org.activiti.api.task.model.impl.TaskImpl;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
Expand Down Expand Up @@ -45,6 +47,7 @@ public Task from(org.activiti.engine.task.Task internalTask,
task.setPriority(internalTask.getPriority());
task.setFormKey(internalTask.getFormKey());
task.setTaskDefinitionKey(internalTask.getTaskDefinitionKey());
task.setAppVersion(Objects.toString(internalTask.getAppVersion(), null));
return task;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public void setUp() {
}

@Test
public void convertFromTaskShouldSetAllFieldsInTheConvertedTask() {
//WHEN
public void should_convertTask_when_allFieldsAreSet() {
Date now = new Date();
Task convertedTask = taskConverter.from(
taskBuilder()
Expand All @@ -61,10 +60,10 @@ public void convertFromTaskShouldSetAllFieldsInTheConvertedTask() {
.withParentTaskId("testParentTaskId")
.withFormKey("testFormKey")
.withTaskDefinitionKey("taskDefinitionKey")
.withAppVersion(1)
.build()
);

//THEN
assertThat(convertedTask)
.isNotNull()
.extracting(Task::getId,
Expand All @@ -80,7 +79,8 @@ public void convertFromTaskShouldSetAllFieldsInTheConvertedTask() {
Task::getParentTaskId,
Task::getFormKey,
Task::getStatus,
Task::getTaskDefinitionKey)
Task::getTaskDefinitionKey,
Task::getAppVersion)
.containsExactly("testTaskId",
"testUser",
"testTaskName",
Expand All @@ -94,7 +94,17 @@ public void convertFromTaskShouldSetAllFieldsInTheConvertedTask() {
"testParentTaskId",
"testFormKey",
ASSIGNED,
"taskDefinitionKey");
"taskDefinitionKey",
"1");
}

@Test
public void should_convertTask_when_appVersionNull() {
Task convertedTask = taskConverter.from(taskBuilder().withAppVersion(null).build());
assertThat(convertedTask)
.isNotNull()
.extracting(Task::getAppVersion)
.isNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public MockTaskBuilder withTaskDefinitionKey(String taskDefinitionKey) {
return this;
}

public MockTaskBuilder withAppVersion(Integer appVersion) {
when(task.getAppVersion()).thenReturn(appVersion);
return this;
}

public Task build() {
return task;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* 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.
Expand All @@ -17,7 +17,7 @@

/**
* Provides access to all the services that expose the BPM and workflow operations.
*
*
* <ul>
* <li>
* <b>{@link org.activiti.engine.RuntimeService}: </b> Allows the creation of {@link org.activiti.engine.repository.Deployment}s and the starting of and searching on
Expand All @@ -29,25 +29,25 @@
* <li>
* <b>{@link org.activiti.engine.HistoryService}: </b> Service exposing information about ongoing and past process instances.</li>
* </ul>
*
*
* Typically, there will be only one central ProcessEngine instance needed in a end-user application. Building a ProcessEngine is done through a {@link ProcessEngineConfiguration} instance and is a
* costly operation which should be avoided. For that purpose, it is advised to store it in a static field or JNDI location (or something similar). This is a thread-safe object, so no special
* precautions need to be taken.
*
*
*/
@Internal
public interface ProcessEngine {

/** the version of the activiti library */
public static String VERSION = "7.1.0.0"; // Note the extra .x at the end. To cater for snapshot releases with different database changes
public static String VERSION = "7.1.0-M6"; // Note the extra -x at the end. To cater for snapshot releases with different database changes

/**
* The name as specified in 'process-engine-name' in the activiti.cfg.xml configuration file. The default name for a process engine is 'default
*/
String getName();

void close();

RepositoryService getRepositoryService();

RuntimeService getRuntimeService();
Expand All @@ -57,7 +57,7 @@ public interface ProcessEngine {
HistoryService getHistoryService();

ManagementService getManagementService();

DynamicBpmnService getDynamicBpmnService();

ProcessEngineConfiguration getProcessEngineConfiguration();
Expand Down
Loading

0 comments on commit 93d4b93

Please sign in to comment.