提交 7c8fcb95 编写于 作者: M Miguel Ruiz 提交者: mergify[bot]

Activiti 3760 definition upgrade logic (#2893)

* ACTIVITI-3760 Change logic for deployment versioning

* ACTIVITI-3760 Mybatis xml descriptor to support versioning

* ACTIVITI-3760 Mybatis descriptor clean up

* ACTIVITI-3760 logic to set procdef version as deployment/application version

* ACTIVITI-3760 Logic to calculate versioning for procdefs

* ACTIVITI-3760 Mybatis config to support app versioning of procdefs

* ACTIVITI-3760 Add sql commands for postgres

* ACTIVITI-3760 Add manifest to test resources

* ACTIVITI-3760 Add new project release version property to deployment

* ACTIVITI-3760 Add new column to table in postgres

* ACTIVITI-3760 Core logic for project release and application version bump up

* ACTIVITI-3760 Add spring configuration

* ACTIVITI-3760 Add properties to tests

* ACTIVITI-3760 Reset version in manifest

* ACTIVITI-3760 Refactor method

* ACTIVITI-3760 Add logger to DefaultAutoDeploymentStrategy class

* ACTIVITI-3760 Clean up

* ACTIVITI-3760 Ensure baackwards compatibility

* ACTIVITI-3760 Add method to Deployment interface

* ACTIVITI-3760 Add IT coverage

* Refactor deployment strategies

* ACTIVITI-3760 Refactor of DB and entities

* ACTIVITI-3760 Rely on default property

* Use SpringBoot test instead of SpringApplicationBuilder

* Clean up

* Update how to set deployment version

Avoid extra query retrieve latest deployment that was already loaded before
上级 fea1edbf
......@@ -18,6 +18,10 @@
<groupId>org.activiti.api</groupId>
<artifactId>activiti-api-runtime-shared</artifactId>
</dependency>
<dependency>
<groupId>org.activiti.core.common</groupId>
<artifactId>activiti-project-model</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-converter</artifactId>
......@@ -180,4 +184,4 @@
</plugins>
</build>
</project>
\ No newline at end of file
</project>
......@@ -168,22 +168,38 @@ public class BpmnDeployer implements Deployer {
Map<ProcessDefinitionEntity, ProcessDefinitionEntity> mapNewToOldProcessDefinitions) {
CommandContext commandContext = Context.getCommandContext();
for (ProcessDefinitionEntity processDefinition : parsedDeployment.getAllProcessDefinitions()) {
int version = 1;
ProcessDefinitionEntity latest = mapNewToOldProcessDefinitions.get(processDefinition);
if (latest != null) {
version = latest.getVersion() + 1;
if(parsedDeployment.getDeployment().getProjectReleaseVersion() != null){
Integer version = parsedDeployment.getDeployment().getVersion();
for (ProcessDefinitionEntity processDefinition : parsedDeployment.getAllProcessDefinitions()) {
processDefinition.setVersion(version);
processDefinition.setId(getIdForNewProcessDefinition(processDefinition));
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED,
processDefinition));
}
}
}else{
processDefinition.setVersion(version);
processDefinition.setId(getIdForNewProcessDefinition(processDefinition));
for (ProcessDefinitionEntity processDefinition : parsedDeployment.getAllProcessDefinitions()) {
int version = 1;
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED,
processDefinition));
ProcessDefinitionEntity latest = mapNewToOldProcessDefinitions.get(processDefinition);
if (latest != null) {
version = latest.getVersion() + 1;
}
processDefinition.setVersion(version);
processDefinition.setId(getIdForNewProcessDefinition(processDefinition));
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.ENTITY_CREATED,
processDefinition));
}
}
}
}
/**
......
......@@ -52,7 +52,10 @@ public class DeployCmd<T> implements Command<Deployment>, Serializable {
deployment.setDeploymentTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
if (deploymentBuilder.isDuplicateFilterEnabled()) {
setProjectReleaseVersion(deployment);
deployment.setVersion(1);
if (deploymentBuilder.isDuplicateFilterEnabled()) {
List<Deployment> existingDeployments = new ArrayList<Deployment>();
if (deployment.getTenantId() == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(deployment.getTenantId())) {
......@@ -74,14 +77,19 @@ public class DeployCmd<T> implements Command<Deployment>, Serializable {
existingDeployment = (DeploymentEntity) existingDeployments.get(0);
}
if ((existingDeployment != null) && !deploymentsDiffer(deployment, existingDeployment)) {
return existingDeployment;
}
if (existingDeployment != null) {
if (!deploymentsDiffer(deployment,
existingDeployment)) {
return existingDeployment;
} else {
deployment.setVersion(existingDeployment.getVersion() + 1);
}
}
}
deployment.setNew(true);
// Save the data
// Save the data
commandContext.getDeploymentEntityManager().insert(deployment);
if (commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
......@@ -107,32 +115,47 @@ public class DeployCmd<T> implements Command<Deployment>, Serializable {
return deployment;
}
protected boolean deploymentsDiffer(DeploymentEntity deployment, DeploymentEntity saved) {
if (deployment.getResources() == null || saved.getResources() == null) {
return true;
private void setProjectReleaseVersion(DeploymentEntity deployment) {
if (deploymentBuilder.hasProjectManifestSet()) {
deployment.setProjectReleaseVersion(deploymentBuilder.getProjectManifest().getVersion());
}
}
Map<String, ResourceEntity> resources = deployment.getResources();
Map<String, ResourceEntity> savedResources = saved.getResources();
protected boolean deploymentsDiffer(DeploymentEntity deployment,
DeploymentEntity saved) {
if (deploymentBuilder.hasProjectManifestSet()) {
for (String resourceName : resources.keySet()) {
ResourceEntity savedResource = savedResources.get(resourceName);
return !deployment.getProjectReleaseVersion().equals(saved.getProjectReleaseVersion());
} else {
if (savedResource == null)
return true;
if (deployment.getResources() == null || saved.getResources() == null) {
return true;
}
if (!savedResource.isGenerated()) {
ResourceEntity resource = resources.get(resourceName);
Map<String, ResourceEntity> resources = deployment.getResources();
Map<String, ResourceEntity> savedResources = saved.getResources();
byte[] bytes = resource.getBytes();
byte[] savedBytes = savedResource.getBytes();
if (!Arrays.equals(bytes, savedBytes)) {
return true;
for (String resourceName : resources.keySet()) {
ResourceEntity savedResource = savedResources.get(resourceName);
if (savedResource == null) {
return true;
}
if (!savedResource.isGenerated()) {
ResourceEntity resource = resources.get(resourceName);
byte[] bytes = resource.getBytes();
byte[] savedBytes = savedResource.getBytes();
if (!Arrays.equals(bytes,
savedBytes)) {
return true;
}
}
}
return false;
}
}
}
return false;
}
protected void scheduleProcessDefinitionActivation(CommandContext commandContext, DeploymentEntity deployment) {
......
......@@ -55,4 +55,12 @@ public interface DeploymentEntity extends Deployment, Entity {
void setEngineVersion(String engineVersion);
}
\ No newline at end of file
Integer getVersion();
void setVersion(Integer version);
String getProjectReleaseVersion();
void setProjectReleaseVersion(String projectReleaseVersion);
}
......@@ -38,8 +38,10 @@ public class DeploymentEntityImpl extends AbstractEntityNoRevision implements De
protected Map<String, ResourceEntity> resources;
protected Date deploymentTime;
protected boolean isNew;
protected Integer version;
private String projectReleaseVersion;
// Backwards compatibility
// Backwards compatibility
protected String engineVersion;
/**
......@@ -168,6 +170,22 @@ public class DeploymentEntityImpl extends AbstractEntityNoRevision implements De
this.engineVersion = engineVersion;
}
public Integer getVersion(){
return version;
}
public void setVersion(Integer version){
this.version = version;
}
public String getProjectReleaseVersion() {
return projectReleaseVersion;
}
public void setProjectReleaseVersion(String projectReleaseVersion) {
this.projectReleaseVersion = projectReleaseVersion;
}
// common methods //////////////////////////////////////////////////////////
@Override
......@@ -175,4 +193,4 @@ public class DeploymentEntityImpl extends AbstractEntityNoRevision implements De
return "DeploymentEntity[id=" + id + ", name=" + name + "]";
}
}
\ No newline at end of file
}
......@@ -48,7 +48,7 @@ public class ProcessDefinitionEntityImpl extends AbstractEntity implements Proce
protected List<IdentityLinkEntity> definitionIdentityLinkEntities = new ArrayList<IdentityLinkEntity>();
protected IOSpecification ioSpecification;
// Backwards compatibility
// Backwards compatibility
protected String engineVersion;
public Object getPersistentState() {
......
......@@ -24,6 +24,7 @@ import java.util.zip.ZipInputStream;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.core.common.project.model.ProjectManifest;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.impl.RepositoryServiceImpl;
......@@ -55,6 +56,7 @@ public class DeploymentBuilderImpl implements DeploymentBuilder, Serializable {
protected boolean isDuplicateFilterEnabled;
protected Date processDefinitionsActivationDate;
protected Map<String, Object> deploymentProperties = new HashMap<>();
private ProjectManifest projectManifest;
public DeploymentBuilderImpl(RepositoryServiceImpl repositoryService) {
this(repositoryService,
......@@ -82,6 +84,19 @@ public class DeploymentBuilderImpl implements DeploymentBuilder, Serializable {
return this;
}
public DeploymentBuilder setProjectManifest(ProjectManifest projectManifest) {
this.projectManifest = projectManifest;
return this;
}
public ProjectManifest getProjectManifest(){
return this.projectManifest;
}
public boolean hasProjectManifestSet(){
return this.projectManifest != null;
}
@Override
public DeploymentBuilder addInputStream(String resourceName,
Resource resource) {
......
......@@ -44,4 +44,8 @@ public interface Deployment {
String getTenantId();
Integer getVersion();
String getProjectReleaseVersion();
}
......@@ -17,6 +17,7 @@ import java.util.Date;
import java.util.zip.ZipInputStream;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.core.common.project.model.ProjectManifest;
import org.activiti.engine.api.internal.Internal;
import org.springframework.core.io.Resource;
......@@ -48,6 +49,8 @@ public interface DeploymentBuilder {
DeploymentBuilder addBpmnModel(String resourceName, BpmnModel bpmnModel);
DeploymentBuilder setProjectManifest(ProjectManifest projectManifest);
/**
* If called, no XML schema validation against the BPMN 2.0 XSD.
*
......
......@@ -32,6 +32,8 @@ create table ACT_RE_DEPLOYMENT (
TENANT_ID_ varchar(255) default '',
DEPLOY_TIME_ timestamp,
ENGINE_VERSION_ varchar(255),
VERSION_ integer,
PROJECT_RELEASE_VERSION_ varchar(255),
primary key (ID_)
);
......
......@@ -32,6 +32,8 @@ create table ACT_RE_DEPLOYMENT (
TENANT_ID_ varchar(255) default '',
DEPLOY_TIME_ timestamp,
ENGINE_VERSION_ varchar(255),
VERSION_ integer,
PROJECT_RELEASE_VERSION_ varchar(255),
primary key (ID_)
);
......
......@@ -7,8 +7,8 @@
<!-- DEPLOYMENT INSERT -->
<insert id="insertDeployment" parameterType="org.activiti.engine.impl.persistence.entity.DeploymentEntityImpl">
insert into ${prefix}ACT_RE_DEPLOYMENT(ID_, NAME_, CATEGORY_, KEY_, TENANT_ID_, DEPLOY_TIME_, ENGINE_VERSION_)
values(#{id, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{category, jdbcType=VARCHAR}, #{key, jdbcType=VARCHAR}, #{tenantId, jdbcType=VARCHAR}, #{deploymentTime, jdbcType=TIMESTAMP}, #{engineVersion, jdbcType=VARCHAR})
insert into ${prefix}ACT_RE_DEPLOYMENT(ID_, NAME_, CATEGORY_, KEY_, TENANT_ID_, DEPLOY_TIME_, ENGINE_VERSION_, VERSION_, PROJECT_RELEASE_VERSION_)
values(#{id, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{category, jdbcType=VARCHAR}, #{key, jdbcType=VARCHAR}, #{tenantId, jdbcType=VARCHAR}, #{deploymentTime, jdbcType=TIMESTAMP}, #{engineVersion, jdbcType=VARCHAR}, #{version, jdbcType=INTEGER}, #{projectReleaseVersion, jdbcType=VARCHAR})
</insert>
<insert id="bulkInsertDeployment" parameterType="java.util.List">
......@@ -20,7 +20,9 @@
#{deployment.category, jdbcType=VARCHAR},
#{deployment.key, jdbcType=VARCHAR},
#{deployment.tenantId, jdbcType=VARCHAR},
#{deployment.deploymentTime, jdbcType=TIMESTAMP})
#{deployment.deploymentTime, jdbcType=TIMESTAMP}),
#{version, jdbcType=INTEGER},
#{projectReleaseVersion, jdbcType=VARCHAR}
</foreach>
</insert>
......@@ -33,7 +35,9 @@
#{deployment.category, jdbcType=VARCHAR},
#{deployment.key, jdbcType=VARCHAR},
#{deployment.tenantId, jdbcType=VARCHAR},
#{deployment.deploymentTime, jdbcType=TIMESTAMP})
#{deployment.deploymentTime, jdbcType=TIMESTAMP}),
#{version, jdbcType=INTEGER},
#{projectReleaseVersion, jdbcType=VARCHAR}
</foreach>
SELECT * FROM dual
</insert>
......@@ -44,7 +48,8 @@
update ${prefix}ACT_RE_DEPLOYMENT set
CATEGORY_ = #{category, jdbcType=VARCHAR},
KEY_ = #{key, jdbcType=VARCHAR},
TENANT_ID_ = #{tenantId, jdbcType=VARCHAR}
TENANT_ID_ = #{tenantId, jdbcType=VARCHAR},
VERSION_ = #{version, jdbcType=INTEGER}
where ID_ = #{id, jdbcType=VARCHAR}
</update>
......@@ -64,6 +69,8 @@
<result property="tenantId" column="TENANT_ID_" jdbcType="VARCHAR" />
<result property="deploymentTime" column="DEPLOY_TIME_" jdbcType="TIMESTAMP"/>
<result property="engineVersion" column="ENGINE_VERSION_" jdbcType="VARCHAR" />
<result property="version" column="VERSION_" jdbcType="INTEGER" />
<result property="projectReleaseVersion" column="PROJECT_RELEASE_VERSION_" jdbcType="VARCHAR" />
</resultMap>
<!-- DEPLOYMENT SELECT -->
......@@ -176,4 +183,4 @@
${sql}
</select>
</mapper>
\ No newline at end of file
</mapper>
......@@ -327,4 +327,4 @@
<select id="selectProcessDefinitionCountByNativeQuery" parameterType="java.util.Map" resultType="long">
${sql}
</select>
</mapper>
\ No newline at end of file
</mapper>
......@@ -23,6 +23,7 @@ import javax.sql.DataSource;
import org.activiti.api.process.model.events.ProcessDeployedEvent;
import org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener;
import org.activiti.api.runtime.shared.identity.UserGroupManager;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.cfg.ProcessEngineConfigurator;
import org.activiti.engine.impl.event.EventSubscriptionPayloadMappingProvider;
......@@ -70,10 +71,11 @@ public class ProcessEngineAutoConfiguration extends AbstractProcessEngineAutoCon
SpringAsyncExecutor springAsyncExecutor,
ActivitiProperties activitiProperties,
ProcessDefinitionResourceFinder processDefinitionResourceFinder,
ProjectModelService projectModelService,
@Autowired(required = false) List<ProcessEngineConfigurationConfigurer> processEngineConfigurationConfigurers,
@Autowired(required = false) List<ProcessEngineConfigurator> processEngineConfigurators) throws IOException {
SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration();
SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration(projectModelService);
conf.setConfigurators(processEngineConfigurators);
configureProcessDefinitionResources(processDefinitionResourceFinder,
conf);
......
package org.activiti.spring.boot;
import org.activiti.core.common.project.model.ProjectManifest;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class ApplicationUpgradeIT {
@Autowired
private RepositoryService repositoryService;
@Test
public void should_UpdateDeploymentVersion_When_ManifestIsPresent() {
ProjectManifest projectManifest = new ProjectManifest();
projectManifest.setVersion("7");
Deployment deployment1 = repositoryService.createDeployment()
.setProjectManifest(projectManifest)
.enableDuplicateFiltering()
.name("deploymentName")
.deploy();
assertThat(deployment1.getVersion()).isEqualTo(1);
assertThat(deployment1.getProjectReleaseVersion()).isEqualTo("7");
projectManifest.setVersion("17");
Deployment deployment2 = repositoryService.createDeployment()
.setProjectManifest(projectManifest)
.enableDuplicateFiltering()
.name("deploymentName")
.deploy();
assertThat(deployment2.getProjectReleaseVersion()).isEqualTo("17");
assertThat(deployment2.getVersion()).isEqualTo(2);
}
}
......@@ -16,6 +16,7 @@
package org.activiti.spring.boot;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.process.validation.AsyncPropertyValidator;
import org.activiti.validation.ProcessValidator;
......@@ -24,8 +25,9 @@ import org.assertj.core.api.Condition;
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.assertj.core.api.Assertions.assertThat;
import static org.mockito.MockitoAnnotations.initMocks;
public class ProcessEngineAutoConfigurationTest {
......@@ -33,6 +35,9 @@ public class ProcessEngineAutoConfigurationTest {
@InjectMocks
private ProcessEngineAutoConfiguration processEngineAutoConfiguration;
@Mock
private ProjectModelService projectModelServiceMock;
@Before
public void setUp() {
initMocks(this);
......@@ -43,7 +48,7 @@ public class ProcessEngineAutoConfigurationTest {
//given
ActivitiProperties activitiProperties = new ActivitiProperties();
activitiProperties.setAsyncExecutorActivate(false);
SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration();
SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration(projectModelServiceMock);
//when
processEngineAutoConfiguration.addAsyncPropertyValidator(activitiProperties,
......@@ -65,7 +70,7 @@ public class ProcessEngineAutoConfigurationTest {
//given
ActivitiProperties activitiProperties = new ActivitiProperties();
activitiProperties.setAsyncExecutorActivate(true);
SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration();
SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration(projectModelServiceMock);
//when
processEngineAutoConfiguration.addAsyncPropertyValidator(activitiProperties,
......@@ -76,4 +81,4 @@ public class ProcessEngineAutoConfigurationTest {
assertThat(processValidator).isNull();
}
}
\ No newline at end of file
}
spring.application.name=my-app
\ No newline at end of file
spring.application.name=my-app
{
"createdBy": "superadminuser",
"creationDate": "2019-08-16T15:58:46.056+0000",
"lastModifiedBy": "qa-modeler-1",
"lastModifiedDate": "2019-08-16T16:03:41.941+0000",
"id": "c519a458-539f-4385-a937-2edfb4045eb9",
"name": "projectA",
"description": "",
"version": "1"
}
......@@ -31,6 +31,10 @@
<groupId>org.activiti.api</groupId>
<artifactId>activiti-api-runtime-shared</artifactId>
</dependency>
<dependency>
<groupId>org.activiti.core.common</groupId>
<artifactId>activiti-spring-project</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
......
......@@ -13,6 +13,7 @@
package org.activiti.spring;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
......@@ -39,6 +40,8 @@ import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
......@@ -54,15 +57,21 @@ public class SpringProcessEngineConfiguration extends ProcessEngineConfiguration
protected String deploymentMode = "default";
protected ApplicationContext applicationContext;
protected Integer transactionSynchronizationAdapterOrder = null;
private Collection<AutoDeploymentStrategy> deploymentStrategies = new ArrayList<AutoDeploymentStrategy>();
private Collection<AutoDeploymentStrategy> deploymentStrategies = new ArrayList<>();
private DefaultAutoDeploymentStrategy defaultAutoDeploymentStrategy;
public SpringProcessEngineConfiguration() {
this.transactionsExternallyManaged = true;
deploymentStrategies.add(new DefaultAutoDeploymentStrategy());
deploymentStrategies.add(new SingleResourceAutoDeploymentStrategy());
deploymentStrategies.add(new ResourceParentFolderAutoDeploymentStrategy());
deploymentStrategies.add(new FailOnNoProcessAutoDeploymentStrategy());
deploymentStrategies.add(new NeverFailAutoDeploymentStrategy());
public SpringProcessEngineConfiguration() {
this(null);
}
public SpringProcessEngineConfiguration(ProjectModelService projectModelService) {
this.transactionsExternallyManaged = true;
defaultAutoDeploymentStrategy = new DefaultAutoDeploymentStrategy(projectModelService);
deploymentStrategies.add(defaultAutoDeploymentStrategy);
deploymentStrategies.add(new SingleResourceAutoDeploymentStrategy(projectModelService));
deploymentStrategies.add(new ResourceParentFolderAutoDeploymentStrategy(projectModelService));
deploymentStrategies.add(new FailOnNoProcessAutoDeploymentStrategy(projectModelService));
deploymentStrategies.add(new NeverFailAutoDeploymentStrategy(projectModelService));
}
@Override
......@@ -181,14 +190,14 @@ public class SpringProcessEngineConfiguration extends ProcessEngineConfiguration
* @return the deployment strategy to use for the mode. Never <code>null</code>
*/
protected AutoDeploymentStrategy getAutoDeploymentStrategy(final String mode) {
AutoDeploymentStrategy result = new DefaultAutoDeploymentStrategy();
for (final AutoDeploymentStrategy strategy : deploymentStrategies) {
if (strategy.handlesMode(mode)) {
result = strategy;
break;
AutoDeploymentStrategy result = defaultAutoDeploymentStrategy;
for (final AutoDeploymentStrategy strategy : deploymentStrategies) {
if (strategy.handlesMode(mode)) {
result = strategy;
break;
}
}
}
return result;
return result;
}
}
......@@ -18,8 +18,10 @@ import java.util.List;
import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.impl.util.io.InputStreamSource;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.validation.ValidationError;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -37,6 +39,12 @@ public abstract class AbstractAutoDeploymentStrategy implements AutoDeploymentSt
protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractAutoDeploymentStrategy.class);
private ProjectModelService projectModelService;
public AbstractAutoDeploymentStrategy(ProjectModelService projectModelService) {
this.projectModelService = projectModelService;
}
/**
* Gets the deployment mode this strategy handles.
*
......@@ -111,4 +119,15 @@ public abstract class AbstractAutoDeploymentStrategy implements AutoDeploymentSt
}
return true;
}
protected DeploymentBuilder loadProjectManifest(DeploymentBuilder deploymentBuilder) {
if (projectModelService != null && projectModelService.hasProjectManifest()) {
try {
deploymentBuilder.setProjectManifest(projectModelService.loadProjectManifest());
} catch (IOException e) {
LOGGER.warn("Manifest of application not found. Project release version will not be set for deployment.");
}
}
return deploymentBuilder;
}
}
/* 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.
......@@ -13,43 +13,48 @@
package org.activiti.spring.autodeployment;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.DeploymentBuilder;
import org.springframework.core.io.Resource;
/**
* Default implementation of {@link AutoDeploymentStrategy} that groups all {@link Resource}s into a single deployment. This implementation is equivalent to the previously used implementation.
*
*/
public class DefaultAutoDeploymentStrategy extends AbstractAutoDeploymentStrategy {
/**
* The deployment mode this strategy handles.
*/
public static final String DEPLOYMENT_MODE = "default";
/**
* The deployment mode this strategy handles.
*/
public static final String DEPLOYMENT_MODE = "default";
public DefaultAutoDeploymentStrategy(ProjectModelService projectModelService) {
super(projectModelService);
}
@Override
protected String getDeploymentMode() {
return DEPLOYMENT_MODE;
}
@Override
protected String getDeploymentMode() {
return DEPLOYMENT_MODE;
}
@Override
public void deployResources(final String deploymentNameHint, final Resource[] resources, final RepositoryService repositoryService) {
@Override
public void deployResources(final String deploymentNameHint,
final Resource[] resources,
final RepositoryService repositoryService) {
// Create a single deployment for all resources using the name hint as
// the
// literal name
final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentNameHint);
// Create a single deployment for all resources using the name hint as
// the
// literal name
for (final Resource resource : resources) {
final String resourceName = determineResourceName(resource);
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentNameHint);
deploymentBuilder.addInputStream(resourceName,
resource);
}
for (final Resource resource : resources) {
final String resourceName = determineResourceName(resource);
deploymentBuilder.deploy();
deploymentBuilder.addInputStream(resourceName,
resource);
}
}
loadProjectManifest(deploymentBuilder).deploy();
}
}
package org.activiti.spring.autodeployment;
import java.io.IOException;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.ActivitiException;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.DeploymentBuilder;
......@@ -13,6 +16,10 @@ public class FailOnNoProcessAutoDeploymentStrategy extends AbstractAutoDeploymen
public static final String DEPLOYMENT_MODE = "fail-on-no-process";
public FailOnNoProcessAutoDeploymentStrategy(ProjectModelService projectModelService) {
super(projectModelService);
}
@Override
protected String getDeploymentMode() {
return DEPLOYMENT_MODE;
......@@ -20,7 +27,7 @@ public class FailOnNoProcessAutoDeploymentStrategy extends AbstractAutoDeploymen
@Override
public void deployResources(String deploymentNameHint, Resource[] resources, RepositoryService repositoryService) {
final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering()
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering()
.name(deploymentNameHint);
int validProcessCount = 0;
......@@ -36,6 +43,8 @@ public class FailOnNoProcessAutoDeploymentStrategy extends AbstractAutoDeploymen
}
}
deploymentBuilder = loadProjectManifest(deploymentBuilder);
if (validProcessCount != 0) {
deploymentBuilder.deploy();
} else {
......
package org.activiti.spring.autodeployment;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.DeploymentBuilder;
import org.slf4j.Logger;
......@@ -12,6 +13,10 @@ public class NeverFailAutoDeploymentStrategy extends AbstractAutoDeploymentStrat
public static final String DEPLOYMENT_MODE = "never-fail";
public NeverFailAutoDeploymentStrategy(ProjectModelService projectModelService) {
super(projectModelService);
}
@Override
protected String getDeploymentMode() {
return DEPLOYMENT_MODE;
......@@ -19,7 +24,7 @@ public class NeverFailAutoDeploymentStrategy extends AbstractAutoDeploymentStrat
@Override
public void deployResources(String deploymentNameHint, Resource[] resources, RepositoryService repositoryService) {
final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering()
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering()
.name(deploymentNameHint);
int validProcessCount = 0;
......@@ -35,6 +40,8 @@ public class NeverFailAutoDeploymentStrategy extends AbstractAutoDeploymentStrat
}
}
deploymentBuilder = loadProjectManifest(deploymentBuilder);
if (validProcessCount != 0) {
deploymentBuilder.deploy();
}
......
......@@ -20,8 +20,11 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.DeploymentBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
/**
......@@ -39,6 +42,10 @@ public class ResourceParentFolderAutoDeploymentStrategy extends AbstractAutoDepl
private static final String DEPLOYMENT_NAME_PATTERN = "%s.%s";
public ResourceParentFolderAutoDeploymentStrategy(ProjectModelService projectModelService) {
super(projectModelService);
}
@Override
protected String getDeploymentMode() {
return DEPLOYMENT_MODE;
......@@ -56,7 +63,7 @@ public class ResourceParentFolderAutoDeploymentStrategy extends AbstractAutoDepl
final String deploymentName = determineDeploymentName(deploymentNameHint, group.getKey());
final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentName);
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentName);
for (final Resource resource : group.getValue()) {
final String resourceName = determineResourceName(resource);
......@@ -64,7 +71,8 @@ public class ResourceParentFolderAutoDeploymentStrategy extends AbstractAutoDepl
deploymentBuilder.addInputStream(resourceName,
resource);
}
deploymentBuilder.deploy();
loadProjectManifest(deploymentBuilder).deploy();
}
}
......
......@@ -13,6 +13,8 @@
package org.activiti.spring.autodeployment;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.DeploymentBuilder;
import org.springframework.core.io.Resource;
......@@ -29,7 +31,11 @@ public class SingleResourceAutoDeploymentStrategy extends AbstractAutoDeployment
*/
public static final String DEPLOYMENT_MODE = "single-resource";
@Override
public SingleResourceAutoDeploymentStrategy(ProjectModelService projectModelService) {
super(projectModelService);
}
@Override
protected String getDeploymentMode() {
return DEPLOYMENT_MODE;
}
......@@ -48,7 +54,8 @@ public class SingleResourceAutoDeploymentStrategy extends AbstractAutoDeployment
deploymentBuilder.addInputStream(resourceName,
resource);
deploymentBuilder.deploy();
loadProjectManifest(deploymentBuilder).deploy();
}
}
......
......@@ -16,9 +16,11 @@ package org.activiti.spring.test.autodeployment;
import java.io.File;
import java.io.InputStream;
import org.activiti.core.common.spring.project.ProjectModelService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.junit.Before;
import org.mockito.Mock;
import org.springframework.core.io.ByteArrayResource;
......@@ -73,6 +75,9 @@ public class AbstractAutoDeploymentStrategyTest {
@Mock
private Deployment deploymentMock;
@Mock
protected ProjectModelService projectModelServiceMock;
protected final String deploymentNameHint = "nameHint";
protected final String resourceName1 = "resourceName1.bpmn";
......@@ -111,4 +116,4 @@ public class AbstractAutoDeploymentStrategyTest {
when(deploymentBuilderMock.deploy()).thenReturn(deploymentMock);
}
}
\ No newline at end of file
}
......@@ -38,7 +38,7 @@ public class DefaultAutoDeploymentStrategyTest extends AbstractAutoDeploymentStr
@Before
public void before() throws Exception {
super.before();
deploymentStrategy = new DefaultAutoDeploymentStrategy();
deploymentStrategy = new DefaultAutoDeploymentStrategy(projectModelServiceMock);
}
@Test
......@@ -106,4 +106,4 @@ public class DefaultAutoDeploymentStrategyTest extends AbstractAutoDeploymentStr
resources,
repositoryServiceMock);
}
}
\ No newline at end of file
}
......@@ -39,7 +39,7 @@ public class FailOnNoProcessAutoDeploymentStrategyTest extends SpringActivitiTes
@Test
public void testValidResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(validName1)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
}
......@@ -47,7 +47,7 @@ public class FailOnNoProcessAutoDeploymentStrategyTest extends SpringActivitiTes
@Test
public void testInvalidResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName1), new ClassPathResource(invalidName2)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
}
......@@ -55,7 +55,7 @@ public class FailOnNoProcessAutoDeploymentStrategyTest extends SpringActivitiTes
@Test
public void testWithParsingErrorResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName1)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
}
......@@ -63,7 +63,7 @@ public class FailOnNoProcessAutoDeploymentStrategyTest extends SpringActivitiTes
@Test
public void testWithValidationErrorResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName2)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
}
......@@ -71,7 +71,7 @@ public class FailOnNoProcessAutoDeploymentStrategyTest extends SpringActivitiTes
@Test
public void testOnlyInvalidResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(invalidName1)};
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy();
FailOnNoProcessAutoDeploymentStrategy deploymentStrategy = new FailOnNoProcessAutoDeploymentStrategy(null);
try {
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
} catch (ActivitiException e) {
......@@ -81,4 +81,4 @@ public class FailOnNoProcessAutoDeploymentStrategyTest extends SpringActivitiTes
}
fail();
}
}
\ No newline at end of file
}
......@@ -38,7 +38,7 @@ public class NeverFailAutoDeploymentStrategyTest extends SpringActivitiTestCase
@Test
public void testValidResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(validName1)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
}
......@@ -46,7 +46,7 @@ public class NeverFailAutoDeploymentStrategyTest extends SpringActivitiTestCase
@Test
public void testInvalidResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName1), new ClassPathResource(invalidName2)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
}
......@@ -54,7 +54,7 @@ public class NeverFailAutoDeploymentStrategyTest extends SpringActivitiTestCase
@Test
public void testWithParsingErrorResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName1)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
}
......@@ -62,7 +62,7 @@ public class NeverFailAutoDeploymentStrategyTest extends SpringActivitiTestCase
@Test
public void testWithValidationErrorResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(validName1), new ClassPathResource(invalidName2)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(1, repositoryService.createDeploymentQuery().count());
}
......@@ -70,8 +70,8 @@ public class NeverFailAutoDeploymentStrategyTest extends SpringActivitiTestCase
@Test
public void testOnlyInvalidResources() {
final Resource[] resources = new Resource[]{new ClassPathResource(invalidName1)};
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy();
NeverFailAutoDeploymentStrategy deploymentStrategy = new NeverFailAutoDeploymentStrategy(null);
deploymentStrategy.deployResources(nameHint, resources, repositoryService);
assertEquals(0, repositoryService.createDeploymentQuery().count());
}
}
\ No newline at end of file
}
......@@ -51,7 +51,7 @@ public class ResourceParentFolderAutoDeploymentStrategyTest extends AbstractAuto
@Before
public void before() throws Exception {
super.before();
deploymentStrategy = new ResourceParentFolderAutoDeploymentStrategy();
deploymentStrategy = new ResourceParentFolderAutoDeploymentStrategy(projectModelServiceMock);
assertNotNull(deploymentStrategy);
when(parentFile1Mock.getName()).thenReturn(parentFilename1);
......@@ -197,4 +197,4 @@ public class ResourceParentFolderAutoDeploymentStrategyTest extends AbstractAuto
verify(deploymentBuilderMock).deploy();
}
}
\ No newline at end of file
}
......@@ -37,7 +37,7 @@ public class SingleResourceAutoDeploymentStrategyTest extends AbstractAutoDeploy
@Before
public void before() throws Exception {
super.before();
deploymentStrategy = new SingleResourceAutoDeploymentStrategy();
deploymentStrategy = new SingleResourceAutoDeploymentStrategy(projectModelServiceMock);
assertNotNull(deploymentStrategy);
}
......@@ -110,4 +110,4 @@ public class SingleResourceAutoDeploymentStrategyTest extends AbstractAutoDeploy
never()).deploy();
}
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册