コード例 #1
0
ファイル: LdapConfigUtils.java プロジェクト: rawmahn/dcm4che
  /**
   * Resolve map/collection key field for a property
   *
   * @param property
   * @return
   */
  static String getDistinguishingFieldForCollectionElement(AnnotatedConfigurableProperty property) {

    // by default use what annotated on the property
    LDAP annotation = property.getAnnotation(LDAP.class);
    String elementDistinguishingField =
        annotation == null ? LDAP.DEFAULT_DISTINGUISHING_FIELD : annotation.distinguishingField();

    // if property is default, check the annotation on the element class if its a confclass
    if (elementDistinguishingField.equals(LDAP.DEFAULT_DISTINGUISHING_FIELD))
      if (property.isArrayOfConfObjects()
          || property.isCollectionOfConfObjects()
          || property.isMapOfConfObjects())
        elementDistinguishingField =
            ((LDAP)
                    property
                        .getPseudoPropertyForConfigClassCollectionElement()
                        .getRawClass()
                        .getAnnotation(LDAP.class))
                .distinguishingField();

    return elementDistinguishingField;
  }
コード例 #2
0
ファイル: LdapConfigUtils.java プロジェクト: rawmahn/dcm4che
  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);
    }
  }