@Test public void testCreate() throws RepositoryException { CreateGroupOperation createGroupOperation = new CreateGroupOperation(); PostResponse response = new JSONResponse(); context.currentResource("/home/users"); context.request().setParameterMap( ImmutableMap.<String, Object>builder().put(SlingPostConstants.RP_NODE_NAME, "test5").build()); createGroupOperation.run(context.request(), response, new SlingPostProcessor[] { Mockito.mock(SlingPostProcessor.class) }); assertNull(response.getError()); assertNotNull(group); assertEquals("/home/groups/tests", group.getPath()); }
@Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { String name = request.getParameter(SlingPostConstants.RP_NODE_NAME); ResourceResolver resolver = request.getResourceResolver(); UserManager userManager = CommonUtils.getUserManager(resolver); if (userManager.getAuthorizable(new SimplePrincipal(name)) != null) { throw new RepositoryException("Authorizable with id " + name + " already exists"); } String intermediatePath = StringUtils.substringBeforeLast(request.getResource().getPath(), "/") .replaceAll("\\/home\\/groups\\/?", ""); Group group = userManager.createGroup(name, new SimplePrincipal(name), intermediatePath); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.setPath(group.getPath()); response.onCreated(group.getPath()); } catch (Exception e) { log.warn("Failed to create group", e); response.setError(e); } }
CreateGroupOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { String name = request.getParameter(SlingPostConstants.RP_NODE_NAME); ResourceResolver resolver = request.getResourceResolver(); UserManager userManager = CommonUtils.getUserManager(resolver); if (userManager.getAuthorizable(new SimplePrincipal(name)) != null) { throw new RepositoryException("Authorizable with id " + name + " already exists"); } String intermediatePath = StringUtils.substringBeforeLast(request.getResource().getPath(), "/") .replaceAll("\\/home\\/groups\\/?", ""); Group group = userManager.createGroup(name, new SimplePrincipal(name), intermediatePath); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.setPath(group.getPath()); response.onCreated(group.getPath()); } catch (Exception e) { log.warn("Failed to create group", e); response.setError(e); } } }
CreateGroupOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { String name = request.getParameter(SlingPostConstants.RP_NODE_NAME); ResourceResolver resolver = request.getResourceResolver(); UserManager userManager = CommonUtils.getUserManager(resolver); if (userManager.getAuthorizable(new SimplePrincipal(name)) != null) { throw new RepositoryException("Authorizable with id " + name + " already exists"); } String intermediatePath = StringUtils.substringBeforeLast(request.getResource().getPath(), "/") .replaceAll("\\/home\\/groups\\/?", ""); Group group = userManager.createGroup(name, new SimplePrincipal(name), intermediatePath); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.setPath(group.getPath()); response.onCreated(group.getPath()); } catch (Exception e) { log.warn("Failed to create group", e); response.setError(e); } }  }
CreateGroupOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { String name = request.getParameter(SlingPostConstants.RP_NODE_NAME); ResourceResolver resolver = request.getResourceResolver(); UserManager userManager = CommonUtils.getUserManager(resolver); if (userManager.getAuthorizable(new SimplePrincipal(name)) != null) { throw new RepositoryException("Authorizable with id " + name + " already exists"); } String intermediatePath = StringUtils.substringBeforeLast(request.getResource().getPath(), "/") .replaceAll("\\/home\\/groups\\/?", ""); Group group = userManager.createGroup(name, new SimplePrincipal(name), intermediatePath); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.setPath(group.getPath()); response.onCreated(group.getPath()); } catch (Exception e) { log.warn("Failed to create group", e); response.setError(e); } }  @Override void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors); }
CreateGroupOperation implements PostOperation { @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) { final List<Modification> changes = new ArrayList<>(); try { String name = request.getParameter(SlingPostConstants.RP_NODE_NAME); ResourceResolver resolver = request.getResourceResolver(); UserManager userManager = CommonUtils.getUserManager(resolver); if (userManager.getAuthorizable(new SimplePrincipal(name)) != null) { throw new RepositoryException("Authorizable with id " + name + " already exists"); } String intermediatePath = StringUtils.substringBeforeLast(request.getResource().getPath(), "/") .replaceAll("\\/home\\/groups\\/?", ""); Group group = userManager.createGroup(name, new SimplePrincipal(name), intermediatePath); if (processors != null) { for (SlingPostProcessor processor : processors) { processor.process(request, changes); } } request.getResourceResolver().commit(); response.setPath(group.getPath()); response.onCreated(group.getPath()); } catch (Exception e) { log.warn("Failed to create group", e); response.setError(e); } }  @Override void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors);  }