8 Replies Latest reply on Jan 30, 2013 6:14 AM by Radouane El Marjani

    Where I have to put the custom.cnd file in JBoss 7?

    Radouane El Marjani Newbie

      Hi,

       

      I am new in touch with Modeshape and Isearch for help here about this, but really I didn't find any cleary answer.

      The question is: I add some new NodeType in my "custom.cnd" file and I want to put it somewhere in JBOSS and after

      startup the jboss to get these files and have to be loaded, then I can work with them in my code.

       

      I see that in "modules/org/modeshape/main/res" are one example "custom.cnd" so I do the same but I still have this exception:

       

      javax.jcr.nodetype.ConstraintViolationException: Unable to determine a valid node definition for the node "...." in workspace "default" of "..."

       

       

      Can someone gives an answer please?

       

      Thanks,

       

      Radouane

        • 1. Re: Where I have to put the custom.cnd file in JBoss 7?
          Randall Hauch Master

          The "res" directory is automatically accessible to that module (see the line that includes the "res" directory in the "modules/org/modeshape/main/module.xml" file), so putting your CND file there is perfectly acceptable. But there are two additional steps you probably need to do.

           

          First, be sure that you include the CND file in your repository configuration. You can see an example of how that "custom.cnd" file is included in the sample "standalone-modeshape.xml" file that we ship with the kit:

           

                      <repository name="preconfiguredRepository">

                         <!-- ... -->

                          <node-types>

                              <node-type>custom.cnd</node-type>

                          </node-types>

                         <!-- ... -->

                      </repository>

           

          or you can use the CLI to add this to an already-configured repository.


          Second, upon startup JBoss AS7 indexes the contents of that directory and creates an "res.index" marker file in the "modules/org/modeshape/main/" directory. IIRC, AS7 only scans that directory if the index file is missing. So if you added your file to the "res" directory after you started AS7, the server probably had already indexed the directory (without your file). Simply remove the "res.index" file and restart your server.

          • 2. Re: Where I have to put the custom.cnd file in JBoss 7?
            Radouane El Marjani Newbie

            Thanks for the quick answer. Now I see under  my repository/jcr:system/jcr:nodetypes my defined node types.

             

            If I have do some changes in my custom.node, should I delete every time the res.index and start new the JBOSS?

             

             

            But I still have some Exceptions:

             

            I do these steps:

            I create my custom.cnd as follow:

             

            [patient:metadata] > nt:unstructured orderable

              - patient:name (string)

              - patient:vorname (string)

              - patient:dob (date)

              + * (patientcase:metadata)

             

            and I try this code: I want to create a new node for a patient:

            ----------------------------------------------------------------------------------------------------------

            public void addPatient(Patient p){

             

                    try {

                    session = createSession();

                    JcrTools tools = new JcrTools();

                    // add Patient Node for Patient p

                    //Node node = tools.findOrCreateNode(session, p.getName(), "nt:folder");

                   

                    Node patients = tools.findOrCreateNode(session,"patients", "nt:folder");

                    Node patientNode = tools.findOrCreateChild(patients, p.getName(), "patient:metadata");

                

                    // Add properties to the Node patient

                    patientNode.setProperty("patient:name", p.getName());

                   patientNode.setProperty("patient:vorname", p.getVorname());

                   SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");

                    Date date=null;

                    try {

                        date = (Date)formatter.parse(p.getDob().toString());

                    } catch (ParseException e) {

                        // TODO Auto-generated catch block

                        e.printStackTrace();

                    }

                    Calendar cal=Calendar.getInstance();

                    cal.setTime(date);

                    patientNode.setProperty("patient:dob", cal);

             

                    session.save();

                    } catch (RepositoryException e) {

                        e.printStackTrace();

                    } finally {

                        // logout

                        if (this.isLoggedIn()) {

                            session.logout();

                            logger.info("Logout");

                        }

                    }

             

                }

             

            When I try to run this code with some test data of patient I get this Exception: patient.name = "Andreas"

             

            javax.jcr.nodetype.ConstraintViolationException: Unable to determine a valid node definition for the node "/patients/Andreas" in workspace "default" of "orc"?

             

            What I do wrog?

             

            Thanks.

            • 3. Re: Where I have to put the custom.cnd file in JBoss 7?
              Radouane El Marjani Newbie

              it worked when I change this line from:

               

              Node patients = tools.findOrCreateNode(session,"patients", "nt:folder");

               

              to

               

              Node patients = tools.findOrCreateNode(session,"patients", "nt:unstrunctured");

               

              Did you have for me a justification?

               

              I am just start for two days with modeshape API. It's great, but I don't find some good examples, when the developper want to define his own node type.

               

              Thanks,

               

              Radouane

              • 4. Re: Where I have to put the custom.cnd file in JBoss 7?
                Randall Hauch Master

                If I have do some changes in my custom.node, should I delete every time the res.index and start new the JBOSS?

                No, I don't think you have to do that. Though you would need to restart the server or restart the repository using the CLI.

                 

                 

                But I still have some Exceptions:

                 

                I do these steps:

                I create my custom.cnd as follow:

                 

                [patient:metadata] > nt:unstructured orderable

                  - patient:name (string)

                  - patient:vorname (string)

                  - patient:dob (date)

                  + * (patientcase:metadata)

                 

                and I try this code: I want to create a new node for a patient:

                ----------------------------------------------------------------------------------------------------------

                public void addPatient(Patient p){

                 

                        try {

                        session = createSession();

                        JcrTools tools = new JcrTools();

                        // add Patient Node for Patient p

                        //Node node = tools.findOrCreateNode(session, p.getName(), "nt:folder");

                       

                        Node patients = tools.findOrCreateNode(session,"patients", "nt:folder");

                        Node patientNode = tools.findOrCreateChild(patients, p.getName(), "patient:metadata");

                    

                        // Add properties to the Node patient

                        patientNode.setProperty("patient:name", p.getName());

                       patientNode.setProperty("patient:vorname", p.getVorname());

                       SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");

                        Date date=null;

                        try {

                            date = (Date)formatter.parse(p.getDob().toString());

                        } catch (ParseException e) {

                            // TODO Auto-generated catch block

                            e.printStackTrace();

                        }

                        Calendar cal=Calendar.getInstance();

                        cal.setTime(date);

                        patientNode.setProperty("patient:dob", cal);

                 

                        session.save();

                        } catch (RepositoryException e) {

                            e.printStackTrace();

                        } finally {

                            // logout

                            if (this.isLoggedIn()) {

                                session.logout();

                                logger.info("Logout");

                            }

                        }

                 

                    }

                 

                When I try to run this code with some test data of patient I get this Exception: patient.name = "Andreas"

                 

                javax.jcr.nodetype.ConstraintViolationException: Unable to determine a valid node definition for the node "/patients/Andreas" in workspace "default" of "orc"?

                 

                What I do wrog?

                 

                Thanks.

                 

                I think the problem is that you're using "nt:folder" for the "patients" node, but "nt:folder" is really designed to represent a folder like on a file system and can only contain other "nt:folder" nodes and "nt:file" nodes as children. Because your "Andreas" node is of type "patient:metadata" (which extends "nt:unstructured" and does not extend "nt:file" or "nt:folder"), it cannot exist as a valid child under the "patients" node.

                 

                I'd suggest only using "nt:folder" if and only if you plan on creating "nt:files", or if you want your nodes to be accessible purely as "nt:file" and "nt:folder" nodes. Remember that you can create a "nt:file" and "nt:folder" nodes under other nodes, so that might be an option if you want to store documents/files somewhere underneath each patient node.

                 

                However, I expect that you really just want "patients" to be a container node. If that's the case, then I'd suggest using "nt:unstructured" or if that's too flexible defining and using a custom node type.

                1 of 1 people found this helpful
                • 5. Re: Where I have to put the custom.cnd file in JBoss 7?
                  Randall Hauch Master

                  I am just start for two days with modeshape API. It's great, but I don't find some good examples, when the developper want to define his own node type.

                  Our documentation is a work-in-progress. We'll keep trying to improve it, though.

                   

                  Have you read our blog?

                  • 6. Re: Where I have to put the custom.cnd file in JBoss 7?
                    Radouane El Marjani Newbie

                    Yes I know the blog. it helps me lot.

                     

                    Thanks for the answer and this allright, my idea is to put Documents of patient in repository then I can use nt:folder.

                     

                    Last Question here for today:

                     

                    I create a Repository and workspaces like this in standalone.xml:

                    --------------------------------------------------------------------------------------------------------------------------

                    <repository name="orc" cache-name="orc" cache-container="modeshape">

                         <node-types>

                             <node-type>

                                  orc.cnd

                             </node-type>

                        </node-types>

                        <workspaces>

                            <workspace name="report"/>

                        </workspaces>

                    </repository>

                    ----------------------------------------------------------------------------------------------------------------------------

                    As I understand workspace is print view of data of repository. If I create nodes for patient in reposiory, should I get a reference of my workspace "report" and I save the nodes there or the workspace is just used, if I want to read data from repository. Because for creating my node in the code, I don't use the workspace.

                     

                    Thanky you very much for answering my questions.

                     

                    Radoaune

                    • 7. Re: Where I have to put the custom.cnd file in JBoss 7?
                      Randall Hauch Master

                      Thanks for the answer and this allright, my idea is to put Documents of patient in repository then I can use nt:folder.

                      Please don't misunderstand. I think it's generally more powerful to use "nt:unstructured" for the "patients" node, so that each patient node can be of a more semantically-correct type. The patient node could contain "nt:file" nodes without the patient node being an "nt:folder".

                       

                       

                      I create a Repository and workspaces like this in standalone.xml:

                      --------------------------------------------------------------------------------------------------------------------------

                      <repository name="orc" cache-name="orc" cache-container="modeshape">

                           <node-types>

                               <node-type>

                                    orc.cnd

                               </node-type>

                          </node-types>

                          <workspaces>

                              <workspace name="report"/>

                          </workspaces>

                      </repository>

                      ----------------------------------------------------------------------------------------------------------------------------

                      As I understand workspace is print view of data of repository. If I create nodes for patient in reposiory, should I get a reference of my workspace "report" and I save the nodes there or the workspace is just used, if I want to read data from repository. Because for creating my node in the code, I don't use the workspace.

                      Every repository is divided into 1 or more workspaces, where each workspace has its own hierarchy of nodes (though all workspaces do see the same content under the "/jcr:system", which is reserved for implementation usage). Each workspace has its own content. One workspace is not a "view" of the repository.

                       

                      Whether you should use one or separate workspaces is a little complicated, because it gets into JCR's "corresponding nodes". A node in one workspace corresponds to a node is a different workspace if they share the same identifier. (This is achieved by cloning one workspace from the other.) Corresponding nodes share the same version history, too.

                       

                      If you don't care about corresponding nodes (and most people won't), then much of the time a single workspace will be sufficient. However, separate workspaces are fine for very different content. Just don't plan on creating a workspace per user/customer/patient/etc , for example. That's an abuse of the workspace concept, and is much better handled within a single workspace and hierarchy that gives you the separate areas.

                       

                      One of the workspaces is considered the default for when applications connect (e.g., log in) without specifying which workspace they want. In your case, you'll only have a single "report" workspace that will be the default. (I don't think this is what you're expecting.)

                       

                      Does this help?

                      1 of 1 people found this helpful
                      • 8. Re: Where I have to put the custom.cnd file in JBoss 7?
                        Radouane El Marjani Newbie

                        Thanks for your time and yours explications... I get in the next days really in touch with Modeshape and I am sure, I will have more then one question. Thanks, that helps a lot