Skip to content

Commit 8fc060d

Browse files
committed
create flow with group id
1 parent 8886796 commit 8fc060d

File tree

7 files changed

+27
-12
lines changed

7 files changed

+27
-12
lines changed

core/src/main/java/com/flowci/core/common/config/MongoConfig.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ public MongoMappingContext mongoMappingContext(MongoCustomConversions customConv
102102
context.setAutoIndexCreation(true);
103103

104104
// add addPersistentEntity for subtypes since not registered if called within same thread
105-
context.addEntity(Flow.class);
106-
context.addEntity(FlowGroup.class);
107-
108105
context.addEntity(SmtpConfig.class);
109106
context.addEntity(TextConfig.class);
110107

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ public Boolean exist(@PathVariable String name) {
7575

7676
@PostMapping(value = "/{name}")
7777
@Action(FlowAction.CREATE)
78-
public Flow create(@PathVariable String name) {
78+
public Flow create(@PathVariable String name,
79+
@RequestParam(required = false) String groupId) {
80+
if (groupId != null) {
81+
return flowService.create(name, groupId);
82+
}
7983
return flowService.create(name);
8084
}
8185

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.fasterxml.jackson.annotation.JsonIgnore;
2020
import com.flowci.core.common.domain.Variables;
2121
import com.flowci.domain.StringVars;
22-
import com.flowci.domain.TypedVars;
2322
import com.flowci.domain.VarValue;
2423
import com.flowci.domain.Vars;
2524
import com.flowci.exception.ArgumentException;
@@ -61,6 +60,8 @@ public enum Status {
6160
CONFIRMED
6261
}
6362

63+
private String groupId;
64+
6465
private Status status = Status.PENDING;
6566

6667
private boolean isYamlFromRepo;

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
import lombok.Setter;
66
import org.springframework.data.mongodb.core.mapping.Document;
77

8-
import java.util.LinkedList;
9-
import java.util.List;
10-
118
@Setter
129
@Getter
13-
@Document(collection = "flow")
10+
@Document(collection = "flow_group")
1411
public class FlowGroup extends FlowItem {
1512

16-
private List<String> flows = new LinkedList<>();
1713
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public interface FlowService {
4949
*/
5050
Flow create(String name);
5151

52+
Flow create(String name, String groupId);
53+
5254
/**
5355
* Confirm flow
5456
*

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.flowci.core.common.manager.SessionManager;
2323
import com.flowci.core.common.manager.SpringEventManager;
2424
import com.flowci.core.flow.dao.FlowDao;
25+
import com.flowci.core.flow.dao.FlowGroupDao;
2526
import com.flowci.core.flow.dao.FlowUserDao;
2627
import com.flowci.core.flow.domain.*;
2728
import com.flowci.core.flow.domain.Flow.Status;
@@ -67,6 +68,9 @@ public class FlowServiceImpl implements FlowService {
6768
@Autowired
6869
private FlowDao flowDao;
6970

71+
@Autowired
72+
private FlowGroupDao flowGroupDao;
73+
7074
@Autowired
7175
private FlowUserDao flowUserDao;
7276

@@ -132,7 +136,6 @@ public List<Flow> listByCredential(String secretName) {
132136
if (Objects.equals(flow.getCredentialName(), secret.getName())) {
133137
continue;
134138
}
135-
136139
iter.remove();
137140
}
138141

@@ -150,19 +153,31 @@ public Boolean exist(String name) {
150153

151154
@Override
152155
public Flow create(String name) {
156+
return create(name, null);
157+
}
158+
159+
@Override
160+
public Flow create(String name, String groupId) {
153161
Flow.validateName(name);
154162
String email = sessionManager.getUserEmail();
155163

156164
if (exist(name)) {
157165
throw new DuplicateException("Flow {0} already exists", name);
158166
}
159167

168+
if (groupId != null) {
169+
if (!flowGroupDao.existsById(groupId)) {
170+
throw new NotFoundException("The group id {0} not found", groupId);
171+
}
172+
}
173+
160174
// reuse from pending list
161175
List<Flow> pending = flowDao.findAllByStatusAndCreatedBy(Status.PENDING, email);
162176
var flow = pending.size() > 0 ? pending.get(0) : new Flow();
163177

164178
// set properties
165179
flow.setName(name);
180+
flow.setGroupId(groupId);
166181
setupDefaultVars(flow);
167182

168183
try {

core/src/test/java/com/flowci/core/test/api/OpenRestServiceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void should_list_all_flow_users() {
7979
@Test
8080
public void should_save_job_report() {
8181
// given:
82-
Flow flow = flowService.create("user-test");
82+
Flow flow = flowService.create("user-test", null);
8383

8484
Job job = new Job();
8585
job.setId("12345");

0 commit comments

Comments
 (0)