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

Commit 17ec400

Browse files
committed
#210 Can now customize the FileFilter for loading schemas
1 parent 34d4f3c commit 17ec400

File tree

7 files changed

+90
-46
lines changed

7 files changed

+90
-46
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
33
version=3.1.0
4-
mlJavaclientUtilVersion=3.1.0
4+
mlJavaclientUtilVersion=77
55
mlJunitVersion=3.1.0
66

src/main/java/com/marklogic/appdeployer/AppConfig.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public class AppConfig {
142142
private String modulePermissions = "rest-admin,read,rest-admin,update,rest-extension-user,execute";
143143

144144
private FileFilter assetFileFilter;
145+
private FileFilter schemasFileFilter;
145146

146147
// Additional module extensions that should be loaded as binaries into the modules database
147148
private String[] additionalBinaryExtensions;
@@ -588,7 +589,15 @@ public void setAssetFileFilter(FileFilter assetFileFilter) {
588589
this.assetFileFilter = assetFileFilter;
589590
}
590591

591-
public String getFlexrepPath() {
592+
public FileFilter getSchemasFileFilter() {
593+
return schemasFileFilter;
594+
}
595+
596+
public void setSchemasFileFilter(FileFilter schemasFileFilter) {
597+
this.schemasFileFilter = schemasFileFilter;
598+
}
599+
600+
public String getFlexrepPath() {
592601
return flexrepPath;
593602
}
594603

src/main/java/com/marklogic/appdeployer/command/schemas/LoadSchemasCommand.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
import com.marklogic.appdeployer.command.SortOrderConstants;
77
import com.marklogic.client.DatabaseClient;
88
import com.marklogic.client.FailedRequestException;
9+
import com.marklogic.client.ext.schemasloader.SchemasLoader;
910
import com.marklogic.client.ext.schemasloader.impl.DefaultSchemasLoader;
1011

12+
import java.io.FileFilter;
13+
1114
public class LoadSchemasCommand extends AbstractCommand {
1215

1316
public LoadSchemasCommand() {
@@ -22,7 +25,7 @@ public void execute(CommandContext context) {
2225
protected void loadSchemasIntoSchemasDatabase(CommandContext context) {
2326
AppConfig config = context.getAppConfig();
2427
DatabaseClient client = config.newSchemasDatabaseClient();
25-
DefaultSchemasLoader schemasLoader = new DefaultSchemasLoader(client);
28+
SchemasLoader schemasLoader = buildSchemasLoader(context, client);
2629
try {
2730
String schemasPath = config.getSchemasPath();
2831
logger.info("Loading schemas from path: " + schemasPath);
@@ -39,4 +42,21 @@ protected void loadSchemasIntoSchemasDatabase(CommandContext context) {
3942
client.release();
4043
}
4144
}
45+
46+
/**
47+
* Will utilize schemasFileFilter in AppConfig if it's been set.
48+
*
49+
* @param context
50+
* @param client
51+
* @return
52+
*/
53+
protected SchemasLoader buildSchemasLoader(CommandContext context, DatabaseClient client) {
54+
AppConfig config = context.getAppConfig();
55+
DefaultSchemasLoader schemasLoader = new DefaultSchemasLoader(client);
56+
FileFilter filter = config.getSchemasFileFilter();
57+
if (filter != null) {
58+
schemasLoader.addFileFilter(filter);
59+
}
60+
return schemasLoader;
61+
}
4262
}

src/test/java/com/marklogic/appdeployer/command/modules/LoadModulesTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.marklogic.appdeployer.AbstractAppDeployerTest;
44
import com.marklogic.appdeployer.command.restapis.DeployRestApiServersCommand;
5-
import com.marklogic.client.ext.modulesloader.impl.AssetFileFilter;
5+
import com.marklogic.client.ext.modulesloader.impl.DefaultFileFilter;
66
import com.marklogic.junit.Fragment;
77
import com.marklogic.junit.PermissionsFragment;
88
import com.marklogic.xcc.template.XccTemplate;
@@ -139,8 +139,8 @@ public void testServerExists() {
139139

140140
appDeployer.deploy(appConfig);
141141

142-
String[] uris = new String[] { "/Default/sample-app/rest-api/options/sample-app-options.xml",
143-
"/Default/sample-app/rest-api/options/sample-app-options.xml" };
142+
String[] uris = new String[]{"/Default/sample-app/rest-api/options/sample-app-options.xml",
143+
"/Default/sample-app/rest-api/options/sample-app-options.xml"};
144144
for (String uri : uris) {
145145
assertEquals("true", xccTemplate.executeAdhocQuery(format("doc-available('%s')", uri)));
146146
}
@@ -166,7 +166,7 @@ private void assertModuleExistsWithDefaultPermissions(String message, String uri
166166

167167
/**
168168
* Apparently, the REST API won't let you remove these 3 default permissions, they're always present.
169-
*
169+
* <p>
170170
* And, now that we're loading modules via the REST API by default, rest-reader/read and rest-writer/update are
171171
* always present, at least on 8.0-6.3 and 9.0-1.1, which seems like a bug.
172172
*/
@@ -184,7 +184,7 @@ private void assertDefaultPermissionsExists(String uri) {
184184

185185
}
186186

187-
class TestFileFilter extends AssetFileFilter {
187+
class TestFileFilter extends DefaultFileFilter {
188188

189189
@Override
190190
public boolean accept(File f) {
Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,77 @@
11
package com.marklogic.appdeployer.command.schemas;
22

3-
import org.junit.After;
4-
import org.junit.Test;
5-
63
import com.marklogic.appdeployer.AbstractAppDeployerTest;
74
import com.marklogic.appdeployer.command.Command;
85
import com.marklogic.appdeployer.command.databases.DeployContentDatabasesCommand;
96
import com.marklogic.appdeployer.command.databases.DeploySchemasDatabaseCommand;
107
import com.marklogic.appdeployer.command.databases.DeployTriggersDatabaseCommand;
11-
import com.marklogic.appdeployer.command.restapis.DeployRestApiServersCommand;
128
import com.marklogic.client.DatabaseClient;
139
import com.marklogic.client.document.GenericDocumentManager;
1410
import com.marklogic.client.io.DocumentMetadataHandle;
11+
import org.junit.After;
12+
import org.junit.Test;
13+
14+
import java.io.File;
15+
import java.io.FileFilter;
1516

1617
public class LoadSchemasTest extends AbstractAppDeployerTest {
1718

18-
@Test
19-
public void testSchemaLoading() {
20-
initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(),
21-
new DeployContentDatabasesCommand(1), new DeployRestApiServersCommand(), newCommand());
22-
appDeployer.deploy(appConfig);
19+
@Test
20+
public void testSchemaLoading() {
21+
initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(),
22+
new DeployContentDatabasesCommand(1), newCommand());
23+
appDeployer.deploy(appConfig);
24+
25+
DatabaseClient client = appConfig.newSchemasDatabaseClient();
2326

24-
DatabaseClient client = appConfig.newSchemasDatabaseClient();
27+
GenericDocumentManager docMgr = client.newDocumentManager();
2528

26-
GenericDocumentManager docMgr = client.newDocumentManager();
29+
assertNull("Rules document loaded", docMgr.exists("notExists"));
30+
assertNotNull("Rules document loaded", docMgr.exists("/my.rules").getUri());
31+
assertNotNull("XSD document loaded", docMgr.exists("/x.xsd").getUri());
32+
assertNull(docMgr.exists("/.do-not-load"));
33+
assertNull(docMgr.exists(".do-not-load"));
34+
}
2735

28-
assertNull("Rules document loaded", docMgr.exists("notExists"));
29-
assertNotNull("Rules document loaded", docMgr.exists("/my.rules").getUri());
30-
assertNotNull("XSD document loaded", docMgr.exists("/x.xsd").getUri());
31-
}
36+
@Test
37+
public void testCustomSchemasPathWithCustomFileFilter() {
38+
initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(),
39+
new DeployContentDatabasesCommand(1), newCommand());
3240

33-
@Test
34-
public void testSchemaCustomSchemasPath() {
35-
initializeAppDeployer(new DeploySchemasDatabaseCommand(), new DeployTriggersDatabaseCommand(),
36-
new DeployContentDatabasesCommand(1), new DeployRestApiServersCommand(), newCommand());
37-
appConfig.setSchemasPath("src/test/resources/schemas-marklogic9");
38-
appDeployer.deploy(appConfig);
41+
appConfig.setSchemasPath("src/test/resources/schemas-marklogic9");
42+
appConfig.setSchemasFileFilter(new CustomFileFilter());
43+
appDeployer.deploy(appConfig);
3944

40-
DatabaseClient client = appConfig.newSchemasDatabaseClient();
45+
DatabaseClient client = appConfig.newSchemasDatabaseClient();
4146

42-
GenericDocumentManager docMgr = client.newDocumentManager();
47+
GenericDocumentManager docMgr = client.newDocumentManager();
4348

44-
assertNotNull("TDEXML document loaded", docMgr.exists("/x.tdex").getUri());
45-
assertNotNull("TDEJSON document loaded", docMgr.exists("/x.tdej").getUri());
49+
assertNotNull("TDEXML document loaded", docMgr.exists("/x.tdex").getUri());
50+
assertNotNull("TDEJSON document loaded", docMgr.exists("/x.tdej").getUri());
51+
assertNull(docMgr.exists("/to-be-ignored/test.xml"));
52+
assertNull(docMgr.exists("to-be-ignored/test.xml"));
4653

47-
for (String uri : new String[] { "/x.tdex", "/x.tdej" }) {
48-
DocumentMetadataHandle h = docMgr.readMetadata(uri, new DocumentMetadataHandle());
49-
assertEquals("Files ending in tdex and tdej go into a special collection", "http://marklogic.com/xdmp/tde",
50-
h.getCollections().iterator().next());
51-
}
52-
}
54+
for (String uri : new String[]{"/x.tdex", "/x.tdej"}) {
55+
DocumentMetadataHandle h = docMgr.readMetadata(uri, new DocumentMetadataHandle());
56+
assertEquals("Files ending in tdex and tdej go into a special collection", "http://marklogic.com/xdmp/tde",
57+
h.getCollections().iterator().next());
58+
}
59+
}
5360

54-
@After
55-
public void cleanup() {
56-
undeploySampleApp();
57-
}
61+
@After
62+
public void cleanup() {
63+
undeploySampleApp();
64+
}
5865

59-
private Command newCommand() {
60-
return new LoadSchemasCommand();
61-
}
66+
private Command newCommand() {
67+
return new LoadSchemasCommand();
68+
}
69+
70+
}
6271

72+
class CustomFileFilter implements FileFilter {
73+
@Override
74+
public boolean accept(File pathname) {
75+
return !(pathname.isDirectory() && "to-be-ignored".equals(pathname.getName()));
76+
}
6377
}

src/test/resources/sample-app/src/main/ml-schemas/.do-not-load

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<test/>

0 commit comments

Comments
 (0)