|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | +package org.elasticsearch.logstashbridge.ingest; |
| 9 | + |
| 10 | +import org.elasticsearch.ingest.IngestDocument; |
| 11 | +import org.elasticsearch.ingest.LogstashInternalBridge; |
| 12 | +import org.elasticsearch.logstashbridge.StableBridgeAPI; |
| 13 | +import org.elasticsearch.logstashbridge.script.MetadataBridge; |
| 14 | +import org.elasticsearch.logstashbridge.script.TemplateScriptBridge; |
| 15 | + |
| 16 | +import java.util.Map; |
| 17 | +import java.util.Set; |
| 18 | +import java.util.function.BiConsumer; |
| 19 | + |
| 20 | +public class IngestDocumentBridge extends StableBridgeAPI.Proxy<IngestDocument> { |
| 21 | + |
| 22 | + public static String INGEST_KEY = IngestDocument.INGEST_KEY; |
| 23 | + |
| 24 | + public static IngestDocumentBridge wrap(final IngestDocument ingestDocument) { |
| 25 | + if (ingestDocument == null) { |
| 26 | + return null; |
| 27 | + } |
| 28 | + return new IngestDocumentBridge(ingestDocument); |
| 29 | + } |
| 30 | + |
| 31 | + public IngestDocumentBridge(final Map<String, Object> sourceAndMetadata, final Map<String, Object> ingestMetadata) { |
| 32 | + this(new IngestDocument(sourceAndMetadata, ingestMetadata)); |
| 33 | + } |
| 34 | + |
| 35 | + private IngestDocumentBridge(IngestDocument inner) { |
| 36 | + super(inner); |
| 37 | + } |
| 38 | + |
| 39 | + public MetadataBridge getMetadata() { |
| 40 | + return new MetadataBridge(delegate.getMetadata()); |
| 41 | + } |
| 42 | + |
| 43 | + public Map<String, Object> getSource() { |
| 44 | + return delegate.getSource(); |
| 45 | + } |
| 46 | + |
| 47 | + public boolean updateIndexHistory(final String index) { |
| 48 | + return delegate.updateIndexHistory(index); |
| 49 | + } |
| 50 | + |
| 51 | + public Set<String> getIndexHistory() { |
| 52 | + return Set.copyOf(delegate.getIndexHistory()); |
| 53 | + } |
| 54 | + |
| 55 | + public boolean isReroute() { |
| 56 | + return LogstashInternalBridge.isReroute(delegate); |
| 57 | + } |
| 58 | + |
| 59 | + public void resetReroute() { |
| 60 | + LogstashInternalBridge.resetReroute(delegate); |
| 61 | + } |
| 62 | + |
| 63 | + public Map<String, Object> getIngestMetadata() { |
| 64 | + return Map.copyOf(delegate.getIngestMetadata()); |
| 65 | + } |
| 66 | + |
| 67 | + public <T> T getFieldValue(final String fieldName, final Class<T> type) { |
| 68 | + return delegate.getFieldValue(fieldName, type); |
| 69 | + } |
| 70 | + |
| 71 | + public <T> T getFieldValue(final String fieldName, final Class<T> type, final boolean ignoreMissing) { |
| 72 | + return delegate.getFieldValue(fieldName, type, ignoreMissing); |
| 73 | + } |
| 74 | + |
| 75 | + public String renderTemplate(final TemplateScriptBridge.Factory templateScriptFactory) { |
| 76 | + return delegate.renderTemplate(templateScriptFactory.unwrap()); |
| 77 | + } |
| 78 | + |
| 79 | + public void setFieldValue(final String path, final Object value) { |
| 80 | + delegate.setFieldValue(path, value); |
| 81 | + } |
| 82 | + |
| 83 | + public void removeField(final String path) { |
| 84 | + delegate.removeField(path); |
| 85 | + } |
| 86 | + |
| 87 | + // public void executePipeline(Pipeline pipeline, BiConsumer<IngestDocument, Exception> handler) { |
| 88 | + public void executePipeline(final PipelineBridge pipelineBridge, final BiConsumer<IngestDocumentBridge, Exception> handler) { |
| 89 | + this.delegate.executePipeline(pipelineBridge.unwrap(), (unwrapped, e) -> handler.accept(IngestDocumentBridge.wrap(unwrapped), e)); |
| 90 | + } |
| 91 | +} |
0 commit comments