1 package io.apicurio.registry.maven.refs;
2
3 import io.apicurio.registry.content.ContentHandle;
4 import io.apicurio.registry.rest.client.models.VersionMetaData;
5 import io.apicurio.registry.types.ArtifactType;
6
7 import java.nio.file.Path;
8 import java.util.Set;
9
10 public class IndexedResource {
11
12 private final Path path;
13 private final String type;
14 private final String resourceName;
15 private final ContentHandle content;
16 private VersionMetaData registration;
17
18
19
20
21
22
23
24
25
26 public IndexedResource(Path path, String type, String resourceName, ContentHandle content) {
27 super();
28 this.path = path;
29 this.content = content;
30 this.type = type;
31 this.resourceName = resourceName;
32 }
33
34
35
36
37 public ContentHandle getContent() {
38 return content;
39 }
40
41
42
43
44 public String getType() {
45 return type;
46 }
47
48
49
50
51 public String getResourceName() {
52 return resourceName;
53 }
54
55
56
57
58 public Path getPath() {
59 return path;
60 }
61
62 public boolean matches(String resourceName, Path relativeToFile, Set<Path> schemaPaths) {
63
64 if (this.path == null) {
65 return this.resourceName.equals(resourceName);
66 }
67
68
69
70 if (ArtifactType.AVRO.equals(this.type)) {
71 if (this.resourceName.equals(resourceName)) {
72 return true;
73 }
74 }
75
76
77 Path resolvedPath = relativeToFile.getParent().resolve(resourceName);
78 boolean resolves = this.path.normalize().equals(resolvedPath.normalize());
79
80
81 if (!resolves && ArtifactType.PROTOBUF.equals(this.type)) {
82 resolves = schemaPaths.parallelStream()
83 .anyMatch(path -> this.path.normalize().equals(path.resolve(resourceName).normalize()));
84 }
85 return resolves;
86 }
87
88
89
90
91 public VersionMetaData getRegistration() {
92 return registration;
93 }
94
95
96
97
98 public void setRegistration(VersionMetaData registration) {
99 this.registration = registration;
100 }
101
102 public boolean isRegistered() {
103 return this.registration != null;
104 }
105 }