6 Replies Latest reply on Mar 19, 2012 3:08 PM by dme

    Create WID Using Rest API

    dme

      Hi,

       

      How can I create a Work Item Definition using the Guvnor/jBPM REST API? I have a requirement to create WIDs for a number of services we have, and the users have an option of selecting the Services they want to expose in jBPM as a Work Item. I would like to expose these by creating the WIDs via the REST API. Is there any sample code I can look at to create the WIDs via the REST API.

       

      Thanks,

        • 1. Re: Create WID Using Rest API
          swiderski.maciej

          This is more Guvnor question rather than jBPM so you could give a try there

           

          An alternative could be to build the work item definition on your side (as the structure is well known) with what ever technology/frameworks you like and the use Guvnor REST API to upload it to the right package.

           

          HTH

          • 2. Re: Create WID Using Rest API
            dme

            Thanks for the suggestion. I tried something like below, it gives a HTTP 415 (Media-Type Not found) exception.

             

            String widxml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><asset><checkInComment>Test</checkInComment><description>This is a Work Item Definition Configuration File</description><metadata><format>wid</format><title>Sample3</title></metadata><type></type><version>1</version></asset>";

            String authorizationHeader = "Basic " + org.apache.cxf.common.util.Base64Utility.encode("guest:".getBytes());

                    WebClient client2 = WebClient.create("http://127.0.0.1:8080/");

                    client2.header("Authorization", authorizationHeader);

                    Response response= client2.path("drools-guvnor/rest/packages").accept("application/atom+xml").post(widxml);

                    System.out.println("response = " + response.getStatus());

             

            I was planning to first create the WID asset in guvnor, and then upload the WID using the octect-stream post method.

             

            Is this what you were suggesting, and if so would you know whats wrong with my implementation? I am using Apache CXF as the WebClient.

             

            Thanks.

            • 3. Re: Create WID Using Rest API
              tsurdilovic

              If you want to store files to Guvnor using its rest api here is an example:

               

               

                              URL createServiceNodeIconURL = new URL(packageAssetsURL);
                              HttpURLConnection createServiceNodeIconConnection = (HttpURLConnection) createServiceNodeIconURL
                                      .openConnection();
                              applyAuth(profile, createServiceNodeIconConnection);
                              createServiceNodeIconConnection.setRequestMethod("POST");
                              createServiceNodeIconConnection.setRequestProperty("Content-Type",
                                      "application/octet-stream");
                              createServiceNodeIconConnection.setRequestProperty("Accept",
                                      "application/atom+xml");
                              createServiceNodeIconConnection.setRequestProperty("Slug", "defaultservicenodeicon.png");
                              createServiceNodeIconConnection.setDoOutput(true);
                              createServiceNodeIconConnection.getOutputStream().write(getBytesFromFile(new File(default_servicenodeicon)));
                              createServiceNodeIconConnection.connect();
                              System.out.println("created service node icon: " + createServiceNodeIconConnection.getResponseCode());
              

               

              Where packageAssetsURL if you are working in a package named "somePackage" could be localhost:8080/drools-guvnor/rest/packages/somePackage/assets. To store files you have to use the "Slug" header to tell Guvnor what the name of your asset it. Note that you should check if this asset exists first and delete it before storing a new one.

               

              Hope this helps.

              • 4. Re: Create WID Using Rest API
                tsurdilovic

                "..users have an option of selecting the Services they want to expose in jBPM as a Work Item"

                This feature would be really nice to add to the jBPM Web Designer. Would you be willing to contribute? Your users then could for example select some services in designer and convert them to workitem definitions without having to leave their modelling environment.

                 

                We are currently working on visual service node creation in the web designer so this would be a nice extension to that.

                If you want to contribute someting like this find me on IRC (#jbpm on codehaus - tsurdilo) and I'll help you get started.

                • 5. Re: Create WID Using Rest API
                  juliuzprize

                  Thanks alot to this post. helped me big time on my project i am in right now.

                   

                   

                   

                                                                                                                                                                        

                  dietrine review

                  • 6. Re: Create WID Using Rest API
                    dme

                    Thanks for the information. I will try this out.

                     

                    I am currently in an experimental mode trying to determine how to integrate jBPM with our Service Repository. It would of-course be great to have this feature available within the Designer and allow users to access the utility from within the designer. There are a few other questions I have and will contact you on IRC once we decide to move forward with this approach.