/** * Executes the given task if the specified node exists in the specific repository, bootstraps the given resource otherwise. */ public BootstrapConditionally(String taskName, String taskDescription, String repositoryName, String pathToCheck, String resourceToBootstrap, Task ifNodeExists) { super(taskName, taskDescription, repositoryName, pathToCheck, ifNodeExists, new BootstrapSingleResource(taskName, taskDescription, resourceToBootstrap)); }
/** * {@inheritDoc} */ @Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { Session session = installContext.getJCRSession(RepositoryConstants.USER_GROUPS); try { session.getRootNode().getNode(group); } catch (PathNotFoundException e) { BootstrapSingleResource bsr = new BootstrapSingleResource("creating group " + group, "creating group " + group, bootstrapFile); bsr.execute(installContext); } } }
@Override protected void bootstrap(InstallContext installContext, int importUUIDBehavior) throws IOException, RepositoryException { if (subPath == null) { super.bootstrap(installContext, importUUIDBehavior); } else { final String[] resourcesToBootstrap = getResourcesToBootstrap(installContext); BootstrapUtil.bootstrap(resourcesToBootstrap[0], subPath, importUUIDBehavior); } }
/** * {@inheritDoc} */ @Override public void execute(InstallContext installContext) throws TaskExecutionException { boolean bootstrap = true; try { bootstrap = shouldBootstrap(installContext); } catch (RepositoryException e) { // ignore } if (bootstrap) { super.execute(installContext); } }
public ConfigureSTKAppGroupTask() { super("Bootstrap partial or entire STK app group configuration", "Bootstraps partial or entire STK app group configuration. Should the group not exist, bootstraps the entire config, else it is assumed that modules previously installed already created the group and possibly some of its subnodes and or properties. " + "The task will therefore only create the missing config, e.g. permissions, color. etc.", RepositoryConstants.CONFIG, APP_LAUNCHER_LAYOUT_GROUPS_STK, buildMissingConfigTask, new BootstrapSingleResource("", "", PATH_TO_BOOTSTRAP_FILE)); }
/** * {@inheritDoc} */ @Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { Session hm = installContext.getJCRSession(RepositoryConstants.USERS); try { hm.getNode(user); } catch (PathNotFoundException e) { BootstrapSingleResource bsr = new BootstrapSingleResource( "creating user " + user, "creating user " + user, bootstrapFile); bsr.execute(installContext); } } }
@Test public void simplesConstructorWorksAsExpected() throws Exception { // GIVEN final String resourceName = "/some-dir/test/foobar/somerepo.bleh.blih.xml"; final Task task = new BootstrapConditionally("taskName", resourceName); // WHEN (not ideal to use reflection but a lot more lightweight and unit-test-style than creating a repo-test case and let the task actually be executed in order to verify wanted behavior) final Field field = info.magnolia.module.delta.ConditionalDelegateTask.class.getDeclaredField("ifFalse"); field.setAccessible(true); final BootstrapSingleResource ifFalseTask = (BootstrapSingleResource) field.get(task); // THEN assertNotNull(ifFalseTask); final String resourceToBootstrap = ifFalseTask.getResourcesToBootstrap(null)[0]; assertEquals(resourceName, resourceToBootstrap); } }
protected List<Task> getCommonTasks() { final List<Task> commonTasks = new ArrayList<>(); commonTasks.add(new IsInstallSamplesTask("Re-Bootstrap website content for sample pages", "Re-bootstrap website content to account for all changes", new ArrayDelegateTask("", new BootstrapSingleResource("", "", "/mgnl-bootstrap-samples/samples/website.ftl-sample-site.xml"), new BootstrapSingleResource("", "", "/mgnl-bootstrap-samples/samples/dam.samples.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING)))); // We re-bootstrap twice because a simple (and single) re-bootstrap (using ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING) would NOT // "move" an existing site definition (which might actually exist from a previous version) in the site module commonTasks.add(new BootstrapSingleModuleResource("config.modules.samples.config.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING)); commonTasks.add(new BootstrapSingleModuleResource("config.modules.samples.config.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW)); return commonTasks; }
/** * {@inheritDoc} */ @Override protected void doExecute(InstallContext installContext) throws RepositoryException, TaskExecutionException { Session hm = installContext.getJCRSession(RepositoryConstants.USER_ROLES); try { hm.getNode(role); } catch (PathNotFoundException e) { BootstrapSingleResource bsr = new BootstrapSingleResource( "creating role " + role, "creating role " + role, bootstrapFile); bsr.execute(installContext); } } }
@Override protected List<Task> getExtraInstallTasks(InstallContext installContext) { List<Task> tasks = new ArrayList<Task>(); tasks.add(new RegisterWorkspaceForCacheFlushingTask("data")); tasks.add(new NodeExistsDelegateTask("Bootstrap data applauncher group if not existing", "/config.modules.ui-admincentral/config/appLauncherLayout/groups/data", null, new BootstrapSingleResource("", "", "/mgnl-bootstrap/ui-admincentral/config.modules.ui-admincentral.config.appLauncherLayout.groups.data.xml"))); tasks.add(new OrderNodeBeforeTask("Data AppLauncher group ordering", "Moves the data app group before tools group", RepositoryConstants.CONFIG, "/modules/ui-admincentral/config/appLauncherLayout/groups/data", "tools")); return tasks; }
@Override public void execute(InstallContext installContext) throws TaskExecutionException { if (SystemProperty.getBooleanProperty(SystemProperty.MAGNOLIA_BOOTSTRAP_SAMPLES)) { new BootstrapConditionally("Bootstrap templater role", "", "/mgnl-bootstrap-samples/inplace-templating/userroles.templater.xml").execute(installContext); User tim = Security.getUserManager().getUser("tim"); // check is the sample user with no modifications if (tim.getAllRoles().size() == 0 && tim.getAllGroups().size() == 0) { // overwrite tim as addRole does not work because tim has a reference to a role that does not exist new BootstrapSingleResource("Overwrite user Tim", "Tim will be overwritted with the right permissions.", "/mgnl-bootstrap-samples/inplace-templating/users.admin.tim.xml", ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING).execute(installContext); installContext.warn("User Tim has been overwritten."); } } }
@Override protected List<Task> getBasicInstallTasks(InstallContext installContext) { final List<Task> installTasks = new ArrayList<Task>(super.getBasicInstallTasks(installContext)); installTasks.add(new FilterOrderingTask("activation", new String[] { "context", "login", "multipartRequest" })); installTasks.add(new IsAuthorInstanceDelegateTask("", "", new BootstrapSingleResource("Bootstrap new activation configuration", "Bootstrap new activation configuration", "/info/magnolia/module/exchangesimple/setup/config.server.activation.xml"), createEmptyActivationConfig)); return installTasks; }
@Test public void bootstrapOfExistingNodesWillFailByDefault() throws Exception { // GIVEN final Session websiteSession = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); websiteSession.importXML(websiteSession.getRootNode().getPath(), getClass().getResourceAsStream("website.xml"), ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW); BootstrapSingleResource bootstrapSingleResource = new BootstrapSingleResource("", "", "/info/magnolia/module/delta/website.xml"); // WHEN // THEN assertThat(() -> bootstrapSingleResource.execute(installContext), throwsAnException(instanceOf(RuntimeException.class))); }
public MigrationTasks(String name, String description) { super(name, description, new ConfigureSTKAppGroupTask(), new ReplaceIfExistsTask("", "Replaces stkImageGallery component configuration.", "Did not find expected path /modules/standard-templating-kit/dialogs/components/features/stkImageGallery.", RepositoryConstants.CONFIG, "/modules/standard-templating-kit/dialogs/components/features/stkImageGallery", "/mgnl-bootstrap/standard-templating-kit/dialogs/components/features/config.modules.standard-templating-kit.dialogs.components.features.stkImageGallery.xml"), new ReplaceIfExistsTask("", "Replaces stkDownloadLink component configuration.", "Did not find expected path /modules/standard-templating-kit/dialogs/components/links/stkDownloadLink.", RepositoryConstants.CONFIG, "/modules/standard-templating-kit/dialogs/components/links/stkDownloadLink", "/mgnl-bootstrap/standard-templating-kit/dialogs/components/links/config.modules.standard-templating-kit.dialogs.components.links.stkDownloadLink.xml"), new ReplaceIfExistsTask("", "Replaces baseTeaserDownload component configuration.", "Did not find expected path /modules/standard-templating-kit/dialogs/generic/master/baseTeaserDownload.", RepositoryConstants.CONFIG, "/modules/standard-templating-kit/dialogs/generic/master/baseTeaserDownload", "/mgnl-bootstrap/standard-templating-kit/dialogs/generic/master/config.modules.standard-templating-kit.dialogs.generic.master.baseTeaserDownload.xml"), new NodeExistsDelegateTask("", "Bootstraps stkContact component if not existing.", RepositoryConstants.CONFIG, "/modules/standard-templating-kit/templates/components/content/stkContact", null, new BootstrapSingleResource("", "", "/info/magnolia/module/standard-templating-kit/setup/contacts/config.modules.standard-templating-kit.templates.components.content.stkContact.xml")), new NodeExistsDelegateTask("", "Makes stkContact component available under stk article area.", RepositoryConstants.CONFIG, "/modules/standard-templating-kit/templates/pages/stkArticle/areas/main/areas/content/availableComponents/stkContact", null, new BootstrapSingleResource("", "", "/info/magnolia/module/standard-templating-kit/setup/contacts/config.modules.standard-templating-kit.templates.pages.stkArticle.areas.main.areas.content.availableComponents.stkContact.xml")), new RemoveRepositoryPropertyTask()); }
@Test public void verifyPartialBootstrapping() throws Exception { // GIVEN BootstrapSingleResource bootstrapSingleResource = new BootstrapSingleResource("", "", "/config.firstLevelNode2.child3.xml", "/child3/subChild4"); Node node = NodeUtil.createPath(configSession.getRootNode(), "firstLevelNode2/child3", NodeTypes.ContentNode.NAME); node.setProperty("p", "toto"); // Bootstrap file has p=tutu, we want to make sure partial bootstrapping doesn't override it // WHEN bootstrapSingleResource.execute(installContext); // THEN assertThat("We want to make sure that partial bootstrapping doesn't override modified values", node, hasProperty("p", "toto")); assertThat(node, hasNode("subChild4")); assertThat(node.getNode("subChild4"), hasProperty("q", "tata")); }
/** * Bootstraps the given resource if the corresponding node does not exist yet, does nothing otherwise. */ public BootstrapConditionally(String taskName, String taskDescription, String resourceToBootstrap) { super(taskName, taskDescription, determineRepository(resourceToBootstrap), determinePath(resourceToBootstrap), null, new BootstrapSingleResource(taskName, taskDescription, resourceToBootstrap)); }
@Test public void bootstrapOfRegularResource() throws Exception { // GIVEN BootstrapSingleResource bootstrapSingleResource = new BootstrapSingleResource("", "", "/config.firstLevelNode2.child3.xml"); // WHEN bootstrapSingleResource.execute(installContext); // THEN assertThat(configSession.getRootNode(), hasNode("firstLevelNode2")); assertThat(configSession.getNode("/firstLevelNode2"), hasNode("child3")); assertThat(configSession.getNode("/firstLevelNode2/child3"), hasNode("subChild4")); }
/** * Bootstraps the given resource if the corresponding node does not exist yet, executes the given task otherwise. */ public BootstrapConditionally(String taskName, String taskDescription, String resourceToBootstrap, Task ifNodeExists) { super(taskName, taskDescription, determineRepository(resourceToBootstrap), determinePath(resourceToBootstrap), ifNodeExists, new BootstrapSingleResource(taskName, taskDescription, resourceToBootstrap)); }
public ReplaceIfExistsTask(String name, String description, String warningMessageIfNotExisting, String workspaceName, String pathToCheck, String bootstrapFile) { super(name, description, workspaceName, pathToCheck, new ArrayDelegateTask("", new RemoveNodeTask("", "", workspaceName, pathToCheck), new BootstrapSingleResource(name, description, bootstrapFile) ), new WarnTask(name, warningMessageIfNotExisting)); } }
public MigrateRenderingListenersTask() { super("Migrate rendering listeners.", new BootstrapSingleResource("Boostrap new rendering liteners configuration", "Boostrap new rendering liteners configuration", "/mgnl-bootstrap/rendering/config.server.rendering.engine.listeners.xml"),