//populate a list with all the sites List < Group > groups = GroupLocalServiceUtil.getGroups(-1, -1);
for (group in groups) { //fetch the groupId long groupId = group.getGroupId();
//we need to use the LayoutSet's create date to find out when the site was created as there's no create date for groups LayoutSet sitePublicLayoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, false); Date siteCreationDate = sitePublicLayoutSet.getCreateDate();
//get the name of the site String name = group.getGroupKey();
//get the users that belong to the site List < User > groupUsers = UserLocalServiceUtil.getGroupUsers(groupId);
//we only need those sites to which users are added (although the creator user will always be added) and when the group is really a site. if (groupUsers.size() > 0) { if (group.isSite()) { out.println("This site is called " + name + " and was created on: " + siteCreationDate + "\n"); out.println("users added to this site can be found below:") }
for (groupUser in groupUsers) { String screenName = groupUser.getScreenName(); out.println(screenName); }