Skip to content

Commit 46618f4

Browse files
committed
fixed #318
1 parent 06dce8c commit 46618f4

File tree

1 file changed

+29
-8
lines changed
  • marklogic-data-hub/src/main/java/com/marklogic/hub

1 file changed

+29
-8
lines changed

marklogic-data-hub/src/main/java/com/marklogic/hub/DataHub.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@
6565
import com.marklogic.mgmt.databases.DatabaseManager;
6666
import com.marklogic.rest.util.Fragment;
6767
import com.marklogic.rest.util.ResourcesFragment;
68+
import org.springframework.core.io.Resource;
69+
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
70+
import org.springframework.core.io.support.ResourcePatternResolver;
6871
import org.springframework.web.client.ResourceAccessException;
6972

73+
import java.io.IOException;
7074
import java.nio.file.Paths;
7175
import java.util.ArrayList;
7276
import java.util.HashMap;
@@ -291,21 +295,38 @@ public void installUserModules() {
291295
* Removes user's modules from the modules db
292296
*/
293297
public void clearUserModules() {
298+
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(DataHub.class.getClassLoader());
294299
try {
295-
runInDatabase(
300+
ArrayList<String> options = new ArrayList<>();
301+
for (Resource r : resolver.getResources("classpath*:/ml-modules/options/*.xml")) {
302+
options.add(r.getFilename().replace(".xml", ""));
303+
}
304+
305+
ArrayList<String> services = new ArrayList<>();
306+
for (Resource r : resolver.getResources("classpath*:/ml-modules/services/*.xqy")) {
307+
services.add(r.getFilename().replaceAll("\\.(xqy|sjs)", ""));
308+
}
309+
310+
311+
ArrayList<String> transforms = new ArrayList<>();
312+
for (Resource r : resolver.getResources("classpath*:/ml-modules/transforms/*")) {
313+
transforms.add(r.getFilename().replaceAll("\\.(xqy|sjs)", ""));
314+
}
315+
316+
String query =
296317
"cts:uris((),(),cts:not-query(cts:collection-query('hub-core-module')))[\n" +
297318
" fn:not(\n" +
298-
" fn:ends-with(., \"options/spring-batch.xml\") or\n" +
299-
" fn:ends-with(., \"options/traces.xml\") or\n" +
300-
" fn:matches(., \"/marklogic.rest.resource/(collector|debug|entity|flow|tracing|validate|writer)/assets/(metadata\\.xml|resource\\.(xqy|sjs))\") or\n" +
301-
" fn:matches(., \"/marklogic.rest.transform/(get-content|run-flow|trace-json|trace-search)/assets/(metadata\\.xml|transform\\.(xqy|sjs))\")\n" +
319+
" fn:matches(., \"^.+options/(" + String.join("|", options) + ").xml$\") or\n" +
320+
" fn:matches(., \"/marklogic.rest.resource/(" + String.join("|", services) + ")/assets/(metadata\\.xml|resource\\.(xqy|sjs))\") or\n" +
321+
" fn:matches(., \"/marklogic.rest.transform/(" + String.join("|", transforms) + ")/assets/(metadata\\.xml|transform\\.(xqy|sjs))\")\n" +
302322
" )\n" +
303-
"] ! xdmp:document-delete(.)\n",
304-
hubConfig.modulesDbName
305-
);
323+
"] ! xdmp:document-delete(.)\n";
324+
runInDatabase(query, hubConfig.modulesDbName);
306325
}
307326
catch(FailedRequestException e) {
308327
logger.error("Failed to clear user modules");
328+
} catch (IOException e) {
329+
e.printStackTrace();
309330
}
310331
}
311332

0 commit comments

Comments
 (0)