Пример #1
0
 public GroupInfo format(GroupDescription.Basic group) throws OrmException {
   GroupInfo info = init(group);
   if (options.contains(MEMBERS) || options.contains(INCLUDES)) {
     GroupResource rsrc = new GroupResource(groupControlFactory.controlFor(group));
     initMembersAndIncludes(rsrc, info);
   }
   return info;
 }
Пример #2
0
  @Override
  public List<GroupInfo> apply(GroupResource rsrc) throws MethodNotAllowedException, OrmException {
    if (rsrc.toAccountGroup() == null) {
      throw new MethodNotAllowedException();
    }

    boolean ownerOfParent = rsrc.getControl().isOwner();
    List<GroupInfo> included = Lists.newArrayList();
    for (AccountGroupById u :
        dbProvider.get().accountGroupById().byGroup(rsrc.toAccountGroup().getId())) {
      try {
        GroupControl i = controlFactory.controlFor(u.getIncludeUUID());
        if (ownerOfParent || i.isVisible()) {
          included.add(json.format(i.getGroup()));
        }
      } catch (NoSuchGroupException notFound) {
        log.warn(
            String.format(
                "Group %s no longer available, included into %s",
                u.getIncludeUUID(), rsrc.getGroup().getName()));
        continue;
      }
    }
    Collections.sort(
        included,
        new Comparator<GroupInfo>() {
          @Override
          public int compare(GroupInfo a, GroupInfo b) {
            int cmp = nullToEmpty(a.name).compareTo(nullToEmpty(b.name));
            if (cmp != 0) {
              return cmp;
            }
            return nullToEmpty(a.id).compareTo(nullToEmpty(b.id));
          }
        });
    return included;
  }