Skip to content

Commit

Permalink
Use the new resolve mechanism only for json
Browse files Browse the repository at this point in the history
  • Loading branch information
carlesarnal committed Apr 26, 2024
1 parent de5de53 commit 58635f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.apicurio.registry.ccompat.rest.v7.impl;


import io.apicurio.registry.ccompat.dto.SchemaReference;
import io.apicurio.registry.ccompat.rest.error.ConflictException;
import io.apicurio.registry.ccompat.rest.error.UnprocessableEntityException;
Expand All @@ -25,28 +24,27 @@
import io.apicurio.registry.rules.RuleApplicationType;
import io.apicurio.registry.rules.RuleViolationException;
import io.apicurio.registry.rules.RulesService;
import io.apicurio.registry.storage.ArtifactNotFoundException;
import io.apicurio.registry.storage.RegistryStorage;
import io.apicurio.registry.storage.RuleNotFoundException;
import io.apicurio.registry.storage.VersionNotFoundException;
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
import io.apicurio.registry.storage.dto.StoredArtifactDto;
import io.apicurio.registry.storage.ArtifactNotFoundException;
import io.apicurio.registry.storage.RuleNotFoundException;
import io.apicurio.registry.storage.VersionNotFoundException;
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.Current;
import io.apicurio.registry.types.RuleType;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
import jakarta.inject.Inject;
import org.apache.avro.AvroTypeException;
import org.apache.avro.SchemaParseException;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;

import jakarta.inject.Inject;

import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -148,8 +146,8 @@ protected ArtifactVersionMetaDataDto lookupSchema(String groupId, String subject
amd = storage.getArtifactVersions(groupId, subject)
.stream().filter(version -> {
StoredArtifactDto artifactVersion = storage.getArtifactVersion(groupId, subject, version);
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(artifactVersion.getContent(), type, artifactVersion.getReferences(), storage::getContentByReference);
String dereferencedExistingContentSha = DigestUtils.sha256Hex(artifactTypeProvider.getContentDereferencer().dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences()).content());
Map<String, ContentHandle> artifactVersionReferences = RegistryContentUtils.recursivelyResolveReferences(artifactVersion.getReferences(), storage::getContentByReference);
String dereferencedExistingContentSha = DigestUtils.sha256Hex(artifactTypeProvider.getContentDereferencer().dereference(artifactVersion.getContent(), artifactVersionReferences).content());
return dereferencedExistingContentSha.equals(DigestUtils.sha256Hex(schema));
})
.findAny()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import io.apicurio.registry.storage.dto.VersionSearchResultsDto;
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.Current;
import io.apicurio.registry.types.ReferenceType;
import io.apicurio.registry.types.RuleType;
Expand Down Expand Up @@ -186,10 +187,16 @@ public Response getLatestArtifact(String groupId, String artifactId, Boolean der
ArtifactTypeUtilProvider artifactTypeProvider = factory.getArtifactTypeProvider(metaData.getType());

if (dereference && !artifact.getReferences().isEmpty()) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(contentToReturn, metaData.getType(),
artifact.getReferences(), storage::getContentByReference);

contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
if (ArtifactType.JSON.equals(metaData.getType())) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(contentToReturn,
metaData.getType(),
artifact.getReferences(), storage::getContentByReference);

contentToReturn = artifactTypeProvider.getContentDereferencer()
.dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
} else {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
}
}

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
Expand Down Expand Up @@ -577,10 +584,16 @@ public Response getArtifactVersion(String groupId, String artifactId, String ver
ArtifactTypeUtilProvider artifactTypeProvider = factory.getArtifactTypeProvider(metaData.getType());

if (dereference && !artifact.getReferences().isEmpty()) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(contentToReturn, metaData.getType(),
artifact.getReferences(), storage::getContentByReference);

contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
if (ArtifactType.JSON.equals(metaData.getType())) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(contentToReturn,
metaData.getType(),
artifact.getReferences(), storage::getContentByReference);

contentToReturn = artifactTypeProvider.getContentDereferencer()
.dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
} else {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
}
}

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
import io.apicurio.registry.types.ArtifactMediaTypes;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.types.ArtifactType;
import io.apicurio.registry.types.Current;
import io.apicurio.registry.types.ReferenceType;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
Expand All @@ -53,7 +54,7 @@
* @author [email protected]
*/
@ApplicationScoped
@Interceptors({ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class})
@Interceptors({ ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class })
@Logged
public class IdsResourceImpl implements IdsResource {

Expand Down Expand Up @@ -106,19 +107,17 @@ public Response getContentByGlobalId(long globalId, Boolean dereference) {
ArtifactTypeUtilProvider artifactTypeProvider = factory.getArtifactTypeProvider(metaData.getType());

if (dereference && !artifact.getReferences().isEmpty()) {
if (metaData.getType().equals("JSON")) {
if (ArtifactType.JSON.equals(metaData.getType())) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils.recursivelyResolveReferencesWithContext(contentToReturn,
metaData.getType(),
artifact.getReferences(), storage::getContentByReference);

contentToReturn = artifactTypeProvider.getContentDereferencer()
.dereference(rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
} else {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
}
else {
contentToReturn = artifactTypeProvider.getContentDereferencer()
.dereference(artifact.getContent(), RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(), storage::getContentByReference));
}
}
}

Response.ResponseBuilder builder = Response.ok(contentToReturn, contentType);
checkIfDeprecated(metaData::getState, metaData.getId(), metaData.getVersion(), builder);
Expand Down Expand Up @@ -165,7 +164,8 @@ public List<ArtifactReference> referencesByGlobalId(long globalId, ReferenceType
return artifact.getReferences().stream()
.map(V2ApiUtil::referenceDtoToReference)
.collect(Collectors.toList());
} else {
}
else {
ArtifactMetaDataDto amd = storage.getArtifactMetaData(globalId);
return storage.getInboundArtifactReferences(amd.getGroupId(), amd.getId(), amd.getVersion()).stream()
.map(V2ApiUtil::referenceDtoToReference)
Expand Down

0 comments on commit 58635f2

Please sign in to comment.