public void testGroupType() {

    GroupType adminType = GroupType.createType(GrouperSession.staticGrouperSession(), "adminType");
    groupA.addType(adminType);

    correctAttributesA.setAttribute("groupType", adminType, GroupTypeFinder.find("base", true));

    runResolveTest("testAttributesOnly", groupA, correctAttributesA);
  }
Example #2
0
 /**
  * Add an <code>Attribute</code> to a <code>GroupType</code>.
  *
  * <p>
  *
  * @param i BeanShell interpreter.
  * @param stack BeanShell call stack.
  * @param type Add to this <code>GroupType</code>.
  * @param name Name of <code>Attribute</code>.
  * @param read <code>Privilege</code> required for reading.
  * @param write <code>Privilege</code> required for writing.
  * @param req Is <code>Attribute</code> required.
  * @return <code>Field</code>
  * @throws GrouperShellException
  * @since 0.1.0
  */
 public static Field invoke(
     Interpreter i,
     CallStack stack,
     String type,
     String name,
     Privilege read,
     Privilege write,
     boolean req)
     throws GrouperShellException {
   GrouperShell.setOurCommand(i, true);
   try {
     GrouperSession s = GrouperShell.getSession(i);
     GroupType t = GroupTypeFinder.find(type);
     return t.addAttribute(s, name, read, write, req);
   } catch (InsufficientPrivilegeException eIP) {
     GrouperShell.error(i, eIP);
   } catch (SchemaException eS) {
     GrouperShell.error(i, eS);
   }
   throw new GrouperShellException(E.TYPE_ADDATTR + name);
 } // public static Field invoke(i, stack, type, name, read, write, req)
  /* (non-Javadoc)
   * @see edu.internet2.middleware.grouper.ui.RepositoryBrowser#advancedSearch(edu.internet2.middleware.grouper.GrouperSession, java.lang.String, java.util.Map, java.util.List)
   */
  public List advancedSearch(GrouperSession s, String from, Map attr, List outTerms)
      throws Exception {
    List res = new ArrayList();
    String maxCountStr = getSingle("maxFields", attr);
    int maxCount = Integer.parseInt(maxCountStr);
    String lastQuery = null;
    String lastField = null;
    String lastAndOrNot = null;
    String field;
    String query;
    String andOrNot;
    Map fieldMaps = GrouperHelper.getFieldsAsMap();
    String lastFieldDisplayName = null;
    QueryFilter queryFilter = null;
    if (outTerms == null) outTerms = new ArrayList();

    Stem fromStem = StemFinder.findByName(s, from, true);
    for (int i = 1; i <= maxCount; i++) {
      field = getSingle("searchField." + i, attr);
      query = getSingle("searchField." + i + ".query", attr);
      if (i == 1 && (field == null || query == null)) {
        if (getSingle("searchType.1", attr) != null) break;
        throw new IllegalArgumentException(
            "The first search field and query value must be enetered");
      }
      andOrNot = getSingle("searchField." + i + ".searchAndOrNot", attr);
      if (query == null || "".equals(query)) query = lastQuery;
      if (i > 1) {
        if (queryFilter == null) {
          queryFilter = getGroupAttributeFilter(lastField, lastQuery, fromStem);
          outTerms.add(lastQuery);
          lastFieldDisplayName = (String) ((Map) fieldMaps.get(lastField)).get("displayName");
          outTerms.add(lastFieldDisplayName);
        }
        if (field == null && i == 2) {
          break;
        }
        if (field == null && i > 2) break;

        if ("and".equals(lastAndOrNot)) {
          queryFilter =
              new IntersectionFilter(queryFilter, getGroupAttributeFilter(field, query, fromStem));
        } else if ("or".equals(lastAndOrNot)) {
          queryFilter =
              new UnionFilter(queryFilter, getGroupAttributeFilter(field, query, fromStem));
        } else {
          queryFilter =
              new ComplementFilter(queryFilter, getGroupAttributeFilter(field, query, fromStem));
        }
        outTerms.add(lastAndOrNot);
        outTerms.add(query);
        outTerms.add(field);
      }
      lastQuery = query;
      lastField = field;
      lastAndOrNot = andOrNot;
    }
    // Now add GroupTYpe filter
    String groupTypeText = navBundle.getString("find.results.group-type");
    String groupType = null;
    maxCountStr = getSingle("maxTypes", attr);
    try {
      maxCount = Integer.parseInt(maxCountStr);
    } catch (NumberFormatException e) {
      maxCount = 0;
    }
    GroupType gt = null;
    for (int i = 1; i <= maxCount; i++) {
      groupType = getSingle("searchType." + i, attr);
      if (groupType == null) break;
      gt = GroupTypeFinder.find(groupType, true);

      andOrNot = getSingle("searchType." + i + ".searchAndOrNot", attr);

      if (queryFilter == null) {
        queryFilter = new GroupTypeFilter(gt, fromStem);
        outTerms.add(groupTypeText);
        outTerms.add(gt.getName());
      } else {
        if ("and".equals(andOrNot)) {
          queryFilter = new IntersectionFilter(queryFilter, new GroupTypeFilter(gt, fromStem));
        } else if ("or".equals(andOrNot)) {
          queryFilter = new UnionFilter(queryFilter, new GroupTypeFilter(gt, fromStem));
        } else {
          queryFilter = new ComplementFilter(queryFilter, new GroupTypeFilter(gt, fromStem));
        }
        outTerms.add(andOrNot);
        outTerms.add(groupTypeText);
        outTerms.add(groupType);
      }
    }

    GrouperQuery q = GrouperQuery.createQuery(s, queryFilter);
    res.addAll(q.getGroups());
    return res;
  }