|
16 | 16 |
|
17 | 17 | package io.apicurio.registry.ccompat.rest.v6.impl;
|
18 | 18 |
|
| 19 | +import io.apicurio.common.apps.logging.Logged; |
19 | 20 | import io.apicurio.registry.auth.Authorized;
|
20 | 21 | import io.apicurio.registry.auth.AuthorizedLevel;
|
21 | 22 | import io.apicurio.registry.auth.AuthorizedStyle;
|
22 | 23 | import io.apicurio.registry.ccompat.dto.SchemaInfo;
|
23 | 24 | import io.apicurio.registry.ccompat.dto.SubjectVersion;
|
24 | 25 | import io.apicurio.registry.ccompat.rest.v6.SchemasResource;
|
25 |
| -import io.apicurio.common.apps.logging.Logged; |
| 26 | +import io.apicurio.registry.ccompat.rest.v7.impl.AbstractResource; |
| 27 | +import io.apicurio.registry.content.ContentHandle; |
26 | 28 | import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
|
27 | 29 | import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
|
| 30 | +import io.apicurio.registry.storage.ArtifactNotFoundException; |
| 31 | +import io.apicurio.registry.storage.dto.ArtifactMetaDataDto; |
| 32 | +import io.apicurio.registry.storage.dto.ArtifactReferenceDto; |
| 33 | +import io.apicurio.registry.storage.dto.ContentWrapperDto; |
| 34 | +import io.apicurio.registry.storage.dto.StoredArtifactDto; |
28 | 35 | import io.apicurio.registry.types.ArtifactType;
|
29 |
| - |
| 36 | +import io.apicurio.registry.util.ArtifactTypeUtil; |
30 | 37 | import jakarta.interceptor.Interceptors;
|
| 38 | + |
31 | 39 | import java.util.Arrays;
|
| 40 | +import java.util.Collections; |
32 | 41 | import java.util.List;
|
| 42 | +import java.util.stream.Collectors; |
| 43 | + |
| 44 | +import static io.apicurio.registry.storage.RegistryStorage.ArtifactRetrievalBehavior.DEFAULT; |
33 | 45 |
|
34 | 46 | /**
|
35 | 47 | * @author Ales Justin
|
|
40 | 52 | public class SchemasResourceImpl extends AbstractResource implements SchemasResource {
|
41 | 53 |
|
42 | 54 | @Override
|
43 |
| - @Authorized(style=AuthorizedStyle.GlobalId, level=AuthorizedLevel.Read) |
| 55 | + @Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read) |
44 | 56 | public SchemaInfo getSchema(int id) {
|
45 |
| - return facade.getSchemaById(id); |
| 57 | + ContentHandle contentHandle; |
| 58 | + List<ArtifactReferenceDto> references; |
| 59 | + if (getCconfig().getCanonicalHashModeEnabled().get()) { |
| 60 | + StoredArtifactDto artifactVersion = getStorage().getArtifactVersion(id); |
| 61 | + contentHandle = artifactVersion.getContent(); |
| 62 | + references = artifactVersion.getReferences(); |
| 63 | + } else { |
| 64 | + ContentWrapperDto contentWrapper = getStorage().getArtifactByContentId(id); |
| 65 | + contentHandle = getStorage().getArtifactByContentId(id).getContent(); |
| 66 | + references = contentWrapper.getReferences(); |
| 67 | + List<ArtifactMetaDataDto> artifacts = getStorage().getArtifactVersionsByContentId(id); |
| 68 | + if (artifacts == null || artifacts.isEmpty()) { |
| 69 | + //the contentId points to an orphaned content |
| 70 | + throw new ArtifactNotFoundException("ContentId: " + id); |
| 71 | + } |
| 72 | + } |
| 73 | + return getConverter().convert(contentHandle, ArtifactTypeUtil.determineArtifactType(contentHandle, null, null, getStorage().resolveReferences(references), getFactory().getAllArtifactTypes()), references); |
46 | 74 | }
|
47 | 75 |
|
48 | 76 | @Override
|
49 |
| - @Authorized(style=AuthorizedStyle.GlobalId, level=AuthorizedLevel.Read) |
| 77 | + @Authorized(style = AuthorizedStyle.GlobalId, level = AuthorizedLevel.Read) |
50 | 78 | public List<SubjectVersion> getSubjectVersions(int id) {
|
51 |
| - return facade.getSubjectVersions(id); |
| 79 | + if (getCconfig().getLegacyIdModeEnabled().get()) { |
| 80 | + ArtifactMetaDataDto artifactMetaData = getStorage().getArtifactMetaData(id); |
| 81 | + return Collections.singletonList(getConverter().convert(artifactMetaData.getId(), artifactMetaData.getVersionId())); |
| 82 | + } |
| 83 | + |
| 84 | + return getStorage().getArtifactVersionsByContentId(id) |
| 85 | + .stream() |
| 86 | + .filter(artifactMetaData -> isArtifactActive(artifactMetaData.getId(), artifactMetaData.getGroupId(), DEFAULT)) |
| 87 | + .map(artifactMetaData -> getConverter().convert(artifactMetaData.getId(), artifactMetaData.getVersionId())) |
| 88 | + .collect(Collectors.toList()); |
52 | 89 | }
|
53 | 90 |
|
54 | 91 | @Override
|
55 |
| - @Authorized(style=AuthorizedStyle.None, level=AuthorizedLevel.Read) |
| 92 | + @Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read) |
56 | 93 | public List<String> getRegisteredTypes() {
|
57 | 94 | return Arrays.asList(ArtifactType.JSON, ArtifactType.PROTOBUF, ArtifactType.AVRO);
|
58 | 95 | }
|
|
0 commit comments