flowable 迁移流程数据

flowable 迁移流程数据:

可以从旧版本流程,迁移到新版本(ps:如果版本差异过大,可能会迁移不成功)

flowable 6.4 主要代码(runtimeService):

	@Autowired
	private RuntimeService runtimeService;

	public JSONObject procInstMigration(String fromProcessDefId, String toProcessDefId) {
		if (StringUtils.isBlank(fromProcessDefId)) {
			// 验证不通过
			return JSONObject.parseObject(String.format(JSON_MSG, "false", "原流程定义id为空!"));
		}
		if (StringUtils.isBlank(toProcessDefId)) {
			// 验证不通过
			return JSONObject.parseObject(String.format(JSON_MSG, "false", "目标流程定义id为空!"));
		}

		// 迁移验证
		boolean migrationValid = runtimeService.createProcessInstanceMigrationBuilder()
				.migrateToProcessDefinition(toProcessDefId)
				.validateMigrationOfProcessInstances(fromProcessDefId)
				.isMigrationValid();
		if (!migrationValid) {
			// 验证不通过
			return JSONObject.parseObject(String.format(JSON_MSG, "false", "流程定义差异过大,不满足在途流程的迁移,请修改流程图!"));
		}

		// 验证通过执行迁移
		runtimeService.createProcessInstanceMigrationBuilder()
				.migrateToProcessDefinition(toProcessDefId)
				.migrateProcessInstances(fromProcessDefId);

		//业务操作
        //TODO

		return JSONObject.parseObject(String.format(JSON_MSG, "true", "迁移成功!"));
	}

flowable 6.5 主要代码(processMigrationService):

	@Autowired
	private ProcessMigrationService processMigrationService;

	public JSONObject procInstMigration(String fromProcessDefId, String toProcessDefId) {
		if (StringUtils.isBlank(fromProcessDefId)) {
			// 验证不通过
			return JSONObject.parseObject(String.format(JSON_MSG, "false", "原流程定义id为空!"));
		}
		if (StringUtils.isBlank(toProcessDefId)) {
			// 验证不通过
			return JSONObject.parseObject(String.format(JSON_MSG, "false", "目标流程定义id为空!"));
		}

		// 迁移验证
		boolean migrationValid = processMigrationService.createProcessInstanceMigrationBuilder()
				.migrateToProcessDefinition(toProcessDefId)
				.validateMigrationOfProcessInstances(fromProcessDefId)
				.isMigrationValid();
		if (!migrationValid) {
			// 验证不通过
			return JSONObject.parseObject(String.format(JSON_MSG, "false", "流程定义差异过大,不满足在途流程的迁移,请修改流程图!"));
		}

		// 验证通过执行迁移
		processMigrationService.createProcessInstanceMigrationBuilder()
				.migrateToProcessDefinition(toProcessDefId)
				.migrateProcessInstances(fromProcessDefId);

		//业务操作
        //TODO

		return JSONObject.parseObject(String.format(JSON_MSG, "true", "迁移成功!"));
	}

测试验证:

	@Test
	public void migration() {
		//迁移
		String oldProcDefId = "test:316:6adbcc25-1bc9-11ee-a93a-00ff237a5526";
		String newProcDefId = "test:319:52385710-220c-11ee-8997-005056b2814b";
		JSONObject jsonObject = procInstMigration(oldProcDefId, newProcDefId);
		System.err.println(jsonObject);
	}

你可能感兴趣的:(flowable,java,插件学习,java,flowbale)