0

I wrote a java program to create a Group inside AEM. It is working fine. But along with Group I also need to create another Group aboutMe property.

My code:

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
UserManager userManager = ((JackrabbitSession) session).getUserManager();
JackrabbitSession js = (JackrabbitSession) session;
Group group = null;
group = userManager.createGroup("TestGroup");
session.save();

Is there any way to add aboutMe property field also?

Neuron
  • 5,141
  • 5
  • 38
  • 59
Hanin Jazi
  • 1
  • 2
  • 4

1 Answers1

0

You could do group.setProperty("jcr:description","your string") or for that matter any property. Refer to javadocs here

Update

Add dependency to your project pom for com.adobe.granite.security.user

Inject

  @Reference
  private UserPropertiesService service;

Get UserProperties Object (resource is the resource instance to your Group) -

if (this.service != null) {
        Authorizable authorizable = (Authorizable)resource.adaptTo(Authorizable.class);
        UserProperties userProperties;
        if (authorizable == null)
        {
          UserProperties userProperties = (UserProperties)resource.adaptTo(UserProperties.class);
          if (userProperties != null) {
            UserManager uMgr = (UserManager)resolver.adaptTo(UserManager.class);
            authorizable = uMgr.getAuthorizable(userProperties.getAuthorizableID());
          }

        }
        else
        {
          Session session = ((Node)resource.adaptTo(Node.class)).getSession();
          UserPropertiesManager mgr = this.service.createUserPropertiesManager(session, resolver);
          String propPath = request.getParameter("path");
          userProperties = mgr.getUserProperties(authorizable, propPath);
        }

Once you get the UserProperties, you can add the aboutMe information to your group.

For further reference, read this and the javadocs here

Ameesh Trikha
  • 1,652
  • 2
  • 12
  • 18