use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType 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();
}
use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType in project kylo by Teradata.
the class JcrExtensibleProvidersTest method testCreateEmployeeType.
@Test(dependsOnMethods = "testCreatePersonType")
public void testCreateEmployeeType() {
String typeName = metadata.commit(() -> {
ExtensibleType person = typeProvider.getType("Person");
// @formatter:off
ExtensibleType emp = typeProvider.buildType("Employee").supertype(person).field("name").type(FieldDescriptor.Type.STRING).displayName("Person name").description("The name of the person").required(true).add().addField("description", FieldDescriptor.Type.STRING).addField("age", FieldDescriptor.Type.LONG).build();
return emp.getSupertype().getName();
}, MetadataAccess.SERVICE);
assertThat(typeName).isNotNull().isEqualTo("Person");
}
use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType in project kylo by Teradata.
the class JcrExtensibleProvidersTest method testCreatePersonType.
@Test(dependsOnMethods = "testGetAllDefaultTypes")
public void testCreatePersonType() {
String typeName = metadata.commit(() -> {
// @formatter:off
ExtensibleType type = typeProvider.buildType("Person").field("name").type(FieldDescriptor.Type.STRING).displayName("Person name").description("The name of the person").required(true).add().addField("description", FieldDescriptor.Type.STRING).addField("age", FieldDescriptor.Type.LONG).build();
return type.getName();
}, MetadataAccess.SERVICE);
assertThat(typeName).isNotNull().isEqualTo("Person");
}
use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType in project kylo by Teradata.
the class JcrExtensibleProvidersTest method testCreateEntity.
@Test(dependsOnMethods = "testCreatePersonType")
public void testCreateEntity() {
ExtensibleEntity.ID id = metadata.commit(() -> {
ExtensibleType type = typeProvider.getType("Person");
Map<String, Object> props = new HashMap<>();
props.put("name", "Bob");
props.put("description", "Silly");
props.put("age", 50);
ExtensibleEntity entity = entityProvider.createEntity(type, props);
return entity.getId();
}, MetadataAccess.SERVICE);
assertThat(id).isNotNull();
}
use of com.thinkbiganalytics.metadata.api.extension.ExtensibleType in project kylo by Teradata.
the class ExtensionsController method createType.
/**
* creates a new extensible type
*
* @param descr a model of the extensible type descriptor
* @return the type that was persisted to the metadata store
*/
@Path("type")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ExtensibleTypeDescriptor createType(ExtensibleTypeDescriptor descr) {
return metadata.commit(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
ExtensibleType type = ExtensiblesModel.createType(descr, this.typeProvider);
return ExtensiblesModel.DOMAIN_TO_TYPE.apply(type);
});
}
Aggregations