>
> Maybe it was because I didn't put in the JcrConstants.NT_FILE
> before?


Yes, that was likely contributing.  The Node#addNode call without
specifying a node type argument will choose the child node type by
inspecting the child node definitions for the parent node type (nt:folder
in this case).  A quick look at the nt:folder node type definition shows
that it allows children with any name whose node type is "nt:heirarchyNode"
(or derived from that type).

I haven't tried this, but I believe in your example it may have
chosen "nt:heirarchyNode" as the node type for the new child which wouldn't
be valid since that is an abstract node type.

Adding the JcrConstants.NT_FILE argument to the addNode call makes the
configuration valid for a child of an nt:folder node.

Regards,
-Eric

On Thu, Aug 26, 2021 at 3:33 PM Brian E. Lavender <br...@brie.com> wrote:

> Hmmm, it seems to work now for adding the file to the folder. See my
> code below. I was contrasting it to my code that previously didn't work.
>
> Maybe it was because I didn't put in the JcrConstants.NT_FILE
> before?
>
>
> ```java
> Node root, folder;
> root = session.getRootNode();
> folder = root.getNode("bar");
>
> Node child = folder.addNode("grade.png", JcrConstants.NT_FILE);
> Node content = child.addNode(JcrConstants.JCR_CONTENT,
> JcrConstants.NT_RESOURCE);
> // Set the property for the node.
> content.setProperty(JcrConstants.JCR_DATA,
>         root.getSession().getValueFactory().createBinary(new
>         FileInputStream("grade.png")));
>         content.setProperty(JcrConstants.JCR_MIMETYPE,
>         "image/png");
> Calendar rightNow = Calendar.getInstance();
> content.setProperty(JcrConstants.JCR_LASTMODIFIED, rightNow);
> ```
>
> On Thu, Aug 26, 2021 at 02:28:30PM -0700, Eric Norman wrote:
> > >
> > > "No child node definition for grade.png found in node /bar"
> >
> >
> > I see.  Well, the folder you created via webdav must be a "nt:folder"
> node
> > type?  In that case, the type of the child must extend "nt:hierarchyNode"
> > to conform with the "nt:folder" node type definition.
> >
> > In the example I provided in my last reply,  the child node is created
> > using the JcrConstants.NT_FILE node type which would satisfy that
> condition
> > since "nt:file" extends the "nt:hierarchyNode" node type.
> >
> > Hope that helps.
> >
> > Regards,
> > -Eric
> >
> > On Thu, Aug 26, 2021 at 2:17 PM Brian E. Lavender <br...@brie.com>
> wrote:
> >
> > > I clarified the root node and made a new variable to hold the node for
> > > the bar folder.
> > >
> > > ```java
> > > // bar is a folder created through the webdav interface.
> > > Node root,folder;
> > > root = session.getRootNode();
> > > folder = root.getNode("bar");
> > >
> > > // fails here
> > > Node child = folder.addNode("grade.png");
> > > ```
> > >
> > > Error message is the following
> > >
> > > "No child node definition for grade.png found in node /bar"
> > >
> > > On Thu, Aug 26, 2021 at 02:03:27PM -0700, Eric Norman wrote:
> > > > Maybe this a typo?  It looks like your sample code added the child
> to the
> > > > root node, not under "/bar" where you were doing the lookup.
> > > >
> > > > Node child = *root*.addNode("grade.png");
> > > >
> > > >
> > > > On Thu, Aug 26, 2021 at 1:47 PM Brian E. Lavender <br...@brie.com>
> > > wrote:
> > > >
> > > > > I still can not seem to add a file.
> > > > >
> > > > > I went through the webdav interface and I created a 'folder' called
> > > bar.
> > > > > Then, I tried to programmatically add a file to that folder. I am
> > > > > getting nothing.
> > > > >
> > > > > ```java
> > > > > // get the path for where to add the file.
> > > > > // We want to put it in the `bar` folder
> > > > > Node root;
> > > > > root = session.getRootNode();
> > > > > root = root.getNode("bar");
> > > > >
> > > > >
> > > > > System.out.print("Adding binary ");
> > > > > Calendar rightNow = Calendar.getInstance();
> > > > > // Add a node for the file
> > > > > // It fails here
> > > > > Node child = root.addNode("grade.png");
> > > > >
> > > > > // Set the property for the node.
> > > > > child.setProperty(JcrConstants.JCR_DATA,
> > > > >         root.getSession().getValueFactory().createBinary(new
> > > > > FileInputStream("grade.png")));
> > > > > child.setProperty(JcrConstants.JCR_MIMETYPE, "image/png");
> > > > > child.setProperty(JcrConstants.JCR_LASTMODIFIED, rightNow);
> > > > >
> > > > > session.save();
> > > > > ```
> > > > >
> > > > > ```
> > > > > javax.jcr.nodetype.ConstraintViolationException: No child node
> > > > > definition for grade.png found in node /bar
> > > > > <snip>
> > > > > at
> > > > >
> > >
> org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException(ServerObject.java:109)
> > > > > at
> > > org.apache.jackrabbit.rmi.client.ClientNode.addNode(ClientNode.java:95)
> > > > > at gov.ca.brea.jackrabbit.FifthHop.main(FifthHop.java:74)
> > > > >
> > > > >
> > > > >
> > > > > On Thu, Aug 26, 2021 at 01:04:35AM +0200, Jakub Kaniewski wrote:
> > > > > > For this you use ValueFactory
> > > > > >
> > > > > > Example
> > > > > >
> > > > >
> > >
> node.setProperty(JcrConstants.JCR_DATA,node.getSession().getValueFactory().createBinary
> > > > > <
> > > > >
> > >
> https://www.tabnine.com/code/java/methods/javax.jcr.ValueFactory/createBinary
> > > >(new
> > > > > FileInputStream(“/tmp/test.jpg)));
> > > > > >
> > > > > >
> > > > > > —
> > > > > > Jakub Kaniewski | 666 831 500 | jakub.kaniew...@gmail.com
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > > On 26 Aug 2021, at 00:59, Brian E. Lavender <br...@brie.com>
> > > wrote:
> > > > > > >
> > > > > > > How is it I add a binary to a Node?
> > > > > > >
> > > > > > > I see the following method.
> > > > > > > Property setProperty(java.lang.String name, Binary value)
> > > > > > >
> > > > > > > I see that Binary is an interface, yet I am not sure how to
> create
> > > a
> > > > > > > Binary from a File that I open.
> > > > > > >
> > > > > > > Or, stated another way, say I want to add a jpg image from my
> disk
> > > to
> > > > > > > a node. Would I use this setProperty method? How would I do it?
> > > > > > >
> > > > > > > Brian
> > > > > > > --
> > > > > > > Brian Lavender
> > > > > > > http://www.brie.com/brian/
> > > > > > >
> > > > > > > "There are two ways of constructing a software design. One way
> is
> > > to
> > > > > > > make it so simple that there are obviously no deficiencies.
> And the
> > > > > other
> > > > > > > way is to make it so complicated that there are no obvious
> > > > > deficiencies."
> > > > > > >
> > > > > > > Professor C. A. R. Hoare
> > > > > > > The 1980 Turing award lecture
> > > > > >
> > > > >
> > > > > --
> > > > > Brian Lavender
> > > > > http://www.brie.com/brian/
> > > > >
> > > > > "There are two ways of constructing a software design. One way is
> to
> > > > > make it so simple that there are obviously no deficiencies. And the
> > > other
> > > > > way is to make it so complicated that there are no obvious
> > > deficiencies."
> > > > >
> > > > > Professor C. A. R. Hoare
> > > > > The 1980 Turing award lecture
> > > > >
> > >
> > > --
> > > Brian Lavender
> > > http://www.brie.com/brian/
> > >
> > > "There are two ways of constructing a software design. One way is to
> > > make it so simple that there are obviously no deficiencies. And the
> other
> > > way is to make it so complicated that there are no obvious
> deficiencies."
> > >
> > > Professor C. A. R. Hoare
> > > The 1980 Turing award lecture
> > >
>
> --
> Brian Lavender
> http://www.brie.com/brian/
>
> "There are two ways of constructing a software design. One way is to
> make it so simple that there are obviously no deficiencies. And the other
> way is to make it so complicated that there are no obvious deficiencies."
>
> Professor C. A. R. Hoare
> The 1980 Turing award lecture
>

Reply via email to