13
13
import com .linkedin .metadata .aspect .batch .ChangeMCP ;
14
14
import com .linkedin .metadata .aspect .batch .MCPItem ;
15
15
import com .linkedin .metadata .aspect .patch .template .common .GenericPatchTemplate ;
16
- import com .linkedin .metadata .entity .AspectUtils ;
17
16
import com .linkedin .metadata .entity .validation .ValidationApiUtils ;
18
17
import com .linkedin .metadata .models .AspectSpec ;
19
18
import com .linkedin .metadata .models .EntitySpec ;
@@ -139,38 +138,51 @@ public ChangeItemImplBuilder systemMetadata(SystemMetadata systemMetadata) {
139
138
return this ;
140
139
}
141
140
141
+ public ChangeItemImplBuilder changeType (ChangeType changeType ) {
142
+ this .changeType = validateOrDefaultChangeType (changeType );
143
+ return this ;
144
+ }
145
+
142
146
@ SneakyThrows
143
147
public ChangeItemImpl build (AspectRetriever aspectRetriever ) {
144
- // Apply change type default
145
- this .changeType = validateOrDefaultChangeType (changeType );
148
+ if (this .changeType == null ) {
149
+ changeType (null ); // Apply change type default
150
+ }
146
151
147
152
// Apply empty headers
148
153
if (this .headers == null ) {
149
154
this .headers = Map .of ();
150
155
}
151
156
152
- if (this .urn == null && this .metadataChangeProposal != null ) {
153
- this .urn = this .metadataChangeProposal .getEntityUrn ();
154
- }
155
-
156
157
ValidationApiUtils .validateUrn (aspectRetriever .getEntityRegistry (), this .urn );
157
158
log .debug ("entity type = {}" , this .urn .getEntityType ());
158
159
159
- entitySpec (aspectRetriever .getEntityRegistry ().getEntitySpec (this .urn .getEntityType ()));
160
+ entitySpec (
161
+ ValidationApiUtils .validateEntity (
162
+ aspectRetriever .getEntityRegistry (), this .urn .getEntityType ()));
160
163
log .debug ("entity spec = {}" , this .entitySpec );
161
164
162
- aspectSpec (ValidationApiUtils .validate (this .entitySpec , this .aspectName ));
165
+ aspectSpec (ValidationApiUtils .validateAspect (this .entitySpec , this .aspectName ));
163
166
log .debug ("aspect spec = {}" , this .aspectSpec );
164
167
168
+ if (this .recordTemplate == null && this .metadataChangeProposal != null ) {
169
+ this .recordTemplate = convertToRecordTemplate (this .metadataChangeProposal , aspectSpec );
170
+ }
171
+
165
172
ValidationApiUtils .validateRecordTemplate (
166
173
this .entitySpec , this .urn , this .recordTemplate , aspectRetriever );
167
174
175
+ if (this .systemMetadata == null ) {
176
+ // generate default
177
+ systemMetadata (null );
178
+ }
179
+
168
180
return new ChangeItemImpl (
169
181
this .changeType ,
170
182
this .urn ,
171
183
this .aspectName ,
172
184
this .recordTemplate ,
173
- SystemMetadataUtils . generateSystemMetadataIfEmpty ( this .systemMetadata ) ,
185
+ this .systemMetadata ,
174
186
this .auditStamp ,
175
187
this .metadataChangeProposal ,
176
188
this .entitySpec ,
@@ -183,35 +195,16 @@ public ChangeItemImpl build(AspectRetriever aspectRetriever) {
183
195
public ChangeItemImpl build (
184
196
MetadataChangeProposal mcp , AuditStamp auditStamp , AspectRetriever aspectRetriever ) {
185
197
186
- log .debug ("entity type = {}" , mcp .getEntityType ());
187
- EntitySpec entitySpec =
188
- aspectRetriever .getEntityRegistry ().getEntitySpec (mcp .getEntityType ());
189
- AspectSpec aspectSpec = AspectUtils .validateAspect (mcp , entitySpec );
190
-
191
- if (!MCPItem .isValidChangeType (ChangeType .UPSERT , aspectSpec )) {
192
- throw new UnsupportedOperationException (
193
- "ChangeType not supported: "
194
- + mcp .getChangeType ()
195
- + " for aspect "
196
- + mcp .getAspectName ());
197
- }
198
-
199
- Urn urn = mcp .getEntityUrn ();
200
- if (urn == null ) {
201
- urn = EntityKeyUtils .getUrnFromProposal (mcp , entitySpec .getKeyAspectSpec ());
202
- }
203
-
204
- return ChangeItemImpl .builder ()
205
- .changeType (mcp .getChangeType ())
206
- .urn (urn )
207
- .aspectName (mcp .getAspectName ())
208
- .systemMetadata (
209
- SystemMetadataUtils .generateSystemMetadataIfEmpty (mcp .getSystemMetadata ()))
210
- .metadataChangeProposal (mcp )
211
- .auditStamp (auditStamp )
212
- .recordTemplate (convertToRecordTemplate (mcp , aspectSpec ))
213
- .nextAspectVersion (this .nextAspectVersion )
214
- .build (aspectRetriever );
198
+ // Validation includes: Urn, Entity, Aspect
199
+ this .metadataChangeProposal =
200
+ ValidationApiUtils .validateMCP (aspectRetriever .getEntityRegistry (), mcp );
201
+ this .urn = this .metadataChangeProposal .getEntityUrn (); // validation ensures existence
202
+ this .auditStamp = auditStamp ;
203
+ this .aspectName = mcp .getAspectName (); // prior validation
204
+ changeType (mcp .getChangeType ());
205
+ this .systemMetadata = mcp .getSystemMetadata ();
206
+ this .headers = mcp .getHeaders ();
207
+ return build (aspectRetriever );
215
208
}
216
209
217
210
// specific to impl, other impls support PATCH, etc
@@ -226,6 +219,11 @@ private static ChangeType validateOrDefaultChangeType(@Nullable ChangeType chang
226
219
227
220
private static RecordTemplate convertToRecordTemplate (
228
221
MetadataChangeProposal mcp , AspectSpec aspectSpec ) {
222
+
223
+ if (mcp .getAspect () == null ) {
224
+ return null ;
225
+ }
226
+
229
227
RecordTemplate aspect ;
230
228
try {
231
229
aspect =
0 commit comments