Uploaded image for project: '[Read Only] - Hippo Site Toolkit 2'
  1. [Read Only] - Hippo Site Toolkit 2
  2. HSTTWO-1371

Improve the getChildBeans in HippoItem to make use of objectConverter.getPrimaryObjectType

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • 2.10.01
    • 2.20.04, 2.21.01
    • None

    Description

      Suggested new method by Ate. Thx!

      public <T> List<T> getChildBeans(String jcrPrimaryNodeType) {
      Class annotatedClass = this.objectConverter.getAnnotatedClassFor(jcrPrimaryNodeType);
      if (annotatedClass == null) {
      log.warn("Cannot get ChildBeans for jcrPrimaryNodeType '{}' because there is no annotated class for this node type. Return null",
      jcrPrimaryNodeType);
      return new ArrayList<T>();
      }
      if (this.node == null) {
      log.warn("Cannot get ChildBeans for jcrPrimaryNodeType '{}' because the jcr node is detached. ",
      jcrPrimaryNodeType);
      return new ArrayList<T>();
      }

      List<T> childBeans = new ArrayList<T>();
      NodeIterator nodes;
      try {
      nodes = node.getNodes();
      while (nodes.hasNext()) {
      Node child = nodes.nextNode();
      if (child == null)

      { continue; }

      try {

      String nodeObjectType = objectConverter.getPrimaryObjectType(child);
      if (nodeObjectType != null && nodeObjectType.equals(jcrPrimaryNodeType)) {
      T bean = (T)this.objectConverter.getObject(child);
      if (bean != null) { // && annotatedClass.isAssignableFrom(bean.getClass()))

      { childBeans.add(bean); }

      }
      } catch (ObjectBeanManagerException e) {
      log.warn("Skipping bean: {}", e);
      }

      }
      } catch (RepositoryException e)

      { log.error("RepositoryException: Cannot get ChildBeans for jcrPrimaryNodeType: '" + jcrPrimaryNodeType + "' ", e); return new ArrayList<T>(); }

      return childBeans;

      Attachments

        Activity

          People

            aschrijvers Ard Schrijvers
            aschrijvers Ard Schrijvers
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: