Skip to content

Commit

Permalink
feature: update workflow demo
Browse files Browse the repository at this point in the history
  • Loading branch information
kalencaya committed Oct 1, 2024
1 parent 8eb1011 commit 0bffb92
Show file tree
Hide file tree
Showing 33 changed files with 720 additions and 208 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 cn.sliew.carp.module.workflow.api.controller;

import cn.sliew.carp.framework.web.response.ApiResponseWrapper;
import cn.sliew.carp.module.workflow.api.engine.domain.definition.WorkflowDefinition;
import cn.sliew.carp.module.workflow.api.service.WorkflowDefinitionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@ApiResponseWrapper
@RequestMapping("/api/carp/workflow/definition")
@Tag(name = "Workflow模块-Definition管理")
public class WorkflowDefinitionController {

@Autowired
private WorkflowDefinitionService workflowDefinitionService;

@GetMapping("{id}")
@Operation(summary = "查询详情", description = "查询详情")
public WorkflowDefinition get(@PathVariable("id") Long id) {
return workflowDefinitionService.get(id);
}

@GetMapping("{id}/graph")
@Operation(summary = "查询详情-图", description = "查询详情-图")
public WorkflowDefinition getGraph(@PathVariable("id") Long id) {
return workflowDefinitionService.getGraph(id);
}

@PutMapping
@Operation(summary = "新增", description = "新增")
public Long add() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 cn.sliew.carp.module.workflow.api.controller;

import cn.sliew.carp.framework.common.security.annotations.AnonymousAccess;
import cn.sliew.carp.framework.web.response.ApiResponseWrapper;
import cn.sliew.carp.module.workflow.api.service.WorkflowInstanceService;
import cn.sliew.carp.module.workflow.api.service.param.WorkflowRunParam;
import cn.sliew.carp.module.workflow.api.service.param.WorkflowStopParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@AnonymousAccess
@RestController
@ApiResponseWrapper
@RequestMapping("/api/carp/workflow/instance")
@Tag(name = "Workflow模块-Instance管理")
public class WorkflowInstanceController {

@Autowired
private WorkflowInstanceService workflowInstanceService;

@PostMapping("run")
@Operation(summary = "启动", description = "启动")
public Long run(@Valid @RequestBody WorkflowRunParam param) {
return workflowInstanceService.run(param);
}

@PostMapping("stop")
@Operation(summary = "停止", description = "停止")
public void stop(@Valid @RequestBody WorkflowStopParam param) {
workflowInstanceService.stop(param);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
* limitations under the License.
*/

package cn.sliew.carp.module.workflow.api.graph;
package cn.sliew.carp.module.workflow.api.engine.dispatch;

import cn.sliew.carp.framework.dag.algorithm.DAG;
import lombok.Data;
import cn.sliew.carp.module.workflow.api.engine.dispatch.event.WorkflowInstanceStatusEvent;

@Data
public class WorkflowDefinitionGraph {
public interface WorkflowInstanceEventDispatcher {

private Long dagConfigId;

private DAG<WorkflowTaskDefinition> dag;
void dispatch(WorkflowInstanceStatusEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* limitations under the License.
*/

package cn.sliew.carp.module.workflow.api.graph;
package cn.sliew.carp.module.workflow.api.engine.dispatch;

import lombok.Data;
import cn.sliew.carp.module.workflow.api.engine.dispatch.event.WorkflowTaskInstanceStatusEvent;

@Data
public class WorkflowDefinitionAttrs {
public interface WorkflowTaskInstanceEventDispatcher {

void dispatch(WorkflowTaskInstanceStatusEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
* limitations under the License.
*/

package cn.sliew.carp.module.workflow.api.graph;
package cn.sliew.carp.module.workflow.api.engine.dispatch.event;

import cn.sliew.carp.framework.dag.algorithm.DAG;
import lombok.Data;
import cn.sliew.carp.framework.common.dict.workflow.WorkflowInstanceEvent;

@Data
public class WorkflowExecutionGraph {
public interface WorkflowInstanceStatusEvent {

private DAG<WorkflowTaskInstance> dag;
WorkflowInstanceEvent getEvent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* limitations under the License.
*/

package cn.sliew.carp.module.workflow.api.graph;
package cn.sliew.carp.module.workflow.api.engine.dispatch.event;

import lombok.Data;
import cn.sliew.carp.framework.common.dict.workflow.WorkflowTaskInstanceEvent;

@Data
public class WorkflowDefinitionMeta {
public interface WorkflowTaskInstanceStatusEvent {

WorkflowTaskInstanceEvent getEvent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,14 @@
* limitations under the License.
*/

package cn.sliew.carp.module.workflow.api.graph;
package cn.sliew.carp.module.workflow.api.engine.dispatch.handler;

import cn.sliew.carp.framework.common.model.BaseDTO;
import lombok.Data;
import cn.sliew.carp.framework.common.dict.workflow.WorkflowInstanceEvent;
import cn.sliew.carp.module.workflow.api.engine.dispatch.event.WorkflowInstanceStatusEvent;

@Data
public class WorkflowTaskDefinition extends BaseDTO {
public interface WorkflowInstanceEventHandler {

private Long dagId;
WorkflowInstanceEvent getType();

private String stepId;

private String name;

private WorkflowTaskDefinitionMeta meta;

private WorkflowTaskDefinitionAttrs attrs;
void handle(WorkflowInstanceStatusEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 cn.sliew.carp.module.workflow.api.engine.dispatch.handler;

import cn.sliew.carp.framework.common.dict.workflow.WorkflowTaskInstanceEvent;
import cn.sliew.carp.module.workflow.api.engine.dispatch.event.WorkflowTaskInstanceStatusEvent;

public interface WorkflowTaskInstanceEventHandler {

WorkflowTaskInstanceEvent getType();

void handle(WorkflowTaskInstanceStatusEvent event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
* limitations under the License.
*/

package cn.sliew.carp.module.workflow.api.domain;
package cn.sliew.carp.module.workflow.api.engine.dispatch.publisher;

import lombok.Data;
import cn.sliew.carp.module.workflow.api.engine.dispatch.event.WorkflowInstanceStatusEvent;

@Data
public class WorkflowDagEdge {
public interface WorkflowInstanceEventPublisher {

private Long sourceId;
private Long targetId;
private String expression;
void publish(WorkflowInstanceStatusEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 cn.sliew.carp.module.workflow.api.engine.dispatch.publisher;

import cn.sliew.carp.module.workflow.api.engine.dispatch.event.WorkflowTaskInstanceStatusEvent;

public interface WorkflowTaskInstanceEventPublisher {

void publish(WorkflowTaskInstanceStatusEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 cn.sliew.carp.module.workflow.api.engine.domain.definition;

import cn.sliew.carp.framework.common.model.BaseDTO;
import lombok.Data;

import java.util.List;

@Data
public class WorkflowDefinition extends BaseDTO {

private String type;

private String name;

private String uuid;

private WorkflowDefinitionGraph graph;

private WorkflowDefinitionMeta meta;

private WorkflowDefinitionAttrs attrs;

private List<WorkflowParamOption> inputOptions;

private List<WorkflowParamOption> outputOptions;

private String remark;
}
Loading

0 comments on commit 0bffb92

Please sign in to comment.