This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git
The following commit(s) were added to refs/heads/master by this push:
new 8c87cb5 SLING-12254 handling jcr:data node missing for file resources
generated in binaries index defintions (#175)
8c87cb5 is described below
commit 8c87cb5aef9b971afc87d79a97ed22ce9e4ee4bf
Author: Abhishek Garg <[email protected]>
AuthorDate: Fri Feb 23 18:33:08 2024 +0530
SLING-12254 handling jcr:data node missing for file resources generated in
binaries index defintions (#175)
Co-authored-by: Abhishek Garg <[email protected]>
---
.../index/IndexDefinitionsJsonWriter.java | 9 +++-
.../index/IndexDefinitionsJsonWriterTest.java | 61 ++++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git
a/src/main/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriter.java
b/src/main/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriter.java
index ef33d8a..ef7ce43 100644
---
a/src/main/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriter.java
+++
b/src/main/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriter.java
@@ -158,10 +158,17 @@ public class IndexDefinitionsJsonWriter {
write(json,
JcrConstants.JCR_MIMETYPE,Collections.singletonList(Files.probeContentType(Paths.get(PlatformNameFormat.getPlatformName(nodeName)))),
Json::createValue );
write(json, JcrConstants.JCR_DATA,
Collections.singletonList(blobAsString), BLOB_MAPPER);
json.writeEnd();
- };
+ }
// 4. write children
for ( DocViewNode2 child : indexDefinitions.getChildren(nodePath)) {
+
+ if( binary.isPresent()){
+ String childNodeName =
indexDefinitions.toShortName(child.getName());
+ if(childNodeName.equalsIgnoreCase(JcrConstants.JCR_CONTENT)) {
+ continue;
+ }
+ }
write(json, child, nodePath);
}
diff --git
a/src/test/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriterTest.java
b/src/test/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriterTest.java
index 26e7566..09f1a7a 100644
---
a/src/test/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriterTest.java
+++
b/src/test/java/org/apache/sling/feature/cpconverter/index/IndexDefinitionsJsonWriterTest.java
@@ -194,6 +194,67 @@ public class IndexDefinitionsJsonWriterTest {
.hasFieldOrPropertyWithValue("string", ":blobId:" +
Base64.encode(configXmlFileContents));
}
+ @Test
+ public void luceneIndexDefinitionWithTikaConfigWithJcrContent() throws
IOException {
+
+ String configXmlFileContents = "<properties/>";
+
+ // lucene index
+ Collection<DocViewProperty2> luceneProps = new ArrayList<>();
+ luceneProps.add(new DocViewProperty2(nameFactory.create("{}type"),
"lucene"));
+ luceneProps.add(new
DocViewProperty2(nameFactory.create(NamespaceRegistry.NAMESPACE_JCR,
"primaryType"), OAK_PREFIX+":QueryIndexDefinition"));
+ luceneProps.add(new DocViewProperty2(nameFactory.create("{}reindex"),
Boolean.FALSE.toString(), PropertyType.BOOLEAN));
+ luceneProps.add(new
DocViewProperty2(nameFactory.create("{}reindexCount"), "1", PropertyType.LONG));
+ luceneProps.add(new
DocViewProperty2(nameFactory.create("{}includePropertyTypes"),
Arrays.asList("String", "Binary"), PropertyType.STRING));
+
+ definitions.addNode("/oak:index", new
DocViewNode2(nameFactory.create("{}lucene"), luceneProps));
+
+ // index rules node
+ List<DocViewProperty2> indexRulesProps = Collections.singletonList(new
DocViewProperty2(nameFactory.create(NamespaceRegistry.NAMESPACE_JCR,
"primaryType"), "nt:unstructured"));
+
+ definitions.addNode("/oak:index/lucene", new
DocViewNode2(nameFactory.create("{}indexRules"), indexRulesProps));
+
+ // tika node
+ List<DocViewProperty2> tikaProps = Collections.singletonList(new
DocViewProperty2(nameFactory.create(NamespaceRegistry.NAMESPACE_JCR,
"primaryType"), "nt:unstructured"));
+
+ definitions.addNode("/oak:index/lucene", new
DocViewNode2(nameFactory.create("{}tika"), tikaProps));
+
+ // tika config.xml node
+ List<DocViewProperty2> configXmlProps = Collections.singletonList(new
DocViewProperty2(nameFactory.create(NamespaceRegistry.NAMESPACE_JCR,
"primaryType"), "nt:file"));
+
+ definitions.addNode("/oak:index/lucene/tika", new
DocViewNode2(nameFactory.create("{}config.xml"), configXmlProps));
+ definitions.registerBinary("/oak:index/lucene/tika/config.xml", new
ByteArrayInputStream(configXmlFileContents.getBytes(StandardCharsets.UTF_8)));
+ definitions.addNode("/oak:index/lucene/tika/config.xml", new
DocViewNode2(nameFactory.create("{}"+JcrConstants.JCR_CONTENT), luceneProps));
+
+
+ JsonObject root = generateAndParse(definitions);
+ System.out.println(root);
+
+ assertThat(root).as("root index")
+ .hasEntrySatisfying("/oak:index/lucene",
Conditions.isJsonObject());
+
+ JsonObject lucene = root.getJsonObject("/oak:index/lucene");
+ assertThat(lucene).as("lucene index")
+ .hasEntrySatisfying("tika", Conditions.isJsonObject());
+
+ JsonObject tika = lucene.getJsonObject("tika");
+ assertThat(tika).as("tika node index")
+ .hasEntrySatisfying("config.xml", Conditions.isJsonObject());
+
+ JsonObject configNode = tika.getJsonObject("config.xml");
+ assertThat(configNode).as("config node has " +
JcrConstants.JCR_PRIMARYTYPE)
+ .containsKey(JcrConstants.JCR_PRIMARYTYPE);
+
+ JsonString jcrPrimaryType =
configNode.getJsonString(JcrConstants.JCR_PRIMARYTYPE);
+ assertThat(jcrPrimaryType.toString()).as("jcrPrimaryType property
contains " + JcrConstants.NT_FILE)
+ .contains(JcrConstants.NT_FILE);
+
+ JsonObject configContentNode =
configNode.getJsonObject(JcrConstants.JCR_CONTENT);
+ JsonString binaryEntry =
configContentNode.getJsonString(JcrConstants.JCR_DATA);
+ assertThat(binaryEntry).as("config.xml blob")
+ .hasFieldOrPropertyWithValue("string", ":blobId:" +
Base64.encode(configXmlFileContents));
+ }
+
@Test
public void propertyIndexDefinitionWithEmptyNodes() throws IOException {