16
16
import com .linkedin .metadata .search .SearchService ;
17
17
import com .linkedin .metadata .search .utils .BrowsePathUtils ;
18
18
import com .linkedin .parseq .Task ;
19
+ import com .linkedin .restli .common .HttpStatus ;
20
+ import com .linkedin .restli .common .validation .RestLiDataValidator ;
19
21
import com .linkedin .restli .server .annotations .Action ;
20
22
import com .linkedin .restli .server .annotations .ActionParam ;
21
23
import com .linkedin .restli .server .annotations .Optional ;
22
24
import com .linkedin .restli .server .annotations .QueryParam ;
23
25
import com .linkedin .restli .server .annotations .RestLiCollection ;
24
26
import com .linkedin .restli .server .annotations .RestMethod ;
27
+ import com .linkedin .restli .server .annotations .ValidatorParam ;
25
28
import com .linkedin .restli .server .resources .CollectionResourceTaskTemplate ;
26
29
import java .net .URISyntaxException ;
27
30
import java .time .Clock ;
39
42
import org .slf4j .LoggerFactory ;
40
43
41
44
import static com .linkedin .metadata .PegasusUtils .urnToEntityName ;
45
+ import static com .linkedin .metadata .resources .ResourceUtils .*;
42
46
import static com .linkedin .metadata .restli .RestliConstants .ACTION_AUTOCOMPLETE ;
43
47
import static com .linkedin .metadata .restli .RestliConstants .ACTION_BROWSE ;
44
48
import static com .linkedin .metadata .restli .RestliConstants .ACTION_GET_BROWSE_PATHS ;
@@ -95,6 +99,8 @@ public Task<Entity> get(@Nonnull String urnStr, @QueryParam(PARAM_ASPECTS) @Opti
95
99
final Entity entity = _entityService .getEntity (urn , projectedAspects );
96
100
if (entity == null ) {
97
101
throw RestliUtils .resourceNotFoundException ();
102
+ } else {
103
+ validateRecord (entity , HttpStatus .S_500_INTERNAL_SERVER_ERROR );
98
104
}
99
105
return entity ;
100
106
});
@@ -116,13 +122,17 @@ public Task<Map<String, Entity>> batchGet(
116
122
return _entityService .getEntities (urns , projectedAspects )
117
123
.entrySet ()
118
124
.stream ()
125
+ .peek (entry -> validateRecord (entry .getValue (), HttpStatus .S_500_INTERNAL_SERVER_ERROR ))
119
126
.collect (Collectors .toMap (entry -> entry .getKey ().toString (), Map .Entry ::getValue ));
120
127
});
121
128
}
122
129
123
130
@ Action (name = ACTION_INGEST )
124
131
@ Nonnull
125
- public Task <Void > ingest (@ ActionParam (PARAM_ENTITY ) @ Nonnull Entity entity ) throws URISyntaxException {
132
+ public Task <Void > ingest (@ ActionParam (PARAM_ENTITY ) @ Nonnull Entity entity , @ ValidatorParam RestLiDataValidator validator ) throws URISyntaxException {
133
+
134
+ validateRecord (entity , HttpStatus .S_422_UNPROCESSABLE_ENTITY );
135
+
126
136
final Set <String > projectedAspects = new HashSet <>(Arrays .asList ("browsePaths" ));
127
137
final RecordTemplate snapshotRecord = RecordUtils .getSelectedRecordTemplateFromUnion (entity .getValue ());
128
138
final Urn urn = com .linkedin .metadata .dao .utils .ModelUtils .getUrnFromSnapshot (snapshotRecord );
@@ -144,6 +154,10 @@ public Task<Void> ingest(@ActionParam(PARAM_ENTITY) @Nonnull Entity entity) thro
144
154
@ Action (name = ACTION_BATCH_INGEST )
145
155
@ Nonnull
146
156
public Task <Void > batchIngest (@ ActionParam (PARAM_ENTITIES ) @ Nonnull Entity [] entities ) throws URISyntaxException {
157
+ for (Entity entity : entities ) {
158
+ validateRecord (entity , HttpStatus .S_422_UNPROCESSABLE_ENTITY );
159
+ }
160
+
147
161
final AuditStamp auditStamp =
148
162
new AuditStamp ().setTime (_clock .millis ()).setActor (Urn .createFromString (DEFAULT_ACTOR ));
149
163
return RestliUtils .toTask (() -> {
0 commit comments