public void testBooleanArray() {
   assertArrayContainer(BooleanContainer.testInstance());
 }
Exemplo n.º 2
0
  static String refToLdapDN(
      String ref, LdapConfigurationStorage ldapStorage, BooleanContainer dnIsKillableWrapper) {

    boolean dnIsKillable = true;
    try {
      Iterator<Map<String, Object>> pathItemIter = ConfigNodeUtil.parseReference(ref).iterator();

      // first pathitem is always dicomconfigroot
      if (!pathItemIter.next().get("$name").equals("dicomConfigurationRoot"))
        throw new IllegalArgumentException("No dicom config root");

      String dn = "cn=DICOM Configuration," + ldapStorage.getBaseDN();

      Class currentClass = CommonDicomConfiguration.DicomConfigurationRootNode.class;
      while (pathItemIter.hasNext()) {

        List<AnnotatedConfigurableProperty> properties =
            ConfigIterators.getAllConfigurableFieldsAndSetterParameters(currentClass);

        Map<String, Object> pathItem = pathItemIter.next();

        Object name = pathItem.get("$name");

        for (AnnotatedConfigurableProperty property : properties) {
          if (name.equals(property.getAnnotatedName())) {

            // in any case
            if (!isNoContainerNode(property)) {
              dn = dnOf(dn, "cn", getLDAPPropertyName(property));
              dnIsKillable = true;
            } else dnIsKillable = false;

            // for collections/maps, analyze predicates
            if (property.isCollectionOfConfObjects()
                || property.isMapOfConfObjects()
                || property.isArrayOfConfObjects()) {

              // remove $name, because it is the collection name in this pathitem
              pathItem.remove("$name");

              // add rdn
              List<String> rdnItems = new ArrayList<String>();
              while (true) {
                // collect rdn pieces
                for (Map.Entry<String, Object> entry : pathItem.entrySet()) {

                  // skip wildcard - expect predicates
                  if (entry.getKey().equals("$name") && entry.getValue().equals("*")) {
                    if (pathItem.size() == 1)
                      throw new IllegalArgumentException(
                          "Wildcard without predicates is not allowed in references");
                    continue;
                  }

                  // add the rest of predicates to rdn
                  String df = null;
                  if (entry.getKey().equals("@name") || entry.getKey().equals("$name"))
                    df = getDistinguishingFieldForCollectionElement(property);
                  else df = entry.getKey();
                  rdnItems.add(df + "=" + escapeStringToLdap(entry.getValue()));
                }

                if (!rdnItems.isEmpty()) {
                  // if rdn found, proceed
                  dn = StringUtils.join(rdnItems, "+") + "," + dn;
                  dnIsKillable = true;
                  break;
                } else if (!pathItemIter.hasNext()) {
                  // rdn not found, path is over,.. nothing to look for
                  break;
                } else {
                  // get next path item and collect the rdn there
                  pathItem = pathItemIter.next();
                }
              }

              currentClass =
                  property.getPseudoPropertyForConfigClassCollectionElement().getRawClass();
            }

            // ConfObject
            if (property.isConfObject()) currentClass = property.getRawClass();
          }
        }

        // handle extensions
        if (currentClass.equals(Device.class)) {
          if (name.equals("deviceExtensions")
              || name.equals("aeExtensions")
              || name.equals("hl7AppExtensions")) {

            dnIsKillable = false;

            String extName;
            if (pathItem.containsKey("@name")) {
              extName = pathItem.get("@name").toString();
            } else {
              pathItem = pathItemIter.next();
              extName = pathItem.get("$name").toString();
            }

            currentClass = getExtensionClassBySimpleName(ldapStorage, extName);

            LDAP ldapanno = (LDAP) currentClass.getAnnotation(LDAP.class);
            if (ldapanno == null || !ldapanno.noContainerNode()) {
              dn = dnOf(dn, "cn", currentClass.getSimpleName());
              dnIsKillable = true;
            }
          }
        }
      }

      dnIsKillableWrapper.setKillable(dnIsKillable);
      return dn;
    } catch (Exception e) {
      throw new RuntimeException("Cannot transform reference " + ref + " to LDAP dn", e);
    }
  }
 protected void store() throws Exception {
   store(BooleanContainer.testInstance());
   store(IntegerContainer.testInstance());
 }