6 Replies Latest reply on Dec 29, 2012 4:05 AM by neoner2002

    create POJO Model jar using REST API

    richard916

      does anyone know how to create POJO Model jar using REST API?

      I post something like this 

      "

      <entry xml:base="http://localhost:9080/repository/packages/package1/assets">

         <title>testAsset1</title>

         <summary>desc1</summary>

      </entry>

       

      " but it's not model.

        • 1. Re: create POJO Model jar using REST API
          bigcar

          Not sure if you can do that using REST api.

           

          Here is what I did using WebDav:

           



          Sardine sardine = SardineFactory.begin("", "");


          byte[] jar = IOUtils.toByteArray(new FileInputStream("./workspace/my_model.jar"));


          sardine.put("http://localhost:38080/guvnor-5.3.0.Final-tomcat-6.0/org.drools.guvnor.Guvnor/webdav/packages/mypackage/my_model.jar", jar);


          System.out.println("Jar added ...");
          • 2. Re: create POJO Model jar using REST API
            richard916

            I finally firebug the post request when creating a pojo model with guvnor, and simulate that.

            besides,your code seems to add the jar file attachment,not create a model asset.

            • 3. Re: create POJO Model jar using REST API
              bigcar

              Yes. from WebDav perspective, uploading a jar file is essentially creating a pojo model asset.

              • 4. Re: create POJO Model jar using REST API
                ravinandan

                Hello Tao,

                 

                I'm able to upload my jar using sardine after which I'm able to see an entry in Model list in Guvnor.

                 

                But the facts are not getting reflected in the rules editor.

                 

                If I upload the same jar manually via Guvnor upload Model jar, I'm able to see the Facts.

                 

                Is there any way to trigger refresh or save functionality after I put the jar from sardine?

                 

                Thanks!

                 

                Edit:

                I'm able to upload the JAR via REST using the below code

                 

                       byte[] jar = Javac.getJar("FactUpload", classInfos);

                WebClient client = WebClient.create("http://localhost:8080");

                MultivaluedMap<String, String> map = new MetadataMap<String, String>();

                List<String> slugHeader = new ArrayList<String>();

                slugHeader.add("FactModel.jar");

                List<String> authHeader = new ArrayList<String>();

                authHeader.add("Basic " + new String(Base64.encodeBase64("admin:admin" .getBytes())));

                List<String> contentTypeHeader = new ArrayList<String>();

                contentTypeHeader.add("application/octet-stream");

                map.put("slug", slugHeader);

                map.put("Authorization", authHeader);

                map.put("Content-Type", contentTypeHeader);

                client.headers(map);

                client.path("/drools-guvnor-webapp/rest/packages/PLATFORMS/assets/");

                Response response = client.post(jar);

                 

                But still the same issue exists!

                • 5. Re: create POJO Model jar using REST API
                  ravinandan

                  Resolved the issue by adding the below block of code before repository save in createAssetFromBinary method from PackageResource class

                   

                  ContentHandler handler = ContentManager.getHandler( ai.getFormat() );

                              if ( handler instanceof ICanHasAttachment ) {

                                  ((ICanHasAttachment) handler).onAttachmentAdded( ai );

                              }

                   

                  Copied it from attachFileToAsset method from FileManagerService class.

                  • 6. Re: create POJO Model jar using REST API
                    neoner2002

                    Hi

                     

                    I'm trying to create an automated way to assign a model to a created package, but I have the same problem.

                     

                    The model is apparently assigned to the package via REST or WebDAV, but if a want to create a rule, it says that there is no model, (manually uploaded jar works)

                     

                    Your solution seems to be to change the surce code of Guvnor and compile it, isn't it?. Is it difficult to do?, Are there other solutions?

                     

                    Regards,

                        Felipe.