Skip to content

Commit 1389962

Browse files
committed
enable to load flow group
1 parent 38b9eb5 commit 1389962

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

core/src/main/java/com/flowci/core/flow/controller/FlowController.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ public class FlowController {
4343

4444
private final FlowService flowService;
4545

46+
private final FlowGroupService flowGroupService;
47+
4648
private final FlowItemService flowItemService;
4749

4850
public FlowController(List<Template> templates,
4951
UserService userService,
5052
FlowService flowService,
53+
FlowGroupService flowGroupService,
5154
FlowItemService flowItemService) {
5255
this.templates = templates;
5356
this.userService = userService;
5457
this.flowService = flowService;
58+
this.flowGroupService = flowGroupService;
5559
this.flowItemService = flowItemService;
5660
}
5761

@@ -69,8 +73,12 @@ public List<Template> getTemplates() {
6973

7074
@GetMapping(value = "/{name}")
7175
@Action(FlowAction.GET)
72-
public Flow get(@PathVariable String name) {
73-
return flowService.get(name);
76+
public Flow get(@PathVariable String name, @RequestParam boolean group) {
77+
var flow = flowService.get(name);
78+
if (group && flow.hasParentId()) {
79+
flow.setParent(flowGroupService.getById(flow.getParentId()));
80+
}
81+
return flow;
7482
}
7583

7684
@GetMapping(value = "/{name}/exist")

core/src/main/java/com/flowci/core/flow/domain/Flow.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.flowci.core.flow.domain;
1818

1919
import com.fasterxml.jackson.annotation.JsonIgnore;
20+
import com.fasterxml.jackson.annotation.JsonInclude;
2021
import com.flowci.core.common.domain.Variables;
2122
import com.flowci.domain.StringVars;
2223
import com.flowci.domain.VarValue;
@@ -29,6 +30,7 @@
2930
import lombok.EqualsAndHashCode;
3031
import lombok.Getter;
3132
import lombok.Setter;
33+
import org.springframework.data.annotation.Transient;
3234
import org.springframework.data.mongodb.core.mapping.Document;
3335

3436
import java.util.Objects;
@@ -84,6 +86,10 @@ public static void validateName(String name) {
8486

8587
private WebhookStatus webhookStatus;
8688

89+
@JsonInclude()
90+
@Transient
91+
private FlowGroup parent;
92+
8793
public Flow() {
8894
this.type = Type.Flow;
8995
}

core/src/main/java/com/flowci/core/flow/domain/FlowItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public enum Type {
4040
protected String parentId = ROOT_ID;
4141

4242
public boolean hasParentId() {
43-
return StringHelper.hasValue(parentId);
43+
return StringHelper.hasValue(parentId) && !parentId.equals(ROOT_ID);
4444
}
4545

4646
public boolean hasRootParent() {

core/src/main/java/com/flowci/core/flow/service/FlowGroupService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public interface FlowGroupService {
99

1010
FlowGroup get(String name);
1111

12+
FlowGroup getById(String id);
13+
1214
List<Flow> flows(String id);
1315

1416
FlowGroup create(String name);

core/src/main/java/com/flowci/core/flow/service/FlowGroupServiceImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ public FlowGroup get(String name) {
4949
return optional.get();
5050
}
5151

52+
@Override
53+
public FlowGroup getById(String id) {
54+
Optional<FlowGroup> optional = flowGroupDao.findById(id);
55+
if (optional.isEmpty()) {
56+
throw new NotFoundException("Group {0} not found", id);
57+
}
58+
return optional.get();
59+
}
60+
5261
@Override
5362
public FlowGroup create(String name) {
5463
var email = sessionManager.getUserEmail();

0 commit comments

Comments
 (0)