diff --git a/src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java b/src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java index d171619..2119a18 100644 --- a/src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java +++ b/src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java @@ -98,4 +98,5 @@ public boolean isCascadingEnabled() { public void setCascadingEnabled(boolean cascadingEnabled) { this.cascadingEnabled = cascadingEnabled; } + } diff --git a/src/main/java/com/marklogic/client/ext/file/CollectionsFileDocumentFileProcessor.java b/src/main/java/com/marklogic/client/ext/file/CollectionsFileDocumentFileProcessor.java index 28d09e2..2756d6b 100644 --- a/src/main/java/com/marklogic/client/ext/file/CollectionsFileDocumentFileProcessor.java +++ b/src/main/java/com/marklogic/client/ext/file/CollectionsFileDocumentFileProcessor.java @@ -15,6 +15,10 @@ */ package com.marklogic.client.ext.file; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.util.Enumeration; import java.util.Properties; /** @@ -36,15 +40,16 @@ public CollectionsFileDocumentFileProcessor(String propertiesFilename) { @Override protected void processProperties(DocumentFile documentFile, Properties properties) { - String name = documentFile.getFile().getName(); - if (properties.containsKey(name)) { - String value = getPropertyValue(properties, name); - documentFile.getDocumentMetadata().withCollections(value.split(delimiter)); - } - - if (properties.containsKey(WILDCARD_KEY)) { - String value = getPropertyValue(properties, WILDCARD_KEY); - documentFile.getDocumentMetadata().withCollections(value.split(delimiter)); + Path name = documentFile.getFile().toPath().getFileName(); + Enumeration keys = properties.propertyNames(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + PathMatcher matcher = + FileSystems.getDefault().getPathMatcher( "glob:" + key); + if (matcher.matches(name)) { + String value = getPropertyValue(properties, key); + documentFile.getDocumentMetadata().withCollections(value.split(delimiter)); + } } } diff --git a/src/main/java/com/marklogic/client/ext/file/PermissionsFileDocumentFileProcessor.java b/src/main/java/com/marklogic/client/ext/file/PermissionsFileDocumentFileProcessor.java index b92db8e..94c8778 100644 --- a/src/main/java/com/marklogic/client/ext/file/PermissionsFileDocumentFileProcessor.java +++ b/src/main/java/com/marklogic/client/ext/file/PermissionsFileDocumentFileProcessor.java @@ -17,6 +17,10 @@ import com.marklogic.client.ext.util.DocumentPermissionsParser; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.nio.file.PathMatcher; +import java.util.Enumeration; import java.util.Properties; /** @@ -48,23 +52,19 @@ public PermissionsFileDocumentFileProcessor(String propertiesFilename, DocumentP @Override protected void processProperties(DocumentFile documentFile, Properties properties) { - String name = documentFile.getFile().getName(); - if (properties.containsKey(name)) { - String value = getPropertyValue(properties, name); - if (documentPermissionsParser != null) { - documentPermissionsParser.parsePermissions(value, documentFile.getDocumentMetadata().getPermissions()); - } else { - documentFile.getDocumentMetadata().getPermissions().addFromDelimitedString(value); - } - - } - - if (properties.containsKey(WILDCARD_KEY)) { - String value = getPropertyValue(properties, WILDCARD_KEY); - if (documentPermissionsParser != null) { - documentPermissionsParser.parsePermissions(value, documentFile.getDocumentMetadata().getPermissions()); - } else { - documentFile.getDocumentMetadata().getPermissions().addFromDelimitedString(value); + Path name = documentFile.getFile().toPath().getFileName(); + Enumeration keys = properties.propertyNames(); + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + PathMatcher matcher = + FileSystems.getDefault().getPathMatcher( "glob:" + key); + if (matcher.matches(name)) { + String value = getPropertyValue(properties, key); + if (documentPermissionsParser != null) { + documentPermissionsParser.parsePermissions(value, documentFile.getDocumentMetadata().getPermissions()); + } else { + documentFile.getDocumentMetadata().getPermissions().addFromDelimitedString(value); + } } } } diff --git a/src/test/java/com/marklogic/client/ext/file/CollectionsFileDocumentFileProcessorTest.java b/src/test/java/com/marklogic/client/ext/file/CollectionsFileDocumentFileProcessorTest.java index e33939f..b36a657 100644 --- a/src/test/java/com/marklogic/client/ext/file/CollectionsFileDocumentFileProcessorTest.java +++ b/src/test/java/com/marklogic/client/ext/file/CollectionsFileDocumentFileProcessorTest.java @@ -38,12 +38,21 @@ public void wildcard() throws IOException { DocumentFile file = new DocumentFile("/test.json", new File(testDir, "test.json")); processor.processDocumentFile(file); assertTrue(file.getDocumentMetadata().getCollections().contains("json-data")); + assertTrue(file.getDocumentMetadata().getCollections().contains("json-data-wildcard")); + assertFalse(file.getDocumentMetadata().getCollections().contains("xml-data")); + assertTrue(file.getDocumentMetadata().getCollections().contains("global")); + + file = new DocumentFile("/test-1.json", new File(testDir, "test-1.json")); + processor.processDocumentFile(file); + assertFalse(file.getDocumentMetadata().getCollections().contains("json-data")); + assertTrue(file.getDocumentMetadata().getCollections().contains("json-data-wildcard")); assertFalse(file.getDocumentMetadata().getCollections().contains("xml-data")); assertTrue(file.getDocumentMetadata().getCollections().contains("global")); file = new DocumentFile("/test.xml", new File(testDir, "test.xml")); processor.processDocumentFile(file); assertFalse(file.getDocumentMetadata().getCollections().contains("json-data")); + assertFalse(file.getDocumentMetadata().getCollections().contains("json-data-wildcard")); assertTrue(file.getDocumentMetadata().getCollections().contains("xml-data")); assertTrue(file.getDocumentMetadata().getCollections().contains("global")); } diff --git a/src/test/java/com/marklogic/client/ext/file/PermissionsFileDocumentFileProcessorTest.java b/src/test/java/com/marklogic/client/ext/file/PermissionsFileDocumentFileProcessorTest.java index 64c9ade..44bd32c 100644 --- a/src/test/java/com/marklogic/client/ext/file/PermissionsFileDocumentFileProcessorTest.java +++ b/src/test/java/com/marklogic/client/ext/file/PermissionsFileDocumentFileProcessorTest.java @@ -47,7 +47,15 @@ public void wildcard() throws IOException { assertTrue(permissions.get("manage-user").contains(DocumentMetadataHandle.Capability.READ)); assertTrue(permissions.get("manage-user").contains(DocumentMetadataHandle.Capability.UPDATE)); assertTrue(permissions.get("manage-admin").contains(DocumentMetadataHandle.Capability.UPDATE)); - assertNull(permissions.get("qconsole-user")); + assertTrue(permissions.get("qconsole-user").contains(DocumentMetadataHandle.Capability.READ)); + + file = new DocumentFile("/test-1.json", new File(testDir, "test-1.json")); + processor.processDocumentFile(file); + permissions = file.getDocumentMetadata().getPermissions(); + assertTrue(permissions.get("manage-user").contains(DocumentMetadataHandle.Capability.READ)); + assertFalse(permissions.get("manage-user").contains(DocumentMetadataHandle.Capability.UPDATE)); + assertNull(permissions.get("manage-admin")); + assertTrue(permissions.get("qconsole-user").contains(DocumentMetadataHandle.Capability.READ)); file = new DocumentFile("/test.xml", new File(testDir, "test.xml")); processor.processDocumentFile(file); diff --git a/src/test/resources/process-files/wildcard-test/collections.properties b/src/test/resources/process-files/wildcard-test/collections.properties index d44c90f..5a556e0 100644 --- a/src/test/resources/process-files/wildcard-test/collections.properties +++ b/src/test/resources/process-files/wildcard-test/collections.properties @@ -1,3 +1,4 @@ *=global test.json=json-data +*.json=json-data-wildcard test.xml=xml-data diff --git a/src/test/resources/process-files/wildcard-test/permissions.properties b/src/test/resources/process-files/wildcard-test/permissions.properties index ba233c0..abaacec 100644 --- a/src/test/resources/process-files/wildcard-test/permissions.properties +++ b/src/test/resources/process-files/wildcard-test/permissions.properties @@ -1,3 +1,4 @@ *=manage-user,read test.json=manage-user,update,manage-admin,update +*.json=qconsole-user,read test.xml=qconsole-user,update diff --git a/src/test/resources/process-files/wildcard-test/test-1.json b/src/test/resources/process-files/wildcard-test/test-1.json new file mode 100644 index 0000000..9859cd3 --- /dev/null +++ b/src/test/resources/process-files/wildcard-test/test-1.json @@ -0,0 +1,3 @@ +{ + "test": "test-1" +}