/** * Method that find all subtemplates in templates node. */ private void findSubTemplates(Node node, InstallContext installContext) throws RepositoryException, TaskExecutionException { if (node.hasNode(SUBTEMPLATES)) { if (!node.hasNode(VARIATION)) { transformSubTemplatesToVariations(node, installContext); return; } final String warningMessage = String.format("Can't transform subtemplates of '%s' to variations, because variations already exist.", node.getPath()); new WarnTask("Transform subtemplates to variations", warningMessage).execute(installContext); return; } if (node.hasNodes()) { NodeIterator nodeIterator = node.getNodes(); while (nodeIterator.hasNext()) { findSubTemplates(nodeIterator.nextNode(), installContext); } } }
/** * Method that transform subtemplates to variations. */ private void transformSubTemplatesToVariations(Node node, InstallContext installContext) throws RepositoryException, TaskExecutionException { NodeIterator subTemplatesNodeIterator = node.getNode(SUBTEMPLATES).getNodes(); while (subTemplatesNodeIterator.hasNext()) { Node subTemplatesNode = subTemplatesNodeIterator.nextNode(); if (!subTemplatesNode.getName().equals("MetaData")) { if (subTemplatesNode.hasProperty("templatePath") && subTemplatesNode.hasProperty("type")) { PropertyUtil.renameProperty(subTemplatesNode.getProperty("templatePath"), "templateScript"); PropertyUtil.renameProperty(subTemplatesNode.getProperty("type"), "renderType"); if (subTemplatesNode.hasProperty("extension")) { NodeUtil.renameNode(subTemplatesNode, subTemplatesNode.getProperty("extension").getString()); subTemplatesNode.getProperty("extension").remove(); } } else { final String warningMessage = String.format("Subtemplate of '%s' has missing required property, can't transform this subtemplate properly. Please edit it in '%s/variations'.", subTemplatesNode.getName(), node.getPath()); new WarnTask("Transform subtemplates to variations", warningMessage).execute(installContext); } } } NodeUtil.renameNode(node.getNode(SUBTEMPLATES), VARIATION); } };
@Override public void execute(InstallContext context) throws TaskExecutionException { ModuleDefinition moduleDefinition = context.getCurrentModuleDefinition(); String defaultURI = StringUtils.isNotEmpty(moduleProperty) ? moduleDefinition.getProperty(moduleProperty) : moduleDefinition.getProperty(DEFAULT_PUBLIC_URI_PROPERTY); Task setPublicTask = new IsAdminInstanceDelegateTask("", "Set default virtual URI on public instances.", null, new NodeExistsDelegateTask(String.format("Set default virtual URI to old mapping path '%s'", OLD_DEFAULT_URI_MAPPING_PATH), OLD_DEFAULT_URI_MAPPING_PATH, new SetPropertyTask(RepositoryConstants.CONFIG, OLD_DEFAULT_URI_MAPPING_PATH, "toURI", defaultURI), new NodeExistsDelegateTask(String.format("Set default virtual URI to new mapping path '%s'", NEW_DEFAULT_URI_MAPPING_PATH), NEW_DEFAULT_URI_MAPPING_PATH, new SetPropertyTask(RepositoryConstants.CONFIG, NEW_DEFAULT_URI_MAPPING_PATH, "toUri", defaultURI), new WarnTask("Default URI", "Could not set defaultPublicURI, default mapping was not found.")))); setPublicTask.execute(context); } }
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)); } }
@Test public void testCheckModuleAndDeltasToStringForUpdate() { final ModuleDefinition mod = new ModuleDefinition("foo", Version.parseVersion("2.3.4"), null, null); final Delta d1 = DeltaBuilder.update("1.1", "New version").addTask(new WarnTask("t1", "test 1")).addTask(new WarnTask("t2", "test 2")); final Delta d2 = DeltaBuilder.update("2.0", "New version 2").addTask(new WarnTask("t3", "test 3")).addTask(new WarnTask("t3", "test 4")); ModuleManager.ModuleAndDeltas mad = new ModuleManager.ModuleAndDeltas(mod, Version.parseVersion("1.0"), Arrays.asList(d1, d2)); assertEquals("ModuleAndDeltas for foo: current version is 1.0.0, updating to 2.3.4 with 2 deltas.", mad.toString()); }
tasks.add(new WarnTask("SMTP Configuration", "Please set the config: /modules/mail/config/smtp to a valid smtp configuration")); tasks.add(new IsModuleInstalledOrRegistered("Use of commenting module", "Use of commenting module by default in STK", "commenting", new CheckAndModifyPropertyValueTask("", "", RepositoryConstants.CONFIG, "/modules/standard-templating-kit/config/site/templates/prototype/areas/main/areas/comments/availableComponents/stkComments", "id", "standard-templating-kit:components/features/stkComments", "commenting:components/comments"))); new ArrayDelegateTask("", "", new NodeExistsDelegateTask("Check for default site", "Check whether default site already exists or not - if no, site from stk will be copied to multisite", RepositoryConstants.CONFIG, "/modules/multisite/config/sites/default", new WarnTask("Default already site exists", "Default site already exists. No actions will be taken."), new ArrayDelegateTask("", "", new CreateNodePathTask("", "/modules/multisite/config/sites/", NodeTypes.ContentNode.NAME),
public MigrateValidationSelectFieldToTwinColSelectFieldTask(String name, String[] fields) { super(name); for (String field : fields) { addTask(new NodeExistsDelegateTask(String.format("Migrate 'validation' field '%s' to multi select field.", field), field, new ArrayDelegateTask("", new RemovePropertyTask(String.format("Remove property 'buttonLabel' for validation field in '%s'", field), field, "buttonLabel"), new RemovePropertyTask(String.format("Remove property 'type' for validation field in '%s'", field), field, "type"), new ValueOfPropertyDelegateTask("", field, "class", "info.magnolia.ui.form.field.definition.SelectFieldDefinition", false, new SetPropertyTask(RepositoryConstants.CONFIG, field, "class", "info.magnolia.ui.form.field.definition.TwinColSelectFieldDefinition")), new SetPropertyTask(RepositoryConstants.CONFIG, field, "leftColumnCaption", "dialog.form.edit.tabMain.validation.leftColumnCaption"), new SetPropertyTask(RepositoryConstants.CONFIG, field, "rightColumnCaption", "dialog.form.edit.tabMain.validation.rightColumnCaption") ), new WarnTask("Unable to migrate validation field", String.format(WARNING_MESSAGE_FORMAT, field))) ); } }
private Task addBypassToResourcesServlet() { return new ArrayDelegateTask("Add delegateResourceVoter to ResourcesServlet.", new NodeExistsDelegateTask("", "/server/filters/servlets/ResourcesServlet", new NodeExistsDelegateTask("", "/server/filters/servlets/ResourcesServlet/bypasses", new WarnTask("", "DelegateResourceVoter couldn't be installed since there is already a bypass defined for ResourcesServlet."), new ArrayDelegateTask("", new CreateNodeTask("", "/server/filters/servlets/ResourcesServlet", "bypasses", NodeTypes.ContentNode.NAME), new CreateNodeTask("", "/server/filters/servlets/ResourcesServlet/bypasses", "bypassWhenNotInResourceFilter", NodeTypes.ContentNode.NAME), new NewPropertyTask("", "/server/filters/servlets/ResourcesServlet/bypasses/bypassWhenNotInResourceFilter", "class", "info.magnolia.module.resources.DelegateResourceVoter"), new NewPropertyTask("", "/server/filters/servlets/ResourcesServlet/bypasses/bypassWhenNotInResourceFilter", "not", true))))); }
@Test public void testCheckModuleAndDeltasToStringForInstall() { final ModuleDefinition mod = new ModuleDefinition("foo", Version.parseVersion("2.3.4"), null, null); final Delta d1 = DeltaBuilder.update("1.1", "New version").addTask(new WarnTask("t1", "test 1")).addTask(new WarnTask("t2", "test 2")); ModuleManager.ModuleAndDeltas mad = new ModuleManager.ModuleAndDeltas(mod, null, Arrays.asList(d1)); assertEquals("ModuleAndDeltas for foo: installing version 2.3.4 with 1 deltas.", mad.toString()); }
@Test public void testDescriptionForUpdatesOnly() { final ModuleManager.ModuleManagementState state = new ModuleManager.ModuleManagementState(); state.addModule(new ModuleDefinition("a", v10, null, null), v01, Arrays.<Delta>asList( DeltaBuilder.update(v10, "").addTask(new WarnTask("", "")), DeltaBuilder.update(v05, "").addTask(new WarnTask("", "")) )); state.addModule(new ModuleDefinition("b", v10, null, null), v01, Arrays.<Delta>asList( DeltaBuilder.update(v10, "").addTask(new WarnTask("", "")), DeltaBuilder.update(v05, "").addTask(new WarnTask("", "")) )); assertEquals(1, state.getDeltaTypes().size()); assertTrue(state.getDeltaTypes().contains(DeltaType.update)); assertEquals("updates only", state.getDeltaTypesDescription(TEXTS)); }
private void doTestTemplate(String templateName) throws ModuleManagementException { final WebContext context = mock(WebContext.class); when(context.getLocale()).thenReturn(Locale.ENGLISH); when(context.getContextPath()).thenReturn("/bibabu"); MgnlContext.setInstance(context); final ModuleDefinition mod1 = new ModuleDefinition("foo", Version.parseVersion("1.0"), null, null); final ModuleDefinition mod2 = new ModuleDefinition("bar", Version.parseVersion("2.0"), null, null); final InstallContextImpl ctx = new InstallContextImpl(new ModuleRegistryImpl()); ctx.setCurrentModule(mod1); ctx.info("trala"); ctx.info("trululu"); ctx.warn("boo !"); ctx.setCurrentModule(mod2); ctx.error("hoolala", new Exception("booh-ooh!")); final ModuleManager moduleManager = mock(ModuleManager.class); final ModuleManager.ModuleManagementState state = new ModuleManager.ModuleManagementState(); state.getList().add(new ModuleManager.ModuleAndDeltas(mod1, null, Arrays.<Delta>asList( DeltaBuilder.install(Version.parseVersion("1.0"), "") .addTask(new WarnTask("a", "")) .addTask(new WarnTask("b", "")) ))); state.getList().add(new ModuleManager.ModuleAndDeltas(mod2, null, Arrays.<Delta>asList( DeltaBuilder.update("1.0", "").addTask(new WarnTask("q", "")), DeltaBuilder.update("1.1", "").addTask(new WarnTask("w", "")) ))); when(moduleManager.getStatus()).thenReturn(state); when(moduleManager.getInstallContext()).thenReturn(ctx); final StringWriter out = new StringWriter(); new ModuleManagerWebUI(moduleManager).render(templateName, out); }
@Test public void testDescriptionForInstallsOnly() { final ModuleManager.ModuleManagementState state = new ModuleManager.ModuleManagementState(); state.addModule(new ModuleDefinition("a", v10, null, null), null, Arrays.<Delta>asList( DeltaBuilder.install(v10, "").addTask(new WarnTask("", "")) )); state.addModule(new ModuleDefinition("b", v10, null, null), null, Arrays.<Delta>asList( DeltaBuilder.install(v10, "").addTask(new WarnTask("", "")) )); assertEquals(1, state.getDeltaTypes().size()); assertTrue(state.getDeltaTypes().contains(DeltaType.install)); assertEquals("installs only", state.getDeltaTypesDescription(TEXTS)); }
@Test public void testDescriptionForInstallsAndUpdates() { final ModuleManager.ModuleManagementState state = new ModuleManager.ModuleManagementState(); state.addModule(new ModuleDefinition("a", v10, null, null), v01, Arrays.<Delta>asList( DeltaBuilder.update(v10, "").addTask(new WarnTask("", "")), DeltaBuilder.update(v05, "").addTask(new WarnTask("", "")) )); state.addModule(new ModuleDefinition("b", v10, null, null), null, Arrays.<Delta>asList( DeltaBuilder.install(v10, "").addTask(new WarnTask("", "")) )); assertEquals(2, state.getDeltaTypes().size()); assertTrue(state.getDeltaTypes().contains(DeltaType.install)); assertTrue(state.getDeltaTypes().contains(DeltaType.update)); assertEquals("installs and updates", state.getDeltaTypesDescription(TEXTS)); } }
new WarnTask("defaultBaseUrl property", "Please set the config:/server/defaultBaseUrl property to a full URL to be used when generating absolute URLs for external systems.") ),
new PropertyValueDelegateTask("", "/modules/mail/config/smtp/", MailConstants.SMTP_PASSWORD, "", false, new RemovePropertyTask("", "/modules/mail/config/smtp/", MailConstants.SMTP_PASSWORD), new WarnTask("", "We suggest to move your plain text SMTP password from {config:/modules/mail/config/smtp/smtpPassword} to password manager app and then link it via the mail app") )), new RemovePropertyTask("", "/modules/mail/config/smtp/", "smtpAuthentication"),
.addTask(new BootstrapSingleModuleResource("JSON", "Add JSON mime-type", "config.server.MIMEMapping.xml", "/MIMEMapping/json"))); register((DeltaBuilder.update("5.1", "")) .addTask(new WarnTask("respectOrderDocument parameter", "As of Magnolia 5.1, the respectOrderDocument parameter has been reintroduced in repo config files and set to true by default. You will need to set it manually for each workspace in your installation. Please, refer to the release notes for more details.")) .addTask(new RemoveNodeTask("Remove intercept filter", "Removes no longer used intercept filter.", RepositoryConstants.CONFIG, "/server/filters/cms/intercept"))); register((DeltaBuilder.update("5.1.1", "")) .addTask(new NodeExistsDelegateTask("Order csrfSecurity Filter", "Put csrfSecurity before uriSecurity Filter.", RepositoryConstants.CONFIG, "/server/filters/uriSecurity", new OrderNodeBeforeTask("Order csrfSecurity Filter", "Put csrfSecurity before uriSecurity Filter.", RepositoryConstants.CONFIG, "/server/filters/csrfSecurity", "uriSecurity"), new WarnTask("CSRF Security Filter is inactive.", "CSRF Security Filter inactive. The installed csrfFilter would normally be ordered before the uriSecurity filter, but could not be moved there as a uriFilter node does not exist in the /server/filters node. The installed csrfFilter must be moved up the filters list manually."))) .addTask(new NodeExistsDelegateTask("Add csrfSecurity Filter", "/server/auditLogging/logConfigurations/security", null, new PartialBootstrapTask("Add 'security' AuditLogging logConfiguration.", "", "/mgnl-bootstrap/core/config.server.auditLogging.xml", "/auditLogging/logConfigurations/security", ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW)))); new NodeExistsDelegateTask("", "/server/filters/login", new OrderNodeBeforeTask("Order csrfTokenSecurity Filter", "Put csrfTokenSecurity before login filter.", RepositoryConstants.CONFIG, "/server/filters/csrfTokenSecurity", "login"), new WarnTask("CSRF Token Security Filter is inactive.", "CSRF Token Security Filter inactive. The installed csrfTokenSecurity filter must be moved up in the filters list and enabled manually."))))) .addTask(new RemoveMIMEIconsTask("Find and remove all legacy 'icon' properties", "", RepositoryConstants.CONFIG, "/server/MIMEMapping")) .addTask(new BootstrapSingleModuleResource("Add WOFF2 MIME type", "", "config.server.MIMEMapping.xml", "/MIMEMapping/woff2"))
.addTask(new WarnTask(String.format("Roles '%s' and '%s' aren't used anymore.", DefaultForumManager.ROLE_FORUM_BASE, DefaultForumManager.ROLE_FORUM_MODERATOR_BASE), String.format("The roles '%s and '%s' aren't used anymore in the forum module. Check your users and groups; you may want to remove theses roles from users and groups and delete them.", DefaultForumManager.ROLE_FORUM_BASE, DefaultForumManager.ROLE_FORUM_MODERATOR_BASE)))