/** * {@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); } }
/** * {@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); } } }
/** * {@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); } } }
/** * {@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 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."); } } }
@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))); }
@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")); }
@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")); }