use of com.thinkbiganalytics.metadata.api.extension.FieldDescriptorBuilder in project kylo by Teradata.
the class JcrPropertyUtil method setUserFields.
/**
* Sets the user-defined fields for the specified type.
*
* @param name the type name
* @param fields the user-defined fields
* @param extensibleTypeProvider the type provider
*/
public static void setUserFields(@Nonnull final String name, @Nonnull final Set<UserFieldDescriptor> fields, @Nonnull final ExtensibleTypeProvider extensibleTypeProvider) {
// Get type builder
final ExtensibleTypeBuilder builder;
final ExtensibleType type = extensibleTypeProvider.getType(name);
if (type == null) {
builder = extensibleTypeProvider.buildType(name);
} else {
builder = extensibleTypeProvider.updateType(type.getId());
}
// Add fields to type
final String prefix = JcrMetadataAccess.USR_PREFIX + ":";
fields.forEach(field -> {
// Encode field name
final String systemName;
try {
systemName = prefix + URLEncoder.encode(field.getSystemName(), USER_PROPERTY_ENCODING);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e.toString(), e);
}
// Create field descriptor
final FieldDescriptorBuilder fieldBuilder = builder.field(systemName);
fieldBuilder.description(field.getDescription());
fieldBuilder.displayName(field.getDisplayName());
fieldBuilder.type(FieldDescriptor.Type.STRING);
fieldBuilder.property(JcrUserFieldDescriptor.ORDER, Integer.toString(field.getOrder()));
fieldBuilder.property(JcrUserFieldDescriptor.REQUIRED, Boolean.toString(field.isRequired()));
fieldBuilder.add();
});
builder.build();
}
Aggregations