All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.apicurio.registry.serde.SchemaResolver Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package io.apicurio.registry.serde;

import io.apicurio.registry.resolver.data.Record;
import io.apicurio.registry.resolver.strategy.ArtifactReferenceResolverStrategy;
import io.apicurio.registry.rest.client.RegistryClient;
import io.apicurio.registry.serde.data.KafkaSerdeMetadata;
import io.apicurio.registry.serde.data.KafkaSerdeRecord;
import io.apicurio.registry.serde.strategy.ArtifactReference;
import io.apicurio.registry.serde.strategy.ArtifactResolverStrategy;
import org.apache.kafka.common.header.Headers;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;

/**
 * This interface is kept for compatibility, It's recommended to migrate custom implementations to adhere the
 * new interface {@link io.apicurio.registry.resolver.SchemaResolver}
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Deprecated
public interface SchemaResolver
        extends io.apicurio.registry.resolver.SchemaResolver, Closeable {

    /**
     * Configure, if supported.
     *
     * @param configs the configs
     * @param isKey are we handling key or value
     */
    @Deprecated
    default void configure(Map configs, boolean isKey, SchemaParser schemaMapper) {
    }

    @Override
    @Deprecated
    public void setClient(RegistryClient client);

    @Deprecated
    default void setArtifactResolverStrategy(ArtifactResolverStrategy artifactResolverStrategy) {
        setArtifactResolverStrategy((ArtifactReferenceResolverStrategy) artifactResolverStrategy);
    }

    /**
     * Used by Serializers to lookup the schema for a given kafka record.
     * 
     * @param topic
     * @param headers, can be null
     * @param data
     * @param parsedSchema, can be null
     * @return SchemaLookupResult
     */
    @Deprecated
    public SchemaLookupResult resolveSchema(String topic, Headers headers, DATA data,
            ParsedSchema parsedSchema);

    /**
     * Used by Deserializers to lookup the schema for a given kafka record. The schema resolver may use
     * different pieces of information from the {@link ArtifactReference} depending on the configuration of
     * the schema resolver.
     * 
     * @param reference
     * @return SchemaLookupResult
     */
    @Deprecated
    public SchemaLookupResult resolveSchemaByArtifactReference(ArtifactReference reference);

    /**
     * Hard reset cache
     */
    @Override
    @Deprecated
    public void reset();

    /**
     * @see io.apicurio.registry.resolver.SchemaResolver#configure(java.util.Map,
     *      io.apicurio.registry.resolver.SchemaParser)
     */
    @Override
    default void configure(Map configs,
            io.apicurio.registry.resolver.SchemaParser schemaMapper) {
        configure(configs, true, new SchemaParser() {

            /**
             * @see io.apicurio.registry.serde.SchemaParser#artifactType()
             */
            @Override
            public String artifactType() {
                return schemaMapper.artifactType();
            }

            /**
             * @see io.apicurio.registry.serde.SchemaParser#parseSchema(byte[])
             */
            @Override
            public Object parseSchema(byte[] rawSchema) {
                return schemaMapper.parseSchema(rawSchema, Collections.emptyMap());
            }

        });
    }

    /**
     * @see io.apicurio.registry.resolver.SchemaResolver#resolveSchema(io.apicurio.registry.resolver.data.Record)
     */
    @Override
    default io.apicurio.registry.resolver.SchemaLookupResult resolveSchema(Record data) {
        KafkaSerdeRecord kdata = (KafkaSerdeRecord) data;
        KafkaSerdeMetadata metadata = kdata.metadata();
        io.apicurio.registry.resolver.ParsedSchema ps = getSchemaParser().getSchemaFromData(data);
        ParsedSchema compatps = ps == null ? null : new ParsedSchemaImpl()
                .setParsedSchema(ps.getParsedSchema()).setRawSchema(ps.getRawSchema());
        return resolveSchema(metadata.getTopic(), metadata.getHeaders(), kdata.payload(), compatps)
                .toCompat();
    }

    /**
     * @see io.apicurio.registry.resolver.SchemaResolver#resolveSchemaByArtifactReference(io.apicurio.registry.resolver.strategy.ArtifactReference)
     */
    @Override
    default io.apicurio.registry.resolver.SchemaLookupResult resolveSchemaByArtifactReference(
            io.apicurio.registry.resolver.strategy.ArtifactReference reference) {
        return resolveSchemaByArtifactReference(
                ArtifactReference.builder().contentId(reference.getContentId())
                        .globalId(reference.getGlobalId()).groupId(reference.getGroupId())
                        .artifactId(reference.getArtifactId()).version(reference.getVersion()).build())
                .toCompat();
    }

    /**
     * @see java.io.Closeable#close()
     */
    @Override
    default void close() throws IOException {
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy