Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AICORE-630: Serialize blob filename in enrichment pipe records #636

Open
wants to merge 2 commits into
base: 2023
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ protected BlobTextFromDocument setupBlobTextFromDocument(String name) throws IOE
}

private ManagedBlob blob(Blob blob, String key) {
return new BlobMetaImpl("test", blob.getMimeType(), key, key, blob.getEncoding(), blob.getLength());
return new BlobMetaImpl("test", blob.getMimeType(), key, key, blob.getEncoding(), blob.getLength(), blob.getFilename());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public void shouldAddTranscribeAsEnrichment() throws IOException {
Blob blob = Blobs.createBlob("A string blob here");
String blobKey = blobProvider.writeBlob(blob);
ManagedBlob managedBlob = new BlobMetaImpl("test", blob.getMimeType(), blobKey, blobKey, blob.getEncoding(),
blob.getLength());
blob.getLength(), blob.getFilename());
btfd.addBlob("file:content", "img", managedBlob);
AIMetadata metadata = new EnrichmentMetadata.Builder(PROVIDER_KIND, PROVIDER_NAME,
new BlobTextFromDocument(doc)).withLabels(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,6 @@ public void shouldDetectMedicalContent() throws IOException {
}

protected ManagedBlob blob(Blob blob, String key) {
return new BlobMetaImpl("test", blob.getMimeType(), key, key, blob.getEncoding(), blob.getLength());
return new BlobMetaImpl("test", blob.getMimeType(), key, key, blob.getEncoding(), blob.getLength(), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static BlobTextFromDocument setupBlobForStream(BlobManager manager, Strin
BlobProvider blobProvider = manager.getBlobProvider("test");
Blob blob = Blobs.createBlob(manager.getClass().getResourceAsStream(fileName), mimeType);
ManagedBlob managedBlob = new BlobMetaImpl("test", blob.getMimeType(), blobProvider.writeBlob(blob),
blob.getDigest(), blob.getEncoding(), blob.getLength());
blob.getDigest(), blob.getEncoding(), blob.getLength(), null);
BlobTextFromDocument blobTextFromDoc = new BlobTextFromDocument();
blobTextFromDoc.setRepositoryName("test");
blobTextFromDoc.setId(UUID.randomUUID().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testBasicComponent() {
ComputationContext testContext = new ComputationContextImpl(null);
BlobTextFromDocument blobTextFromDoc = new BlobTextFromDocument();
blobTextFromDoc.addBlob(FILE_CONTENT, "img",
new BlobMetaImpl("test", "application/pdf", "xyx", "xyz", null, 45L));
new BlobMetaImpl("test", "application/pdf", "xyx", "xyz", null, 45L, null));
Record record = toRecord("k", blobTextFromDoc);

EnrichingStreamProcessor.EnrichmentMetrics metrics = new EnrichingStreamProcessor.EnrichmentMetrics("test.e1");
Expand Down Expand Up @@ -196,7 +196,7 @@ protected Record setupTestRecord() {
blobTextFromDoc.setId("xderftgt");
blobTextFromDoc.setRepositoryName("test");
blobTextFromDoc.addBlob(FILE_CONTENT, "img",
new BlobMetaImpl("test", "application/pdf", "xyx", "xyz", null, 45L));
new BlobMetaImpl("test", "application/pdf", "xyx", "xyz", null, 45L, null));
return toRecord("k", blobTextFromDoc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void testConfiguredStreamProcessor() throws Exception {
BlobTextFromDocument blobTextFromDoc = new BlobTextFromDocument();
blobTextFromDoc.setId(docId);
blobTextFromDoc.setRepositoryName(testDoc.getRepositoryName());
blobTextFromDoc.addBlob(FILE_CONTENT, "img", new BlobMetaImpl("test", "image/jpeg", "xyx", "xyz", null, 45L));
blobTextFromDoc.addBlob(FILE_CONTENT, "img", new BlobMetaImpl("test", "image/jpeg", "xyx", "xyz", null, 45L, null));

// Check metrics, nothing produced
Map<String, Gauge> gauges = getMetrics(METRICS_PREFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void testCacheKeys() throws IOException {
ManagedBlob blob = blobTextFromDoc.computePropertyBlobs().get(fileContentProp);
blobTextFromDoc.addBlob("TEST_AGAIN", "img",
new BlobMetaImpl(blob.getProviderId(), blob.getMimeType(), blob.getKey(), "58YY", blob.getEncoding(),
blob.getLength()));
blob.getLength(), null));
assertEquals("testin47XX_58YY", EnrichmentUtils.makeKeyUsingBlobDigests(blobTextFromDoc, "testin"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testCallService() throws IOException {

BlobTextFromDocument blobTextFromDoc = new BlobTextFromDocument("docId", "default", "parent", "File", null);
blobTextFromDoc.addBlob(FILE_CONTENT, "img",
new BlobMetaImpl("test", "application/pdf", "xyx", "xyz", null, 45L));
new BlobMetaImpl("test", "application/pdf", "xyx", "xyz", null, 45L, null));
Collection<EnrichmentMetadata> results = service.enrich(blobTextFromDoc);
assertEquals(1, results.size());
EnrichmentMetadata metadata = results.iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class TestModelServing {

protected static ManagedBlob blob(Blob blob, String key) {
return new BlobMetaImpl("test", blob.getMimeType(), key, blob.getDigest(), blob.getEncoding(),
blob.getLength());
blob.getLength(), null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public void serialize(ManagedBlob blob, JsonGenerator jg, SerializerProvider ser
jg.writeStringField("providerId", blob.getProviderId());
jg.writeStringField("key", blob.getKey());
jg.writeNumberField("length", blob.getLength());
jg.writeStringField("filename", blob.getFilename());
jg.writeEndObject();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ public class BlobMetaImpl extends AbstractBlob implements ManagedBlob {
@JsonCreator
public BlobMetaImpl(@JsonProperty("providerId") String providerId, @JsonProperty("mimeType") String mimeType,
@JsonProperty("key") String key, @JsonProperty("digest") String digest,
@JsonProperty("encoding") String encoding, @JsonProperty("length") long length) {
@JsonProperty("encoding") String encoding, @JsonProperty("length") long length,
@JsonProperty("filename") String filename ) {
this.providerId = providerId;
this.mimeType = mimeType;
this.key = key;
this.digest = digest;
this.encoding = encoding;
this.length = length;
this.filename = filename;
}

@Override
Expand Down Expand Up @@ -97,6 +99,11 @@ public String getDigest() {
return digest;
}

@Override
public String getFilename() {
return filename;
}

@Override
public InputStream getStream() throws IOException {
BlobProvider blobProvider = Framework.getService(BlobManager.class).getBlobProvider(getProviderId());
Expand Down