提交 17340008 编写于 作者: T Tijs Rademakers

Cherry pick of deployment category update and process definition key query

上级 30f17e68
......@@ -65,6 +65,14 @@ public interface RepositoryService {
* @param deploymentId id of the deployment, cannot be null.
*/
void deleteDeployment(String deploymentId, boolean cascade);
/**
* Sets the category of the deployment.
* Deployments can be queried by category: see {@link DeploymentQuery#deploymentCategory(String)}.
*
* @throws ActivitiObjectNotFoundException if no deployment with the provided id can be found.
*/
void setDeploymentCategory(String deploymentId, String category);
/**
* Retrieves a list of deployment resources for the given deployment,
......
......@@ -13,6 +13,10 @@
package org.activiti.engine.impl;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.impl.cmd.ActivateProcessDefinitionCmd;
......@@ -36,6 +40,7 @@ import org.activiti.engine.impl.cmd.GetModelCmd;
import org.activiti.engine.impl.cmd.GetModelEditorSourceCmd;
import org.activiti.engine.impl.cmd.GetModelEditorSourceExtraCmd;
import org.activiti.engine.impl.cmd.SaveModelCmd;
import org.activiti.engine.impl.cmd.SetDeploymentCategoryCmd;
import org.activiti.engine.impl.cmd.SetProcessDefinitionCategoryCmd;
import org.activiti.engine.impl.cmd.SuspendProcessDefinitionCmd;
import org.activiti.engine.impl.persistence.entity.ModelEntity;
......@@ -54,10 +59,6 @@ import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.task.IdentityLink;
import java.io.InputStream;
import java.util.Date;
import java.util.List;
/**
* @author Tom Baeyens
......@@ -85,6 +86,10 @@ public class RepositoryServiceImpl extends ServiceImpl implements RepositoryServ
public void deleteDeployment(String deploymentId, boolean cascade) {
commandExecutor.execute(new DeleteDeploymentCmd(deploymentId, cascade));
}
public void setDeploymentCategory(String deploymentId, String category) {
commandExecutor.execute(new SetDeploymentCategoryCmd(deploymentId, category));
}
public ProcessDefinitionQuery createProcessDefinitionQuery() {
return new ProcessDefinitionQueryImpl(commandExecutor);
......
/* 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.engine.impl.cmd;
import org.activiti.engine.ActivitiIllegalArgumentException;
import org.activiti.engine.ActivitiObjectNotFoundException;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.DeploymentEntity;
import org.activiti.engine.repository.Deployment;
/**
* @author Tijs Rademakers
*/
public class SetDeploymentCategoryCmd implements Command<Void> {
protected String deploymentId;
protected String category;
public SetDeploymentCategoryCmd(String deploymentId, String category) {
this.deploymentId = deploymentId;
this.category = category;
}
public Void execute(CommandContext commandContext) {
if (deploymentId == null) {
throw new ActivitiIllegalArgumentException("Deployment id is null");
}
DeploymentEntity deployment = Context
.getCommandContext()
.getDeploymentEntityManager()
.findDeploymentById(deploymentId);
if (deployment == null) {
throw new ActivitiObjectNotFoundException("No deployment found for id = '" + deploymentId + "'", Deployment.class);
}
// Update category
deployment.setCategory(category);
return null;
}
public String getDeploymentId() {
return deploymentId;
}
public void setDeploymentId(String deploymentId) {
this.deploymentId = deploymentId;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
}
......@@ -45,15 +45,6 @@ public class DeploymentEntity implements Serializable, Deployment, PersistentObj
*/
protected Map<Class<?>, List<Object>> deployedArtifacts;
public Object getPersistentState() {
// properties of this entity are immutable
// so always the same value is returned
// so never will an update be issued for a DeploymentEntity
return DeploymentEntity.class;
}
// lazy loading /////////////////////////////////////////////////////////////
public ResourceEntity getResource(String resourceName) {
return getResources().get(resourceName);
}
......@@ -65,6 +56,7 @@ public class DeploymentEntity implements Serializable, Deployment, PersistentObj
resources.put(resource.getName(), resource);
}
// lazy loading /////////////////////////////////////////////////////////////
public Map<String, ResourceEntity> getResources() {
if (resources==null && id!=null) {
List<ResourceEntity> resourcesList = Context
......@@ -79,8 +71,13 @@ public class DeploymentEntity implements Serializable, Deployment, PersistentObj
return resources;
}
// deployed artifacts manipulation //////////////////////////////////////////
public Object getPersistentState() {
Map<String, Object> persistentState = new HashMap<String, Object>();
persistentState.put("category", this.category);
return persistentState;
}
// Deployed artifacts manipulation //////////////////////////////////////////
public void addDeployedArtifact(Object deployedArtifact) {
if (deployedArtifacts == null) {
deployedArtifacts = new HashMap<Class<?>, List<Object>>();
......
......@@ -13,6 +13,12 @@
<!-- DEPLOYMENT UPDATE -->
<update id="updateDeployment" parameterType="org.activiti.engine.impl.persistence.entity.DeploymentEntity">
update ${prefix}ACT_RE_DEPLOYMENT set
CATEGORY_ = #{category, jdbcType=VARCHAR}
where ID_ = #{id, jdbcType=VARCHAR}
</update>
<!-- DEPLOYMENT DELETE -->
<delete id="deleteDeployment" parameterType="string">
......
......@@ -32,6 +32,7 @@ public class DeploymentCategoryTest extends PluggableActivitiTestCase {
String deploymentOneId = null;
String deploymentTwoV1Id = null;
String deploymentTwoV2Id = null;
String deploymentTwoNoCategory = null;
try {
noCategoryDeploymentId = repositoryService
......@@ -86,12 +87,27 @@ public class DeploymentCategoryTest extends PluggableActivitiTestCase {
expectedDeploymentNames.add("0");
assertEquals(expectedDeploymentNames, deploymentNames);
deploymentTwoNoCategory = repositoryService
.createDeployment()
.name("noCategory")
.addClasspathResource("org/activiti/engine/test/repository/two.bpmn20.xml")
.deploy()
.getId();
Deployment deploymentNoCategory = repositoryService.createDeploymentQuery().deploymentId(deploymentTwoNoCategory).singleResult();
assertNull(deploymentNoCategory.getCategory());
repositoryService.setDeploymentCategory(deploymentTwoNoCategory, "newCategory");
deploymentNoCategory = repositoryService.createDeploymentQuery().deploymentId(deploymentTwoNoCategory).singleResult();
assertEquals("newCategory", deploymentNoCategory.getCategory());
} finally {
if (noCategoryDeploymentId!=null) undeploy(noCategoryDeploymentId);
if (deploymentOneId!=null) undeploy(deploymentOneId);
if (deploymentTwoV1Id!=null) undeploy(deploymentTwoV1Id);
if (deploymentTwoV2Id!=null) undeploy(deploymentTwoV2Id);
if (deploymentTwoNoCategory!=null) undeploy(deploymentTwoNoCategory);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册