Skip to content

Commit

Permalink
[Backport 2.x] Fix build after Lucene upgrade and breaking XContentFa…
Browse files Browse the repository at this point in the history
…ctory changes (#3069) (#3075)

Backport #3069 to 2.x
  • Loading branch information
cwperks authored Jul 31, 2023
1 parent 11041cd commit d925d8c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.index.StoredFieldVisitor;
import org.apache.lucene.index.StoredFields;
import org.apache.lucene.index.TermState;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
Expand Down Expand Up @@ -473,6 +474,24 @@ public void close() throws IOException {
}
}

private class DlsFlsStoredFields extends StoredFields {
private final StoredFields in;

public DlsFlsStoredFields(StoredFields storedFields) {
this.in = storedFields;
}

@Override
public void document(final int docID, StoredFieldVisitor visitor) throws IOException {
visitor = getDlsFlsVisitor(visitor);
try {
in.document(docID, visitor);
} finally {
finishVisitor(visitor);
}
}
}

@Override
protected StoredFieldsReader doGetSequentialStoredFieldsReader(final StoredFieldsReader reader) {
return new DlsFlsStoredFieldsReader(reader);
Expand Down Expand Up @@ -1284,6 +1303,12 @@ public TermState termState() throws IOException {

}

@Override
public StoredFields storedFields() throws IOException {
ensureOpen();
return new DlsFlsStoredFields(in.storedFields());
}

private String getRuntimeActionName() {
return (String) threadContext.getTransient(ConfigConstants.OPENDISTRO_SECURITY_ACTION_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static BytesReference readXContent(final Reader reader, final MediaType m
BytesReference retVal;
XContentParser parser = null;
try {
parser = XContentFactory.xContent(mediaType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, reader);
parser = mediaType.xContent().createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, reader);
parser.nextToken();
final XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ private static BytesReference readXContent(final String content, final MediaType
BytesReference retVal;
XContentParser parser = null;
try {
parser = XContentFactory.xContent(mediaType).createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, content);
parser = mediaType.xContent().createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, content);
parser.nextToken();
final XContentBuilder builder = XContentFactory.jsonBuilder();
builder.copyCurrentStructure(parser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static BytesReference readYamlContent(final String file) {

XContentParser parser = null;
try {
parser = XContentFactory.xContent(XContentType.YAML)
parser = XContentType.YAML.xContent()
.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, new StringReader(loadFile(file)));
parser.nextToken();
final XContentBuilder builder = XContentFactory.jsonBuilder();
Expand All @@ -127,7 +127,7 @@ public static BytesReference readYamlContentFromString(final String yaml) {

XContentParser parser = null;
try {
parser = XContentFactory.xContent(XContentType.YAML)
parser = XContentType.YAML.xContent()
.createParser(NamedXContentRegistry.EMPTY, THROW_UNSUPPORTED_OPERATION, new StringReader(yaml));
parser.nextToken();
final XContentBuilder builder = XContentFactory.jsonBuilder();
Expand Down

0 comments on commit d925d8c

Please sign in to comment.