@Test public void testFromJson_nodeTypeFilters() throws Exception { final File targetFile = new File(testOutDir, "testFromJson_nodeTypeFilters.json"); if (targetFile.exists()) { targetFile.delete(); } final String fooMixin1 = "foo:mixin1"; final String fooMixin2 = "foo:mixin2"; final List<JcrNs> nsList = Collections.singletonList(JcrNs.create("foo", "http: OakMachine.Builder oak = TestUtil.fromPlan(obj() .key("jcrNamespaces", nsList) .key("jcrNodetypes", obj() .key("foo:folder", key("extends", arr("nt:folder"))) .key(fooMixin1, key("@", arr("mixin"))) .key(fooMixin2, key("@", arr("mixin")))) .key("forcedRoots", arr() .val(new ForcedRoot().withPath("/foo1").withPrimaryType("nt:folder").withMixinTypes("mix:title", fooMixin1)) .val(new ForcedRoot().withPath("/foo2").withPrimaryType("nt:unstructured").withMixinTypes(fooMixin1)) ) .get()); WebsterChecklistTarget target = WebsterChecklistTarget.fromJson(targetFile, obj() .key("jcrNamespaces", nsList) .key("selectors", arr() .val(key("type", "nodetype").key("args", arr("mix:title"))) .val(key("type", "query").key("args", arr("select * from [nt:unstructured] as nun where issamenode([nun], '/foo2')")))) .key("nodeTypeFilters", arr() .val(new Rule(RuleType.INCLUDE, Pattern.compile("foo:mixin.*")))) .key("exportNodeTypes", arr(fooMixin2)) .get()); oak.build().adminInitAndInspect(target::perform); assertJsonFile(targetFile, json -> { final Checklist checklist = Checklist.fromJson("testFromJson", null, json); assertEquals("expect 2 roots", 2, checklist.getForcedRoots().size()); assertEquals("expect root path", "/foo1", checklist.getForcedRoots().get(0).getPath()); assertNull("expect no primary type", checklist.getForcedRoots().get(0).getPrimaryType()); assertEquals("expect mixins", Collections.singletonList(fooMixin1), checklist.getForcedRoots().get(0).getMixinTypes()); assertEquals("expect root path", "/foo2", checklist.getForcedRoots().get(1).getPath()); assertNull("expect no primary type", checklist.getForcedRoots().get(1).getPrimaryType()); assertEquals("expect mixins", Collections.singletonList(fooMixin1), checklist.getForcedRoots().get(1).getMixinTypes()); assertEquals("two types were exported", 2, checklist.getJcrNodetypes().size()); final NamePathResolver resolver = new DefaultNamePathResolver(JsonCnd.toNamespaceMapping(nsList)); assertEquals("foo:mixin1 node type was exported", uncheck1(resolver::getQName).apply(fooMixin1), checklist.getJcrNodetypes().get(0).getName()); assertEquals("foo:mixin2 node type was exported", uncheck1(resolver::getQName).apply(fooMixin2), checklist.getJcrNodetypes().get(1).getName()); }); }
static WebsterChecklistTarget fromJson(final File target, final JsonObject config) { LOGGER.debug("[fromJson] fromJson: {}", config.toString()); ChecklistExporter.Builder exporter = new ChecklistExporter.Builder(); WebsterChecklistTarget.selectorsFromConfigCompactForm(config) .forEach(selector -> selector.selectOnExporter(exporter)); if (config.containsKey(KEY_SELECTORS)) { JsonArray ops = config.getJsonArray(KEY_SELECTORS); List<Selector> selectors = JavaxJson.mapArrayOfObjects(ops, WebsterChecklistTarget::selectorFromJson); selectors.forEach(selector -> selector.selectOnExporter(exporter)); } if (config.containsKey(KEY_SCOPE_PATHS)) { List<Rule> scopePaths = Rules.fromJsonArray(config.getJsonArray(KEY_SCOPE_PATHS)); exporter.withScopePaths(scopePaths); } if (config.containsKey(KEY_NODE_TYPE_FILTERS)) { List<Rule> nodeTypeFilters = Rules.fromJsonArray(config.getJsonArray(KEY_NODE_TYPE_FILTERS)); exporter.withNodeTypeFilters(nodeTypeFilters); } if (config.containsKey(KEY_JCR_NAMESPACES)) { List<JcrNs> jcrNsList = JavaxJson.mapArrayOfObjects(config.getJsonArray(KEY_JCR_NAMESPACES), JcrNs::fromJson); exporter.withJcrNamespaces(jcrNsList); } if (config.containsKey(KEY_EXPORT_NODETYPES)) { List<String> ntList = JavaxJson.mapArrayOfStrings(config.getJsonArray(KEY_EXPORT_NODETYPES)); exporter.withExportNodeTypes(ntList); } ChecklistExporter.ForcedRootUpdatePolicy updatePolicy = null; if (config.containsKey(KEY_UPDATE_POLICY)) { updatePolicy = ChecklistExporter.ForcedRootUpdatePolicy.byName(config.getString(KEY_UPDATE_POLICY)); } return new WebsterChecklistTarget(target, exporter.build(), updatePolicy); }
WebsterChecklistTarget implements WebsterTarget { static WebsterChecklistTarget fromJson(final File target, final JsonObject config) { LOGGER.debug("[fromJson] fromJson: {}", config.toString()); ChecklistExporter.Builder exporter = new ChecklistExporter.Builder(); WebsterChecklistTarget.selectorsFromConfigCompactForm(config) .forEach(selector -> selector.selectOnExporter(exporter)); if (config.containsKey(KEY_SELECTORS)) { JsonArray ops = config.getJsonArray(KEY_SELECTORS); List<Selector> selectors = JavaxJson.mapArrayOfObjects(ops, WebsterChecklistTarget::selectorFromJson); selectors.forEach(selector -> selector.selectOnExporter(exporter)); } if (config.containsKey(KEY_SCOPE_PATHS)) { List<Rule> scopePaths = Rules.fromJsonArray(config.getJsonArray(KEY_SCOPE_PATHS)); exporter.withScopePaths(scopePaths); } if (config.containsKey(KEY_NODE_TYPE_FILTERS)) { List<Rule> nodeTypeFilters = Rules.fromJsonArray(config.getJsonArray(KEY_NODE_TYPE_FILTERS)); exporter.withNodeTypeFilters(nodeTypeFilters); } if (config.containsKey(KEY_JCR_NAMESPACES)) { List<JcrNs> jcrNsList = JavaxJson.mapArrayOfObjects(config.getJsonArray(KEY_JCR_NAMESPACES), JcrNs::fromJson); exporter.withJcrNamespaces(jcrNsList); } if (config.containsKey(KEY_EXPORT_NODETYPES)) { List<String> ntList = JavaxJson.mapArrayOfStrings(config.getJsonArray(KEY_EXPORT_NODETYPES)); exporter.withExportNodeTypes(ntList); } ChecklistExporter.ForcedRootUpdatePolicy updatePolicy = null; if (config.containsKey(KEY_UPDATE_POLICY)) { updatePolicy = ChecklistExporter.ForcedRootUpdatePolicy.byName(config.getString(KEY_UPDATE_POLICY)); } return new WebsterChecklistTarget(target, exporter.build(), updatePolicy); } }
WebsterChecklistTarget implements WebsterTarget { static WebsterChecklistTarget fromJson(final File target, final JsonObject config) { LOGGER.debug("[fromJson] fromJson: {}", config.toString()); ChecklistExporter.Builder exporter = new ChecklistExporter.Builder(); WebsterChecklistTarget.selectorsFromConfigCompactForm(config) .forEach(selector -> selector.selectOnExporter(exporter)); if (config.containsKey(KEY_SELECTORS)) { JsonArray ops = config.getJsonArray(KEY_SELECTORS); List<Selector> selectors = JavaxJson.mapArrayOfObjects(ops, WebsterChecklistTarget::selectorFromJson); selectors.forEach(selector -> selector.selectOnExporter(exporter)); } if (config.containsKey(KEY_SCOPE_PATHS)) { List<Rule> scopePaths = Rules.fromJsonArray(config.getJsonArray(KEY_SCOPE_PATHS)); exporter.withScopePaths(scopePaths); } if (config.containsKey(KEY_NODE_TYPE_FILTERS)) { List<Rule> nodeTypeFilters = Rules.fromJsonArray(config.getJsonArray(KEY_NODE_TYPE_FILTERS)); exporter.withNodeTypeFilters(nodeTypeFilters); } if (config.containsKey(KEY_JCR_NAMESPACES)) { List<JcrNs> jcrNsList = JavaxJson.mapArrayOfObjects(config.getJsonArray(KEY_JCR_NAMESPACES), JcrNs::fromJson); exporter.withJcrNamespaces(jcrNsList); } if (config.containsKey(KEY_EXPORT_NODETYPES)) { List<String> ntList = JavaxJson.mapArrayOfStrings(config.getJsonArray(KEY_EXPORT_NODETYPES)); exporter.withExportNodeTypes(ntList); } ChecklistExporter.ForcedRootUpdatePolicy updatePolicy = null; if (config.containsKey(KEY_UPDATE_POLICY)) { updatePolicy = ChecklistExporter.ForcedRootUpdatePolicy.byName(config.getString(KEY_UPDATE_POLICY)); } return new WebsterChecklistTarget(target, exporter.build(), updatePolicy); } private  WebsterChecklistTarget(final File checklist,
                                   final ChecklistExporter exporter,
                                   final ChecklistExporter.ForcedRootUpdatePolicy updatePolicy); }
WebsterChecklistTarget implements WebsterTarget { static WebsterChecklistTarget fromJson(final File target, final JsonObject config) { LOGGER.debug("[fromJson] fromJson: {}", config.toString()); ChecklistExporter.Builder exporter = new ChecklistExporter.Builder(); WebsterChecklistTarget.selectorsFromConfigCompactForm(config) .forEach(selector -> selector.selectOnExporter(exporter)); if (config.containsKey(KEY_SELECTORS)) { JsonArray ops = config.getJsonArray(KEY_SELECTORS); List<Selector> selectors = JavaxJson.mapArrayOfObjects(ops, WebsterChecklistTarget::selectorFromJson); selectors.forEach(selector -> selector.selectOnExporter(exporter)); } if (config.containsKey(KEY_SCOPE_PATHS)) { List<Rule> scopePaths = Rules.fromJsonArray(config.getJsonArray(KEY_SCOPE_PATHS)); exporter.withScopePaths(scopePaths); } if (config.containsKey(KEY_NODE_TYPE_FILTERS)) { List<Rule> nodeTypeFilters = Rules.fromJsonArray(config.getJsonArray(KEY_NODE_TYPE_FILTERS)); exporter.withNodeTypeFilters(nodeTypeFilters); } if (config.containsKey(KEY_JCR_NAMESPACES)) { List<JcrNs> jcrNsList = JavaxJson.mapArrayOfObjects(config.getJsonArray(KEY_JCR_NAMESPACES), JcrNs::fromJson); exporter.withJcrNamespaces(jcrNsList); } if (config.containsKey(KEY_EXPORT_NODETYPES)) { List<String> ntList = JavaxJson.mapArrayOfStrings(config.getJsonArray(KEY_EXPORT_NODETYPES)); exporter.withExportNodeTypes(ntList); } ChecklistExporter.ForcedRootUpdatePolicy updatePolicy = null; if (config.containsKey(KEY_UPDATE_POLICY)) { updatePolicy = ChecklistExporter.ForcedRootUpdatePolicy.byName(config.getString(KEY_UPDATE_POLICY)); } return new WebsterChecklistTarget(target, exporter.build(), updatePolicy); } private  WebsterChecklistTarget(final File checklist,
                                   final ChecklistExporter exporter,
                                   final ChecklistExporter.ForcedRootUpdatePolicy updatePolicy); @Override void perform(final Session session); }
WebsterChecklistTarget implements WebsterTarget { static WebsterChecklistTarget fromJson(final File target, final JsonObject config) { LOGGER.debug("[fromJson] fromJson: {}", config.toString()); ChecklistExporter.Builder exporter = new ChecklistExporter.Builder(); WebsterChecklistTarget.selectorsFromConfigCompactForm(config) .forEach(selector -> selector.selectOnExporter(exporter)); if (config.containsKey(KEY_SELECTORS)) { JsonArray ops = config.getJsonArray(KEY_SELECTORS); List<Selector> selectors = JavaxJson.mapArrayOfObjects(ops, WebsterChecklistTarget::selectorFromJson); selectors.forEach(selector -> selector.selectOnExporter(exporter)); } if (config.containsKey(KEY_SCOPE_PATHS)) { List<Rule> scopePaths = Rules.fromJsonArray(config.getJsonArray(KEY_SCOPE_PATHS)); exporter.withScopePaths(scopePaths); } if (config.containsKey(KEY_NODE_TYPE_FILTERS)) { List<Rule> nodeTypeFilters = Rules.fromJsonArray(config.getJsonArray(KEY_NODE_TYPE_FILTERS)); exporter.withNodeTypeFilters(nodeTypeFilters); } if (config.containsKey(KEY_JCR_NAMESPACES)) { List<JcrNs> jcrNsList = JavaxJson.mapArrayOfObjects(config.getJsonArray(KEY_JCR_NAMESPACES), JcrNs::fromJson); exporter.withJcrNamespaces(jcrNsList); } if (config.containsKey(KEY_EXPORT_NODETYPES)) { List<String> ntList = JavaxJson.mapArrayOfStrings(config.getJsonArray(KEY_EXPORT_NODETYPES)); exporter.withExportNodeTypes(ntList); } ChecklistExporter.ForcedRootUpdatePolicy updatePolicy = null; if (config.containsKey(KEY_UPDATE_POLICY)) { updatePolicy = ChecklistExporter.ForcedRootUpdatePolicy.byName(config.getString(KEY_UPDATE_POLICY)); } return new WebsterChecklistTarget(target, exporter.build(), updatePolicy); } private  WebsterChecklistTarget(final File checklist,
                                   final ChecklistExporter exporter,
                                   final ChecklistExporter.ForcedRootUpdatePolicy updatePolicy); @Override void perform(final Session session);  }