GenerateFunctionMetadataCommand extends AbstractCommand { @Override public void execute(CommandContext context) { if (isCompatibleWithES || (versions != null && versions.isVersionCompatibleWithES())) { if (modulesClient == null) { if (hubConfig == null) { throw new IllegalStateException("Unable to create a DatabaseClient for the modules database because hubConfig is null"); } modulesClient = hubConfig.newStagingClient(hubConfig.getDbName(DatabaseKind.MODULES)); } DataMovementManager dataMovementManager = modulesClient.newDataMovementManager(); StructuredQueryBuilder sb = modulesClient.newQueryManager().newStructuredQueryBuilder(); ServerTransform serverTransform = new ServerTransform("mlGenerateFunctionMetadata"); ApplyTransformListener transformListener = new ApplyTransformListener() .withTransform(serverTransform) .withApplyResult(ApplyTransformListener.ApplyResult.IGNORE) .onFailure((batch, throwable) -> { logger.error(throwable.getMessage()); if (caughtException == null) { caughtException = throwable; } }); QueryBatcher queryBatcher = dataMovementManager.newQueryBatcher( new StructuredQueryBuilder().or(sb.directory(true, "/data-hub/5/mapping-functions/"), sb.directory(true, "/custom-modules/mapping-functions/"))) .withBatchSize(1) .withThreadCount(4) .onUrisReady(transformListener); dataMovementManager.startJob(queryBatcher); try { queryBatcher.awaitCompletion(2L, TimeUnit.MINUTES); } catch (InterruptedException e) { logger.error("Loading function metadata timed out, took longer than 2 minutes"); } dataMovementManager.stopJob(queryBatcher); if (caughtException != null) { throw new RuntimeException(caughtException); } } else { logger.warn("GenerateFunctionMetadataCommand is not supported on this MarkLogic server version "); } } GenerateFunctionMetadataCommand();  GenerateFunctionMetadataCommand(HubConfig hubConfig, boolean isCompatibleWithES);  GenerateFunctionMetadataCommand(DatabaseClient modulesClient, Versions versions); @Override void execute(CommandContext context);  }
@Test public void testMetaDataGeneration() { if (versions.isVersionCompatibleWithES()) { CommandContext context = new CommandContext(hubConfig.getAppConfig(), hubConfig.getManageClient(), hubConfig.getAdminManager()); generateFunctionMetadataCommand.execute(context); String uri = "/custom-modules/mapping-functions/testModule.xml.xslt"; DocumentMetadataHandle metadata = new DocumentMetadataHandle(); BytesHandle handle = modMgr.read(uri, metadata, new BytesHandle()); Assertions.assertNotEquals(0, handle.get().length); DocumentMetadataHandle.DocumentPermissions permissions = metadata.getPermissions(); Assertions.assertTrue(permissions.get("data-hub-operator").contains(READ)); Assertions.assertTrue(permissions.get("data-hub-operator").contains(EXECUTE)); Assertions.assertTrue(permissions.get("data-hub-developer").contains(UPDATE)); } }