use of com.linkedin.data.grammar.PdlParser.JsonValueContext in project rest.li by linkedin.
the class PdlSchemaParser method parseFields.
private List<Field> parseFields(RecordDataSchema recordSchema, FieldSelectionContext fieldGroup) throws ParseException {
List<Field> results = new ArrayList<>();
for (FieldDeclarationContext field : fieldGroup.fields) {
if (field != null) {
if (field.type == null) {
throw new IllegalStateException("type is missing for field: " + field.getText());
}
Field result = new Field(toDataSchema(field.type));
recordLocation(result, field);
Map<String, Object> properties = new HashMap<>();
result.setName(field.name, errorMessageBuilder());
result.setOptional(field.isOptional);
FieldDefaultContext fieldDefault = field.fieldDefault();
if (fieldDefault != null) {
JsonValueContext defaultValue = fieldDefault.jsonValue();
if (defaultValue != null) {
result.setDefault(parseJsonValue(defaultValue));
}
}
List<String> aliases = new ArrayList<>();
RecordDataSchema.Field.Order sortOrder = null;
for (PropDeclarationContext prop : field.props) {
if (equalsSingleSegmentProperty(prop, DataSchemaConstants.ALIASES_KEY)) {
aliases = parseAliases(prop);
} else if (equalsSingleSegmentProperty(prop, DataSchemaConstants.ORDER_KEY)) {
Object value = parsePropValue(prop);
if (!(value instanceof String)) {
startErrorMessage(prop).append("'order' must be string, but found ").append(prop.getText()).append(NEWLINE);
} else {
String order = (String) value;
try {
sortOrder = RecordDataSchema.Field.Order.valueOf(order.toUpperCase());
} catch (IllegalArgumentException exc) {
startErrorMessage(order).append("\"").append(order).append("\" is an invalid sort order.\n");
}
}
} else {
addPropertiesAtPath(properties, prop);
}
}
if (field.doc != null) {
result.setDoc(field.doc.value);
}
if (aliases.size() > 0) {
result.setAliases(aliases, errorMessageBuilder());
}
if (sortOrder != null) {
result.setOrder(sortOrder);
}
result.setProperties(properties);
result.setRecord(recordSchema);
result.setDeclaredInline(isDeclaredInline(field.type));
results.add(result);
} else {
startErrorMessage(field).append("Unrecognized field element parse node: ").append(field.getText()).append(NEWLINE);
}
}
return results;
}
Aggregations