test_class.declarator: context = new SlingContext()
test_class.modifier: @Rule
      public
test_class.original_string: @Rule
      public SlingContext context = new SlingContext();
test_class.type: SlingContext
test_class.var_name: context
test_class.declarator: added
test_class.modifier: private
test_class.original_string: private ArrayList<String> added;
test_class.type: ArrayList<String>
test_class.var_name: added
test_class.declarator: removed
test_class.modifier: private
test_class.original_string: private ArrayList<String> removed;
test_class.type: ArrayList<String>
test_class.var_name: removed
test_class.file: core/src/test/java/org/apache/sling/cms/core/internal/operations/MembershipOperationTest.java
test_class.identifier: MembershipOperationTest
test_case.body: @Test
      public void testInvalidPath() throws RepositoryException {
          MembershipOperation membersOperation = new MembershipOperation();
          PostResponse response = new JSONResponse();
  
          context.currentResource("/content");
          context.request().setParameterMap(ImmutableMap.<String, Object>builder()
                  .put(":members", new String[] { "/home/groups/sling-cms/authors" }).build());
  
          membersOperation.run(context.request(), response, null);
  
          assertNotNull(response.getError());
      }
test_case.class_method_signature: MembershipOperationTest.testInvalidPath()
test_case.full_signature: @Test public void testInvalidPath()
test_case.identifier: testInvalidPath
test_case.invocations: currentResource setParameterMap request build put builder run request assertNotNull getError
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testInvalidPath()
focal_class.declarator: log = LoggerFactory.getLogger(MembershipOperation.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(MembershipOperation.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: PN_MEMBERSHIP = ":membership"
focal_class.modifier: public static final
focal_class.original_string: public static final String PN_MEMBERSHIP = ":membership";
focal_class.type: String
focal_class.var_name: PN_MEMBERSHIP
focal_class.file: core/src/main/java/org/apache/sling/cms/core/internal/operations/MembershipOperation.java
focal_class.identifier: MembershipOperation
focal_class.interfaces: implements PostOperation
focal_class.class_method_signature: MembershipOperation.run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_class.full_signature: @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_class.identifier: run
focal_class.modifiers: @Override public
focal_class.parameters: (SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_class.return: void
focal_class.signature: void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_method.body: @Override
      public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors) {
          final List<Modification> changes = new ArrayList<>();
          try {
  
              List<String> groups = new ArrayList<>();
              Optional.ofNullable(request.getParameterValues(PN_MEMBERSHIP))
                      .ifPresent(p -> groups.addAll(Arrays.asList(p)));
  
              AuthorizableWrapper authWrapper = request.getResource().adaptTo(AuthorizableWrapper.class);
  
              Authorizable auth = authWrapper.getAuthorizable();
              response.setPath(auth.getPath());
              changes.add(Modification.onModified(auth.getPath()));
  
              auth.declaredMemberOf().forEachRemaining(group -> {
                  try {
                      if (!groups.contains(group.getPath())) {
                          log.debug("Removing member {} from {}", auth, group);
                          group.removeMember(auth);
                          changes.add(Modification.onModified(group.getPath()));
                      } else {
                          groups.remove(group.getPath());
                      }
                  } catch (RepositoryException e) {
                      log.warn("Failed to remove members", e);
                  }
              });
  
              for (String path : groups) {
                  Resource resource = request.getResourceResolver().getResource(path);
                  if (resource == null) {
                      throw new RepositoryException("Failed to resolve authorizable at " + path);
                  }
                  Group group = (Group) resource.adaptTo(AuthorizableWrapper.class).getAuthorizable();
                  group.addMember(auth);
                  changes.add(Modification.onModified(group.getPath()));
                  log.debug("Adding member {} to {}", auth, group);
              }
  
              // invoke processors
              if (processors != null) {
                  for (SlingPostProcessor processor : processors) {
                      processor.process(request, changes);
                  }
              }
  
              request.getResourceResolver().commit();
  
              response.onModified(auth.getPath());
          } catch (Exception e) {
              log.warn("Failed to update membership", e);
              response.setError(e);
          }
      }
focal_method.class_method_signature: MembershipOperation.run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_method.full_signature: @Override public void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_method.identifier: run
focal_method.invocations: ifPresent ofNullable getParameterValues addAll asList adaptTo getResource getAuthorizable setPath getPath add onModified getPath forEachRemaining declaredMemberOf contains getPath debug removeMember add onModified getPath remove getPath warn getResource getResourceResolver getAuthorizable adaptTo addMember add onModified getPath debug process commit getResourceResolver onModified getPath warn setError
focal_method.modifiers: @Override public
focal_method.parameters: (SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)
focal_method.return: void
focal_method.signature: void run(SlingHttpServletRequest request, PostResponse response, SlingPostProcessor[] processors)