Esempio n. 1
0
  private boolean compareGroups(Group org, Group copy) {
    if (showCompare) f.format("compare Group %s to %s %n", org.getName(), copy.getName());
    boolean ok = true;

    if (!org.getName().equals(copy.getName())) {
      f.format(" ** names are different %s != %s %n", org.getName(), copy.getName());
      ok = false;
    }

    // dimensions
    ok &= checkAll(org.getDimensions(), copy.getDimensions(), null);

    // attributes
    ok &= checkAll(org.getAttributes(), copy.getAttributes(), null);

    // variables
    // cant use object equality, just match on short name
    for (Variable orgV : org.getVariables()) {
      Variable copyVar = copy.findVariable(orgV.getShortName());
      if (copyVar == null) {
        f.format(" ** cant find variable %s in 2nd file%n", orgV.getFullName());
        ok = false;
      } else {
        ok &= compareVariables(orgV, copyVar, compareData, true);
      }
    }

    for (Variable copyV : copy.getVariables()) {
      Variable orgV = org.findVariable(copyV.getShortName());
      if (orgV == null) {
        f.format(" ** cant find variable %s in 1st file%n", copyV.getFullName());
        ok = false;
      }
    }

    // nested groups
    List groups = new ArrayList();
    ok &= checkAll(org.getGroups(), copy.getGroups(), groups);
    for (int i = 0; i < groups.size(); i += 2) {
      Group orgGroup = (Group) groups.get(i);
      Group ncmlGroup = (Group) groups.get(i + 1);
      ok &= compareGroups(orgGroup, ncmlGroup);
    }

    return ok;
  }
Esempio n. 2
0
    private void count(Group g) {
      ndims += g.getDimensions().size();
      nvars += g.getVariables().size();
      ngatts += g.getAttributes().size();
      ngroups += g.getGroups().size();

      for (Variable v : g.getVariables()) {
        natts += v.getAttributes().size();
        if (v instanceof Structure) {
          nstructFields += ((Structure) v).getVariables().size();
        }
      }
      for (Group ng : g.getGroups()) count(ng);
    }
  protected Group getJoinedGroup(String userRole, Group group1, Group group2) {
    Group res = null;

    {
      Principal principal = null;
      String id = null;
      String name = null;

      // Set 'principal':
      {
        principal = new SimplePrincipal(userRole);
      }

      // Set 'id':
      {
        id = userRole;
      }

      // Set 'name':
      {
        name = ApplicationUserRoles.getDisplayName(userRole);
      }

      if (group1 == null) {
        if (group2 == null) {
          res = null;
        } else {
          // Set result from 'group2':
          {
            AbstractUserAuthorizor.DefaultGroup g = new AbstractUserAuthorizor.DefaultGroup(group2);

            g.setName(name);
            g.setPrincipal(principal);

            res = g;
          }
        }
      } else {
        if (group2 == null) {
          // Set result from 'group1':
          {
            AbstractUserAuthorizor.DefaultGroup g = new AbstractUserAuthorizor.DefaultGroup(group1);

            g.setName(name);
            g.setPrincipal(principal);

            res = g;
          }
        } else {
          Properties properties = null;
          Map<String, List<String>> attributes = null;
          List<Principal> userPrincipals = null;
          List<Principal> superGroupPrincipals = null;
          List<Principal> groupPrincipals = null;

          // Set 'properties':
          {
            properties = new Properties();

            // Add properties from 'group1':
            {
              addPropertiesWithPrefix(properties, group1);
            }

            // Add properties from 'group2':
            {
              addPropertiesWithPrefix(properties, group2);
            }
          }

          // Set 'attributes':
          {
            Map<String, List<String>> attributes1 = group1.getAttributes();
            Map<String, List<String>> attributes2 = group2.getAttributes();

            attributes = joinAttributes(attributes1, attributes2);
          }

          // Set 'userPrincipals':
          {
            userPrincipals = new ArrayList<Principal>();

            // Add user principals from 'group1':
            {
              List<Principal> l = group1.getUserPrincipals();
              if (l != null) {
                userPrincipals.addAll(l);
              }
            }

            // Add user principals from 'group2':
            {
              List<Principal> l = group2.getUserPrincipals();
              if (l != null) {
                userPrincipals.addAll(l);
              }
            }
          }

          // Set 'superGroupPrincipals':
          {
            superGroupPrincipals = new ArrayList<Principal>();

            // Add super-group principals from 'group1':
            {
              List<Principal> l = group1.getSuperGroupPrincipals();
              if (l != null) {
                superGroupPrincipals.addAll(l);
              }
            }

            // Add super-group principals from 'group2':
            {
              List<Principal> l = group2.getSuperGroupPrincipals();
              if (l != null) {
                superGroupPrincipals.addAll(l);
              }
            }
          }

          // Set 'groupPrincipals':
          {
            groupPrincipals = new ArrayList<Principal>();

            // Add group principals from 'group1':
            {
              List<Principal> l = group1.getGroupPrincipals();
              if (l != null) {
                groupPrincipals.addAll(l);
              }
            }

            // Add group principals from 'group2':
            {
              List<Principal> l = group2.getGroupPrincipals();
              if (l != null) {
                groupPrincipals.addAll(l);
              }
            }
          }

          res =
              new AbstractUserAuthorizor.DefaultGroup(
                  principal,
                  id,
                  name,
                  properties,
                  attributes,
                  userPrincipals,
                  superGroupPrincipals,
                  groupPrincipals);
        }
      }
    }

    return res;
  }