1 Reply Latest reply on Oct 31, 2012 8:57 AM by rush_pawan

    Weird results when adding or validating nt:file-Node

    u005078 Level 1

      Hello,

       

      I'm trying to add the absolute path: /content/2012/201212/20121219_lh_lu_1442.pdf/jcr.content/renditions/original/jcr.content by this code:

       

      Node parentNode = session.getNode("/content");
                    Verbose.message(3,"Add node " + folders[folders.length-1]);
              if (session.nodeExists(parentNode.getPath()+"/"+"2012"))  {
                  parentNode = session.getNode(parentNode.getPath()+"/"+"2012");
                  Verbose.message(3,parentNode.getPath() + " already there");
              }    
              else  {
                  parentNode = parentNode.addNode("2012", "sling:OrderedFolder");
                 Verbose.message(3,parentNode.getPath() + " created");
              }
      
              if (session.nodeExists(parentNode.getPath()+"/"+"201212"))  {
                  parentNode = session.getNode(parentNode.getPath()+"/"+"201212");
                  Verbose.message(3,parentNode.getPath() + " already there");
              }    
              else  {
                  parentNode = parentNode.addNode("201212", "sling:OrderedFolder");
                 Verbose.message(3,parentNode.getPath() + " created");
              }
      
              // dam:Asset-Node named with the PDF-Name
              Verbose.message(3,"Add node 20121219_lh_lu_1442.pdf ");
              if (session.nodeExists(parentNode.getPath()+"/"+"20121219_lh_lu_1442.pdf")  {
                  parentNode = session.getNode(parentNode.getPath()+"/"+"20121219_lh_lu_1442.pdf");
                  Verbose.message(3,parentNode.getPath() + " already there");
              }
              else  {
                  parentNode = parentNode.addNode("20121219_lh_lu_1442.pdf", "dam:Asset");
                  Verbose.message(3,parentNode.getPath() + " created");
              }
      
              // jcr:content 
              if (session.nodeExists(parentNode.getPath()+"/"+"jcr.content"))  {
                  parentNode = session.getNode(parentNode.getPath()+"/"+"jcr.content");
                  Verbose.message(3,parentNode.getPath() + " already there");
              }
              else  {
                  parentNode = parentNode.addNode("jcr.content", "dam:AssetContent");
                  session.save();
                  Verbose.message(3,parentNode.getPath() + " created");
              }
      
              // metadata
              Node metadata=null;        
              if (session.nodeExists(parentNode.getPath()+"/"+"metadata"))  {
                  metadata = session.getNode(parentNode.getPath()+"/"+"metadata");
                  Verbose.message(3,metadata.getPath() + " already there");
              }
              else  {
                  metadata=parentNode.addNode("metadata", "nt:unstructured");
                  session.save();
                  Verbose.message(3,metadata.getPath() + " created");
              }
      
              // renditions
              if (session.nodeExists(parentNode.getPath()+"/"+"renditions"))  {
                  parentNode = session.getNode(parentNode.getPath()+"/"+"renditions");
                  Verbose.message(3,parentNode.getPath() + " already there");
              }
              else  {
                  parentNode = parentNode.addNode("renditions", "nt:folder");
                  Verbose.message(3,parentNode.getPath() + " created");
              }
      
              listChildren("--->", parentNode );
      
              // orignal 
              Verbose.message(3,"Create node " + parentNode.getPath()+"/"+"orignal - Exists=" + session.itemExists(parentNode.getPath()+"/"+"orignal"));
              if (session.nodeExists(parentNode.getPath()+"/"+"orignal"))  {
                  parentNode = session.getNode(parentNode.getPath()+"/"+"orignal");
                  Verbose.message(3,parentNode.getPath() + " already there");
              }
              else  {
                  parentNode = parentNode.addNode("orignal", "nt:file");
                  parentNode.addNode("orignal", "nt:file");
                  Verbose.message(3,parentNode.getPath() + " created");
              }
      
              // jcr:content 
              Verbose.message(3,"Add node 'jcr.content' to " + parentNode.getPath());
              if (session.nodeExists(parentNode.getPath()+"/"+"jcr.content"))  {
                  parentNode = session.getNode(parentNode.getPath()+"/"+"jcr.content");
                  Verbose.message(3,parentNode.getPath() + " already there");
              }
              else  {
                  parentNode = parentNode.addNode("jcr.content", "nt:resource");            
      //            session.save();
                  Verbose.message(3,parentNode.getPath() + " created");
              }
      
              session.save();
      
              return parentNode.getPath();
          }
      
          private static void listChildren(String indent, Node node ) throws RepositoryException {
              System.out.println("-->" + indent + node.getName()+ " Exists=" + session.nodeExists(node.getPath())); 
              NodeIterator ni = node.getNodes();
              while(ni.hasNext()) {
                  Node nextNode=ni.nextNode();
                  listChildren(indent+"  ", nextNode);
                  String NAME = nextNode.getName();
              }
          }
      

       

      (Just to avoid irritations; the Verbose class does the logging.)

       

      My program fails in the line "parentNode = parentNode.addNode("orignal", "nt:file");" with the messages:

       

      Okt 29 16:33:14 --- Verbose(3): /content/2012 already there
      Okt 29 16:33:14 --- Verbose(3): /content/2012/201212 already there
      Okt 29 16:33:14 --- Verbose(3): Add node 20121219_lh_lu_1442.pdf
      Okt 29 16:33:14 --- Verbose(3): /content/2012/201212/20121219_lh_lu_1442.pdf already there
      Okt 29 16:33:14 --- Verbose(3): /content/2012/201212/20121219_lh_lu_1442.pdf/jcr.content already there
      Okt 29 16:33:14 --- Verbose(3): /content/2012/201212/20121219_lh_lu_1442.pdf/jcr.content/metadata already there
      Okt 29 16:33:14 --- Verbose(3): /content/2012/201212/20121219_lh_lu_1442.pdf/jcr.content/renditions already there
      -->--->renditions Exists=true
      -->--->  original Exists=true
      -->--->    jcr:content Exists=true
      Okt 29 16:33:15 --- Verbose(3): Create node /content/2012/201212/20121219_lh_lu_1442.pdf/jcr.content/renditions/orignal - Exists=false
      
      Exception in thread "main" javax.jcr.nodetype.ConstraintViolationException: no matching child node definition found for {}orignal
          at org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProviderImpl.getQNodeDefinition(ItemDefinitionProviderImpl.java:201)
          at org.apache.jackrabbit.jcr2spi.nodetype.ItemDefinitionProviderImpl.getQNodeDefinition(ItemDefinitionProviderImpl.java:90)
          at org.apache.jackrabbit.jcr2spi.NodeImpl.createNode(NodeImpl.java:1444)
          at org.apache.jackrabbit.jcr2spi.NodeImpl.addNode(NodeImpl.java:187)
          at com.lsy.test.lnnreader.lufthanseat.CRXrepository.addArchiveFolder(CRXrepository.java:120)
      
      

       

      I've no idea, why this program fails. The node ../original is already there; have added it with CRXDE Explorer. Saving there didn't work before adding jcr.content with the property "jcr:data". But now you can see that there is a difference in the validating the existence of the relative path "original" in the ongoing routine (results in "Exists=false") and in the "listChildren-method" called immediately after validating the "renditions". This routines results in "Exists=true" for the node "original".

       

      So I've got two questions left: What do I need to do to add the node with the WebDAV-Connected program and how can I make sure it recognizes correctly the existence of a node

       

       

      best regards,

      Ulrich