4
4
5
5
package io .airbyte .server .converters ;
6
6
7
+ import io .airbyte .api .client .model .generated .ConnectionScheduleType ;
7
8
import io .airbyte .api .model .generated .ActorDefinitionResourceRequirements ;
8
9
import io .airbyte .api .model .generated .ConnectionRead ;
9
10
import io .airbyte .api .model .generated .ConnectionSchedule ;
11
+ import io .airbyte .api .model .generated .ConnectionScheduleData ;
12
+ import io .airbyte .api .model .generated .ConnectionScheduleDataBasicSchedule ;
13
+ import io .airbyte .api .model .generated .ConnectionScheduleDataCron ;
10
14
import io .airbyte .api .model .generated .ConnectionStatus ;
11
15
import io .airbyte .api .model .generated .ConnectionUpdate ;
12
16
import io .airbyte .api .model .generated .JobType ;
17
21
import io .airbyte .config .JobSyncConfig .NamespaceDefinitionType ;
18
22
import io .airbyte .config .Schedule ;
19
23
import io .airbyte .config .StandardSync ;
24
+ import io .airbyte .config .StandardSync .ScheduleType ;
20
25
import io .airbyte .server .handlers .helpers .CatalogConverter ;
26
+ import io .airbyte .server .handlers .helpers .ConnectionScheduleHelper ;
27
+ import io .airbyte .validation .json .JsonValidationException ;
21
28
import java .util .stream .Collectors ;
22
29
23
30
public class ApiPojoConverters {
@@ -78,7 +85,7 @@ public static ResourceRequirements resourceRequirementsToApi(final io.airbyte.co
78
85
.memoryLimit (resourceReqs .getMemoryLimit ());
79
86
}
80
87
81
- public static io .airbyte .config .StandardSync connectionUpdateToInternal (final ConnectionUpdate update ) {
88
+ public static io .airbyte .config .StandardSync connectionUpdateToInternal (final ConnectionUpdate update ) throws JsonValidationException {
82
89
83
90
final StandardSync newConnection = new StandardSync ()
84
91
.withNamespaceDefinition (Enums .convertTo (update .getNamespaceDefinition (), NamespaceDefinitionType .class ))
@@ -99,7 +106,9 @@ public static io.airbyte.config.StandardSync connectionUpdateToInternal(final Co
99
106
}
100
107
101
108
// update sync schedule
102
- if (update .getSchedule () != null ) {
109
+ if (update .getScheduleType () != null ) {
110
+ ConnectionScheduleHelper .populateSyncFromScheduleTypeAndData (newConnection , update .getScheduleType (), update .getScheduleData ());
111
+ } else if (update .getSchedule () != null ) {
103
112
final Schedule newSchedule = new Schedule ()
104
113
.withTimeUnit (toPersistenceTimeUnit (update .getSchedule ().getTimeUnit ()))
105
114
.withUnits (update .getSchedule ().getUnits ());
@@ -112,21 +121,12 @@ public static io.airbyte.config.StandardSync connectionUpdateToInternal(final Co
112
121
}
113
122
114
123
public static ConnectionRead internalToConnectionRead (final StandardSync standardSync ) {
115
- ConnectionSchedule apiSchedule = null ;
116
-
117
- if (!standardSync .getManual ()) {
118
- apiSchedule = new ConnectionSchedule ()
119
- .timeUnit (toApiTimeUnit (standardSync .getSchedule ().getTimeUnit ()))
120
- .units (standardSync .getSchedule ().getUnits ());
121
- }
122
-
123
124
final ConnectionRead connectionRead = new ConnectionRead ()
124
125
.connectionId (standardSync .getConnectionId ())
125
126
.sourceId (standardSync .getSourceId ())
126
127
.destinationId (standardSync .getDestinationId ())
127
128
.operationIds (standardSync .getOperationIds ())
128
129
.status (toApiStatus (standardSync .getStatus ()))
129
- .schedule (apiSchedule )
130
130
.name (standardSync .getName ())
131
131
.namespaceDefinition (Enums .convertTo (standardSync .getNamespaceDefinition (), io .airbyte .api .model .generated .NamespaceDefinitionType .class ))
132
132
.namespaceFormat (standardSync .getNamespaceFormat ())
@@ -138,6 +138,8 @@ public static ConnectionRead internalToConnectionRead(final StandardSync standar
138
138
connectionRead .resourceRequirements (resourceRequirementsToApi (standardSync .getResourceRequirements ()));
139
139
}
140
140
141
+ populateConnectionReadSchedule (standardSync , connectionRead );
142
+
141
143
return connectionRead ;
142
144
}
143
145
@@ -149,10 +151,15 @@ public static io.airbyte.config.JobTypeResourceLimit.JobType toInternalJobType(f
149
151
return Enums .convertTo (jobType , io .airbyte .config .JobTypeResourceLimit .JobType .class );
150
152
}
151
153
154
+ // TODO(https://github.com/airbytehq/airbyte/issues/11432): remove these helpers.
152
155
public static ConnectionSchedule .TimeUnitEnum toApiTimeUnit (final Schedule .TimeUnit apiTimeUnit ) {
153
156
return Enums .convertTo (apiTimeUnit , ConnectionSchedule .TimeUnitEnum .class );
154
157
}
155
158
159
+ public static ConnectionSchedule .TimeUnitEnum toApiTimeUnit (final BasicSchedule .TimeUnit timeUnit ) {
160
+ return Enums .convertTo (timeUnit , ConnectionSchedule .TimeUnitEnum .class );
161
+ }
162
+
156
163
public static ConnectionStatus toApiStatus (final StandardSync .Status status ) {
157
164
return Enums .convertTo (status , ConnectionStatus .class );
158
165
}
@@ -169,4 +176,75 @@ public static BasicSchedule.TimeUnit toBasicScheduleTimeUnit(final ConnectionSch
169
176
return Enums .convertTo (apiTimeUnit , BasicSchedule .TimeUnit .class );
170
177
}
171
178
179
+ public static BasicSchedule .TimeUnit toBasicScheduleTimeUnit (final ConnectionScheduleDataBasicSchedule .TimeUnitEnum apiTimeUnit ) {
180
+ return Enums .convertTo (apiTimeUnit , BasicSchedule .TimeUnit .class );
181
+ }
182
+
183
+ public static ConnectionScheduleDataBasicSchedule .TimeUnitEnum toApiBasicScheduleTimeUnit (final BasicSchedule .TimeUnit timeUnit ) {
184
+ return Enums .convertTo (timeUnit , ConnectionScheduleDataBasicSchedule .TimeUnitEnum .class );
185
+ }
186
+
187
+ public static ConnectionScheduleDataBasicSchedule .TimeUnitEnum toApiBasicScheduleTimeUnit (final Schedule .TimeUnit timeUnit ) {
188
+ return Enums .convertTo (timeUnit , ConnectionScheduleDataBasicSchedule .TimeUnitEnum .class );
189
+ }
190
+
191
+ public static void populateConnectionReadSchedule (final StandardSync standardSync , final ConnectionRead connectionRead ) {
192
+ // TODO(https://github.com/airbytehq/airbyte/issues/11432): only return new schema once frontend is
193
+ // ready.
194
+ if (standardSync .getScheduleType () != null ) {
195
+ // Populate everything based on the new schema.
196
+ switch (standardSync .getScheduleType ()) {
197
+ case MANUAL -> {
198
+ connectionRead .scheduleType (io .airbyte .api .model .generated .ConnectionScheduleType .MANUAL );
199
+ }
200
+ case BASIC_SCHEDULE -> {
201
+ connectionRead .scheduleType (io .airbyte .api .model .generated .ConnectionScheduleType .BASIC );
202
+ connectionRead .scheduleData (new ConnectionScheduleData ()
203
+ .basicSchedule (new ConnectionScheduleDataBasicSchedule ()
204
+ .timeUnit (toApiBasicScheduleTimeUnit (standardSync .getScheduleData ().getBasicSchedule ().getTimeUnit ()))
205
+ .units (standardSync .getScheduleData ().getBasicSchedule ().getUnits ())));
206
+ connectionRead .schedule (new ConnectionSchedule ()
207
+ .timeUnit (toApiTimeUnit (standardSync .getScheduleData ().getBasicSchedule ().getTimeUnit ()))
208
+ .units (standardSync .getScheduleData ().getBasicSchedule ().getUnits ()));
209
+ }
210
+ case CRON -> {
211
+ // We don't populate any legacy data here.
212
+ connectionRead .scheduleType (io .airbyte .api .model .generated .ConnectionScheduleType .CRON );
213
+ connectionRead .scheduleData (new ConnectionScheduleData ()
214
+ .cron (new ConnectionScheduleDataCron ()
215
+ .cronExpression (standardSync .getScheduleData ().getCron ().getCronExpression ())
216
+ .cronTimeZone (standardSync .getScheduleData ().getCron ().getCronTimeZone ())));
217
+ }
218
+ }
219
+ } else if (standardSync .getManual ()) {
220
+ // Legacy schema, manual sync.
221
+ connectionRead .scheduleType (io .airbyte .api .model .generated .ConnectionScheduleType .MANUAL );
222
+ } else {
223
+ // Legacy schema, basic schedule.
224
+ connectionRead .scheduleType (io .airbyte .api .model .generated .ConnectionScheduleType .BASIC );
225
+ connectionRead .schedule (new ConnectionSchedule ()
226
+ .timeUnit (toApiTimeUnit (standardSync .getSchedule ().getTimeUnit ()))
227
+ .units (standardSync .getSchedule ().getUnits ()));
228
+ connectionRead .scheduleData (new ConnectionScheduleData ()
229
+ .basicSchedule (new ConnectionScheduleDataBasicSchedule ()
230
+ .timeUnit (toApiBasicScheduleTimeUnit (standardSync .getSchedule ().getTimeUnit ()))
231
+ .units (standardSync .getSchedule ().getUnits ())));
232
+ }
233
+ }
234
+
235
+ public static ConnectionScheduleType toApiScheduleType (final ScheduleType scheduleType ) {
236
+ switch (scheduleType ) {
237
+ case MANUAL -> {
238
+ return ConnectionScheduleType .MANUAL ;
239
+ }
240
+ case BASIC_SCHEDULE -> {
241
+ return ConnectionScheduleType .BASIC ;
242
+ }
243
+ case CRON -> {
244
+ return ConnectionScheduleType .CRON ;
245
+ }
246
+ }
247
+ throw new RuntimeException ("Unexpected schedule type" );
248
+ }
249
+
172
250
}
0 commit comments