Search in sources :

Example 1 with ExtensibleType

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();
}
Also used : ExtensibleTypeBuilder(com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) FieldDescriptorBuilder(com.thinkbiganalytics.metadata.api.extension.FieldDescriptorBuilder)

Example 2 with ExtensibleType

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");
}
Also used : ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) Test(org.testng.annotations.Test)

Example 3 with ExtensibleType

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");
}
Also used : ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) Test(org.testng.annotations.Test)

Example 4 with ExtensibleType

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();
}
Also used : HashMap(java.util.HashMap) ExtensibleEntity(com.thinkbiganalytics.metadata.api.extension.ExtensibleEntity) ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) Test(org.testng.annotations.Test)

Example 5 with ExtensibleType

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);
    });
}
Also used : ExtensibleType(com.thinkbiganalytics.metadata.api.extension.ExtensibleType) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

ExtensibleType (com.thinkbiganalytics.metadata.api.extension.ExtensibleType)10 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 FieldDescriptor (com.thinkbiganalytics.metadata.api.extension.FieldDescriptor)2 Consumes (javax.ws.rs.Consumes)2 ExtensibleEntity (com.thinkbiganalytics.metadata.api.extension.ExtensibleEntity)1 ExtensibleTypeBuilder (com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder)1 FieldDescriptorBuilder (com.thinkbiganalytics.metadata.api.extension.FieldDescriptorBuilder)1 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Session (javax.jcr.Session)1 NodeType (javax.jcr.nodetype.NodeType)1 NodeTypeIterator (javax.jcr.nodetype.NodeTypeIterator)1 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)1 GET (javax.ws.rs.GET)1