boolean emitSource = ! ((field.getRecord() == oldField.getRecord()) && (field.getRecord() == this)); errorMessageBuilder.append("Field \"").append(field.getName()); errorMessageBuilder.append("\" defined more than once, with ").append(oldField.getType()); if (emitSource) errorMessageBuilder.append(" defined in \"").append(oldField.getRecord().getFullName()).append("\""); errorMessageBuilder.append(" defined in \"").append(field.getRecord().getFullName()).append("\"");
/** * Build the schema of a {@link DynamicRecordTemplate}. * * @param name the name of the record. * @param fieldDefs the fields of the record. * @throws IllegalArgumentException if the {@link com.linkedin.data.schema.RecordDataSchema.Field} of the fieldDefs * are already set. */ public static RecordDataSchema buildSchema(String name, Collection<? extends FieldDef<?>> fieldDefs) { StringBuilder errorMessageBuilder = new StringBuilder(); RecordDataSchema schema = new RecordDataSchema(new Name(name, errorMessageBuilder), RecordDataSchema.RecordType.RECORD); List<RecordDataSchema.Field> fields = new ArrayList<RecordDataSchema.Field>(fieldDefs.size()); for (FieldDef<?> fieldDef: fieldDefs) { RecordDataSchema.Field paramField = fieldDef.getField(); if (paramField.getRecord() != null) { throw new IllegalArgumentException("Attempt to assign field "+ fieldDef.getName() + " to record " + schema.getName() + "failed: " + "Record of field is already set to " + paramField.getRecord().getName() ); } paramField.setRecord(schema); fields.add(paramField); } schema.setFields(fields, errorMessageBuilder); return schema; }
for (RecordDataSchema.Field field : schema.getFields()) if (field.getRecord().equals(schema))
/** * Encode a the fields of a {@link RecordDataSchema}. * * This method does not output a key. The key should be emitted before calling this method. * If {@link #isEncodeInclude()} returns true, then only fields that are defined in the record being * encoded will be encoded, else all fields including those from included records will be encoded. * * @param recordDataSchema the {@link RecordDataSchema} being encoded. * @throws IOException if there is an error while encoding. */ protected void encodeFields(RecordDataSchema recordDataSchema) throws IOException { Collection<RecordDataSchema.Field> fields = recordDataSchema.getFields(); _builder.writeStartArray(); boolean encodeInclude = isEncodeInclude(); for (RecordDataSchema.Field field : fields) { if (encodeInclude == false || recordDataSchema == field.getRecord()) { encodeField(field); } } _builder.writeEndArray(); }
private void addParams(ActionRequestBuilder<?, ?> request, DynamicRecordMetadata requestMetadata, ParameterSchemaArray parameters) { if (parameters != null) { for (ParameterSchema parameter : parameters) { FieldDef<?> fieldDef = requestMetadata.getFieldDef(parameter.getName()); Object value = generateFieldDefValue(fieldDef); // For custom types(TypeRefs) we generate the example values using the dereferenced type. Changing the field-def // to the dereferenced type so the example values can be set on the request without coercing. if (fieldDef.getDataSchema().getType() == Type.TYPEREF) { FieldDef<?> deRefFieldDef = new FieldDef<>(fieldDef.getName(), fieldDef.getDataClass(), fieldDef.getDataSchema().getDereferencedDataSchema()); deRefFieldDef.getField().setRecord(fieldDef.getField().getRecord()); fieldDef = deRefFieldDef; } request.setParam(fieldDef, value); } } }
/** * Check if this {@link FieldDef} belongs to the {@link RecordDataSchema} in this * {@link DynamicRecordTemplate}. * * If this fails, it is because the FieldDef passed in was not the same fieldDef used to create * the RecordDataSchema. * * @param fieldDef provides the {@link FieldDef} to check. * @return true if the provided fieldDef belongs to the schema of this {@link DynamicRecordTemplate}, false otherwise. */ private boolean fieldDefInRecord(FieldDef<?> fieldDef) { return fieldDef.getField().getRecord() == this.schema(); }