Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.sling.jackrabbit.usermanager.impl.post;
 
 import java.util.List;
 import java.util.Map;
 
 

Sling Post Operation implementation for updating a group in the jackrabbit UserManager.

Rest Service Description

Updates a group's properties. Maps on to nodes of resourceType sling/groups like /rep:system/rep:userManager/rep:groups/ae/3f/ed/testGroup mapped to a resource url /system/userManager/group/testGroup. This servlet responds at /system/userManager/group/testGroup.update.html

Methods

  • POST

Post Parameters

*
Any additional parameters become properties of the group node (optional)
*@Delete
The property is deleted, eg prop1@Delete

Response

200
Success, a redirect is sent to the group's resource locator. The redirect comes with HTML describing the status.
404
The resource was not found
500
Failure

Example

curl -Fprop1=value2 -Fproperty1=value1 http://localhost:8080/system/userManager/group/testGroup.update.html

Scr.component:
metatype="no" immediate="true"
Scr.service:
interface="javax.servlet.Servlet"
Scr.property:
name="sling.servlet.resourceTypes" values="sling/group"
Scr.property:
name="sling.servlet.methods" value="POST"
Scr.property:
name="sling.servlet.selectors" value="update"
 
 public class UpdateGroupServlet extends AbstractGroupPostServlet {
     private static final long serialVersionUID = -8292054361992488797L;
 
     /*
      * (non-Javadoc)
      * @see
      * org.apache.sling.jackrabbit.usermanager.post.AbstractAuthorizablePostServlet
      * #handleOperation(org.apache.sling.api.SlingHttpServletRequest,
      * org.apache.sling.api.servlets.HtmlResponse, java.util.List)
      */
     @Override
     protected void handleOperation(SlingHttpServletRequest request,
             HtmlResponse htmlResponseList<Modificationchanges)
             throws RepositoryException {
         Authorizable authorizable = null;
         Resource resource = request.getResource();
         if (resource != null) {
             authorizable = resource.adaptTo(Authorizable.class);
         }
 
         // check that the group was located.
         if (authorizable == null) {
            throw new ResourceNotFoundException(
                "Group to update could not be determined");
        }
        Session session = request.getResourceResolver().adaptTo(Session.class);
        if (session == null) {
            throw new RepositoryException("JCR Session not found");
        }
        Map<StringRequestPropertyreqProperties = collectContent(request,
            htmlResponse);
        try {
            // cleanup any old content (@Delete parameters)
            processDeletes(authorizablereqPropertieschanges);
            // write content from form
            writeContent(sessionauthorizablereqPropertieschanges);
            // update the group memberships
            if (authorizable.isGroup()) {
                updateGroupMembership(requestauthorizablechanges);
            }
        } catch (RepositoryException re) {
            throw new RepositoryException("Failed to update group."re);
        }
    }
New to GrepCode? Check out our FAQ X