@Override protected List<Task> getBasicInstallTasks(InstallContext ctx) { final List<Task> tasks = new ArrayList<>(); tasks.addAll(GenericTasks.genericTasksForNewInstallation()); tasks.add(auditTrailManagerTask); tasks.add(bootstrapWebContainerResources); tasks.add(new BootstrapConditionally("Security", "Bootstraps security-base role.", "/mgnl-bootstrap/core/userroles.security-base.xml")); // always hash passwords. Task will not re-hash so it is safe to run this op at any time, multiple times. tasks.add(new HashUsersPasswords()); tasks.add(bootstrapChannelManagement); tasks.add(bootstrapChannelFilter); tasks.add(placeChannelBeforeLogout); return tasks; }
private static String determineRepository(String filename) { return StringUtils.substringBefore(cleanupFilename(filename), "."); }
/** * Bootstraps the given resource if the corresponding node does not exist yet, does nothing otherwise. * Task description gets auto-generated. */ public BootstrapConditionally(String taskName, String resourceToBootstrap) { super(taskName, String.format("Bootstraps file '%s' into '%s:%s' if the path doesn't exist yet.", resourceToBootstrap, determineRepository(resourceToBootstrap), determinePath(resourceToBootstrap)), determineRepository(resourceToBootstrap), determinePath(resourceToBootstrap), null, new BootstrapSingleResource(taskName, String.format("Bootstraps file '%s' into '%s:%s'.", resourceToBootstrap, determineRepository(resourceToBootstrap), determinePath(resourceToBootstrap)), resourceToBootstrap)); }
@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."); } } }
private void doTest(String resourceToBootstrap, boolean shouldBootstrap, boolean shouldExecuteDelegateTask) throws Exception { final MockSession session = SessionTestUtil.createSession("somerepo", SOME_PROPERTY); final InstallContext ctx = createStrictMock(InstallContext.class); final Task delegateTask = createStrictMock(Task.class); expect(ctx.getJCRSession("somerepo")).andReturn(session); if (shouldExecuteDelegateTask) { delegateTask.execute(ctx); } replay(ctx, delegateTask); final BootstrapConditionally task = new BootstrapConditionally("test", "test", resourceToBootstrap, delegateTask); try { task.execute(ctx); // TODO : ugly hack until BootstrapUtil is refactored / mockable / testable } catch (TaskExecutionException e) { if (shouldBootstrap) { assertEquals("Could not bootstrap: Can't find resource to bootstrap at /some-dir/test/foobar/somerepo.bleh.blih.xml", e.getMessage()); } else { fail("Failed! NullPointerException: " + e.getMessage() + " : " + ExceptionUtils.getStackTrace(e)); } } verify(ctx, delegateTask); }
@Override protected List<Task> getExtraInstallTasks(InstallContext installContext) { final List<Task> tasks = new ArrayList<Task>(); tasks.add(new BootstrapConditionally("Observation listeners", "Installs observation listeners by keeping already existing ones, possibly provided by other modules.", "/mgnl-bootstrap/listenerConfigs/config.modules.observation.config.xml", new ArrayDelegateTask("", new PartialBootstrapTask("", "", "/mgnl-bootstrap/listenerConfigs/config.modules.observation.config.xml", "/config/listenerConfigurations/sendMailOnPageChanges"), new PartialBootstrapTask("", "", "/mgnl-bootstrap/listenerConfigs/config.modules.observation.config.xml", "/config/listenerConfigurations/activateAddedPages")))); tasks.add(usePublicationCommand); return tasks; } }
/** * 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)); }
private static String determinePath(String filename) { String withoutExtensionAndRepository = StringUtils.substringAfter(cleanupFilename(filename), "."); String path = StringUtils.replace(withoutExtensionAndRepository, ".", "/"); return (StringUtils.isEmpty(path) ? "/" : "/" + path); }
@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); } }
/** * 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)); }
@Test public void autoGeneratedDescription() throws Exception { // GIVEN Task task; // WHEN task = new BootstrapConditionally("taskName", "/some-dir/test/foobar/somerepo.bleh.blih.xml"); // THEN assertEquals("Bootstraps file '/some-dir/test/foobar/somerepo.bleh.blih.xml' into 'somerepo:/bleh/blih' if the path doesn't exist yet.", task.getDescription()); }
new BootstrapConditionally("", "Author permissions", "/info/magnolia/setup/author/userroles.anonymous.xml"), new BootstrapConditionally("", "Public permissions", "/info/magnolia/setup/public/userroles.anonymous.xml")), new BootstrapConditionally("Superuser role", "Bootstraps the superuser role if needed.", "/mgnl-bootstrap/core/userroles.superuser.xml"), new BootstrapConditionally("Anonymous user", "Anonymous user must exist in the system realm: will move the existing one or bootstrap it.", RepositoryConstants.USERS, "/anonymous", "/mgnl-bootstrap/core/users.system.anonymous.xml", new ArrayDelegateTask("", )), new BootstrapConditionally("Superuser user", "Superuser user must exist in the system realm: will move the existing one or bootstrap it.", RepositoryConstants.USERS, "/superuser", "/mgnl-bootstrap/core/users.system.superuser.xml", new MoveNodeTask("", "", RepositoryConstants.USERS, "/superuser", "/system/superuser", false)),
.addTask(new BootstrapSingleResource("Sample using wirtual uri", "Adds a sample", "/mgnl-bootstrap-samples/samples/website.products-freemarker.xml")) .addTask(new BootstrapConditionally("Samples developers", "Adds developers group if does not exist", "/mgnl-bootstrap-samples/samples/usergroups.developers.xml")) .addTask(new BootstrapConditionally("Samples employees", "Adds employees group if does not exist", "/mgnl-bootstrap-samples/samples/usergroups.employees.xml")) .addTask(new BootstrapConditionally("Samples editor", "Adds editor role if does not exist", "/mgnl-bootstrap-samples/samples/userroles.editor.xml")) .addTask(new BootstrapConditionally("Samples user", "Adds user if does not exist", "/mgnl-bootstrap-samples/samples/users.admin.david.xml")) .addTask(new BootstrapConditionally("Samples user", "Adds user if does not exist", "/mgnl-bootstrap-samples/samples/users.admin.eve.xml")) .addTask(new BootstrapConditionally("Samples user", "Adds user if does not exist", "/mgnl-bootstrap-samples/samples/users.admin.patrick.xml")) .addTask(new RemoveNodeTask("Remove menu items", "Removes the samples menu config item sample templates.",
public SiteModuleVersionHandler() { register(DeltaBuilder.update("1.0.1", "") .addTask(updateI18nContentSupport)); register(DeltaBuilder.update("1.0.3", "") .addTask(new NodeExistsDelegateTask("Create empty site definition node if it does not exist", "/modules/site/config/site", null, new BootstrapSingleModuleResource("config.modules.site.config.site.xml")))); register(DeltaBuilder.update("1.0.5", "") .addTask(new BootstrapConditionally("Add site-aware JSP renderer if it does not exist", "/mgnl-bootstrap/site/config.modules.site.renderers.site-jsp.xml")) .addTask(new PropertyValueDelegateTask("Reconfigure site renderer to delegate to freemarker renderer", "/modules/site/renderers/site", "class", SiteAwareFreemarkerRenderer.class.getName(), true, new ArrayDelegateTask("", new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/site/renderers/site", "wrappedRendererType", "freemarker"), new SetPropertyTask(RepositoryConstants.CONFIG, "/modules/site/renderers/site", "class", SiteAwareRendererWrapper.class.getName()), new RemoveNodeTask("", "/modules/site/renderers/site/contextAttributes"), new RemovePropertyTask("", "/modules/site/renderers/site/", "type")))) .addTask(orderSiteMergeFilter) //fix incorrect order of siteMerge filter after update from M5.3 which is before multiSite filter ); register(DeltaBuilder.update("1.1", "") .addTask(new NodeExistsDelegateTask("Remove themes folder if empty", "Location /modules/site/config/themes is deprecated but still supported", RepositoryConstants.CONFIG, "/modules/site/config/themes", new RemoveNodeWithoutChildren("/modules/site/config/themes")))); }
.addTask(new BootstrapConditionally("Register resource loader", "Allow registration of resource loaders under config/resourceLoaders node.", "/mgnl-bootstrap/resources/config/config.modules.resources.config.resourceLoaders.xml"))); register(DeltaBuilder.update("1.5.8", "") .addTask(new BootstrapSingleResource("Config", "Commands configuration", "/mgnl-bootstrap/resources/commands/config.modules.resources.commands.xml")));
.addTask(new BootstrapConditionally("Bootstrap 'formStaticField'", "Bootstrap 'formStaticField' into 'ui-framework/fieldTypes'.", "/mgnl-bootstrap/form/config.modules.ui-framework.fieldTypes.formStaticField.yaml")) .addTask(rebootstrapBrokenDialogsTask));
.addTask(new PartialBootstrapTask("Rebootstrap 'metadataStandard'", "Rebootstrap 'config:modules/dam/assets/subApps/detail/editor/form/tabs/asset/fields/metadataStandard'.", "/mgnl-bootstrap/dam-app-1-x/config.modules.dam.apps.assets.xml", "/assets/subApps/detail/editor/form/tabs/asset/fields/metadataStandard")) .addTask(new BootstrapConditionally("Bootstrap ZIP archive import action field types", "", "/mgnl-bootstrap/dam-app-1-x/config.modules.dam.fieldTypes.xml")) .addTask(new PartialBootstrapTask("Bootstrap restore version action", "", "/mgnl-bootstrap/dam-app-1-x/config.modules.dam.apps.assets.xml", "/assets/subApps/browser/actions/restoreVersion")) .addTask(new NodeExistsDelegateTask("Bootstrap restore version action to actionbar", "", RepositoryConstants.CONFIG, "/modules/dam/apps/assets/subApps/browser/actionbar/sections/asset/groups/versionsActions/items",