Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ public boolean isCascadingEnabled() {
public void setCascadingEnabled(boolean cascadingEnabled) {
this.cascadingEnabled = cascadingEnabled;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*=global
test.json=json-data
*.json=json-data-wildcard
test.xml=xml-data
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*=manage-user,read
test.json=manage-user,update,manage-admin,update
*.json=qconsole-user,read
test.xml=qconsole-user,update
3 changes: 3 additions & 0 deletions src/test/resources/process-files/wildcard-test/test-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test": "test-1"
}