Search in sources :

Example 1 with ExtensibleTypeBuilder

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder 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 ExtensibleTypeBuilder

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder in project kylo by Teradata.

the class JcrExtensibleTypeProvider method updateType.

@Nonnull
@Override
public ExtensibleTypeBuilder updateType(@Nonnull final ID id) {
    try {
        final JcrExtensibleType.TypeId typeId = (JcrExtensibleType.TypeId) id;
        final Node typeNode = getSession().getNodeByIdentifier(typeId.getIdValue());
        return new TypeBuilder(typeNode.getName(), typeNode);
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Unable to retrieve extensible type: " + id, e);
    }
}
Also used : MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) ExtensibleTypeBuilder(com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder) Node(javax.jcr.Node) MetadataRepositoryException(com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Nonnull(javax.annotation.Nonnull)

Example 3 with ExtensibleTypeBuilder

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder in project kylo by Teradata.

the class ExtensiblesModel method createType.

/**
 * Create the API model ExtensibleType from the REST model ExtensibleTypeDescriptor
 *
 * @param typeDescr    the type descriptor given in the rest call
 * @param typeProvider the type provider
 * @return the extensible type
 */
public static ExtensibleType createType(ExtensibleTypeDescriptor typeDescr, ExtensibleTypeProvider typeProvider) {
    ExtensibleTypeBuilder bldr = typeProvider.buildType(typeDescr.getName());
    build(typeDescr, bldr);
    return bldr.build();
}
Also used : ExtensibleTypeBuilder(com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder)

Example 4 with ExtensibleTypeBuilder

use of com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder in project kylo by Teradata.

the class ExtensiblesModel method updateType.

/**
 * Create an extensible type using the REST model and an ID and provider
 *
 * @param typeDescr    the type descriptor given in the rest call
 * @param id           the id to use
 * @param typeProvider the type provider
 * @return the extensible type
 */
public static ExtensibleType updateType(ExtensibleTypeDescriptor typeDescr, ExtensibleType.ID id, ExtensibleTypeProvider typeProvider) {
    ExtensibleTypeBuilder bldr = typeProvider.updateType(id);
    build(typeDescr, bldr);
    return bldr.build();
}
Also used : ExtensibleTypeBuilder(com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder)

Aggregations

ExtensibleTypeBuilder (com.thinkbiganalytics.metadata.api.extension.ExtensibleTypeBuilder)4 ExtensibleType (com.thinkbiganalytics.metadata.api.extension.ExtensibleType)1 FieldDescriptorBuilder (com.thinkbiganalytics.metadata.api.extension.FieldDescriptorBuilder)1 MetadataRepositoryException (com.thinkbiganalytics.metadata.modeshape.MetadataRepositoryException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Nonnull (javax.annotation.Nonnull)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1