Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 8a5f38f

Browse files
authored
Merge pull request #192 from marklogic/feature/cascade-fix-2
Fixed how cascading is disabled
2 parents 6484db1 + c1bd555 commit 8a5f38f

File tree

15 files changed

+71
-34
lines changed

15 files changed

+71
-34
lines changed

src/main/java/com/marklogic/client/ext/file/CascadingPropertiesDrivenDocumentFileProcessor.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,39 @@ protected CascadingPropertiesDrivenDocumentFileProcessor(String propertiesFilena
4444

4545
@Override
4646
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
47-
File collectionsPropertiesFile = new File(dir.toFile(), this.getPropertiesFilename());
48-
if (collectionsPropertiesFile.exists()) {
49-
this.loadProperties(collectionsPropertiesFile);
47+
// If cascading is disabled, we still use a stack to keep track of whether a directory has properties or not.
48+
// We just never grab properties from the stack in case a directory doesn't have properties.
49+
if (logger.isDebugEnabled()) {
50+
logger.debug(format("Visiting directory: %s", dir.toFile().getAbsolutePath()));
51+
}
52+
File propertiesFile = new File(dir.toFile(), this.getPropertiesFilename());
53+
if (propertiesFile.exists()) {
54+
if (logger.isDebugEnabled()) {
55+
logger.debug(format("Loading properties from file: %s", propertiesFile.getAbsolutePath()));
56+
}
57+
this.loadProperties(propertiesFile);
5058
} else {
5159
if (cascadingEnabled && !propertiesStack.isEmpty()) {
60+
if (logger.isDebugEnabled()) {
61+
logger.debug("No properties file, and cascading is enabled, so using properties from top of stack.");
62+
}
5263
this.setProperties(propertiesStack.peek());
5364
} else {
65+
if (logger.isDebugEnabled()) {
66+
logger.debug("No properties file, or cascading is disabled, so using empty properties.");
67+
}
5468
this.setProperties(new Properties());
5569
}
5670
}
57-
if (cascadingEnabled) {
58-
propertiesStack.push(this.getProperties());
59-
}
71+
propertiesStack.push(this.getProperties());
6072
return FileVisitResult.CONTINUE;
6173
}
6274

6375
@Override
6476
public FileVisitResult postVisitDirectory(Path dir, IOException exc) {
65-
if (cascadingEnabled) {
66-
propertiesStack.pop();
67-
if (!propertiesStack.isEmpty()) {
68-
this.setProperties(propertiesStack.peek());
69-
}
77+
propertiesStack.pop();
78+
if (!propertiesStack.isEmpty()) {
79+
this.setProperties(propertiesStack.peek());
7080
}
7181
return FileVisitResult.CONTINUE;
7282
}

src/test/java/com/marklogic/client/ext/file/CascadeCollectionsAndPermissionsTest.java

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,32 @@ void setup() {
4242
void parentWithBothProperties() {
4343
loader.loadFiles("src/test/resources/process-files/cascading-metadata-test/parent1-withCP");
4444

45-
verifyCollections("/child1_1-noCP/test.json", PARENT_COLLECTION);
46-
verifyPermissions("/child1_1-noCP/test.json", "rest-writer", "update");
47-
48-
verifyCollections("/child1_2-withCP/test.json", CHILD_COLLECTION);
49-
verifyPermissions("/child1_2-withCP/test.json", "rest-reader", "read");
50-
51-
verifyCollections("/child3_1-withCP/grandchild3_1_1-noCP/test.json", CHILD_COLLECTION);
52-
verifyPermissions("/child3_1-withCP/grandchild3_1_1-noCP/test.json", "rest-reader", "read");
45+
verifyCollections("/parent.json", PARENT_COLLECTION);
46+
verifyPermissions("/parent.json", "rest-writer", "update");
5347

54-
verifyCollections("/child1/child1.json", "ParentCollection");
48+
// Should be same as parent as it doesn't have C/P files.
49+
verifyCollections("/child1/child1.json", PARENT_COLLECTION);
5550
verifyPermissions("/child1/child1.json", "rest-writer", "update");
5651

52+
// Differs from parent because it has its own C/P files.
5753
verifyCollections("/child2/child2.json", "child2");
5854
verifyPermissions("/child2/child2.json", "app-user", "read");
5955

60-
verifyCollections("/parent.json", "ParentCollection");
61-
verifyPermissions("/parent.json", "rest-writer", "update");
56+
// Differs from parent because it has its own C/P files.
57+
verifyCollections("/child3/child3.json", "child3");
58+
verifyPermissions("/child3/child3.json", "rest-reader", "read");
59+
60+
// Should inherit from child3, not parent.
61+
verifyCollections("/child3/grandchild3/grandchild3.json", "child3");
62+
verifyPermissions("/child3/grandchild3/grandchild3.json", "rest-reader", "read");
63+
64+
// Should inherit from parent.
65+
verifyCollections("/child4/child4.json", PARENT_COLLECTION);
66+
verifyPermissions("/child4/child4.json", "rest-writer", "update");
67+
68+
// Should override parent.
69+
verifyCollections("/child4/grandchild4/grandchild4.json", "grandchild4");
70+
verifyPermissions("/child4/grandchild4/grandchild4.json", "qconsole-user", "read");
6271
}
6372

6473
@Test
@@ -87,7 +96,32 @@ void cascadingDisabled() {
8796
loader = new GenericFileLoader(client);
8897

8998
loader.loadFiles("src/test/resources/process-files/cascading-metadata-test/parent1-withCP");
90-
verifyCollections("/child1_1-noCP/test.json");
91-
verifyPermissions("/child1_1-noCP/test.json");
99+
100+
verifyCollections("/parent.json", PARENT_COLLECTION);
101+
verifyPermissions("/parent.json", "rest-writer", "update");
102+
103+
// Has no C/P files.
104+
verifyCollections("/child1/child1.json");
105+
verifyPermissions("/child1/child1.json");
106+
107+
// Has C/P files.
108+
verifyCollections("/child2/child2.json", "child2");
109+
verifyPermissions("/child2/child2.json", "app-user", "read");
110+
111+
// Has C/P files.
112+
verifyCollections("/child3/child3.json", "child3");
113+
verifyPermissions("/child3/child3.json", "rest-reader", "read");
114+
115+
// Has no C/P files.
116+
verifyCollections("/child3/grandchild3/grandchild3.json");
117+
verifyPermissions("/child3/grandchild3/grandchild3.json");
118+
119+
// Has no C/P files.
120+
verifyCollections("/child4/child4.json");
121+
verifyPermissions("/child4/child4.json");
122+
123+
// Has C/P files.
124+
verifyCollections("/child4/grandchild4/grandchild4.json", "grandchild4");
125+
verifyPermissions("/child4/grandchild4/grandchild4.json", "qconsole-user", "read");
92126
}
93127
}

src/test/resources/logback.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
<appender-ref ref="STDOUT" />
2525
</logger>
2626

27-
<logger name="com.marklogic.client.modulesloader" level="INFO" additivity="false">
28-
<appender-ref ref="STDOUT" />
29-
</logger>
30-
3127
<logger name="org.springframework" level="WARN" additivity="false">
3228
<appender-ref ref="STDOUT" />
3329
</logger>

src/test/resources/process-files/cascading-metadata-test/parent1-withCP/child1_2-withCP/collections.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*=child3

src/test/resources/process-files/cascading-metadata-test/parent1-withCP/child3_1-withCP/collections.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/test/resources/process-files/cascading-metadata-test/parent1-withCP/child3_1-withCP/permissions.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)