Example #1
0
 @Override
 public GroupInfo apply(GroupResource resource)
     throws MethodNotAllowedException, ResourceNotFoundException, OrmException {
   AccountGroup group = resource.toAccountGroup();
   if (group == null) {
     throw new MethodNotAllowedException();
   }
   try {
     GroupControl c = controlFactory.validateFor(group.getOwnerGroupUUID());
     return json.format(c.getGroup());
   } catch (NoSuchGroupException e) {
     throw new ResourceNotFoundException();
   }
 }
Example #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;
  }