如何以编程方式在AEM中创建组描述[关于Field或aboutMe属性]?

时间:2016-09-23 06:10:47

标签: java servlets aem sling

我写了一个java程序来在AEM中创建一个Group。它工作正常。但与Group一起,我还需要创建另一个组aboutMe属性。

我的代码:

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();

有没有办法添加aboutMe属性字段?

1 个答案:

答案 0 :(得分:0)

您可以group.setProperty("jcr:description","your string")或任何财产。请参阅javadocs here

<强>更新

com.adobe.granite.security.user

的项目pom添加依赖项

注入

  @Reference
  private UserPropertiesService service;

获取UserProperties对象(资源是您的组的资源实例) -

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);
        }

获得UserProperties后,您可以将aboutMe信息添加到您的论坛。

如需进一步参考,请阅读this和javadocs here