I would like to create a new form data using the Form Runner persistence API REST
-- as write here http://wiki.orbeon.com/forms/doc/developer-guide/form-runner/persistence-api I use the PUT method /crud/[APPLICATION_NAME]/[FORM_NAME]/(data|draft)/[FORM_DATA_ID]/data.xml It seems that the FORM_DATA_ID that I create is not correct. Here my code: //xml file with xform data String strXMLFilename = ... // orbeon server path like // http://localhost:8085/orbeon/fr/service/persistence/crud/myapp/myform/data/[FORM_DATA_ID]/data.xml String strURL = ... File input = new File(strXMLFilename); PutMethod put = new PutMethod(strURL); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); put.setRequestEntity(entity); // Get HTTP client HttpClient httpclient = new HttpClient(); // Execute request try { int result = httpclient.executeMethod(put); // Display status code LOG.debug("[newEntry] Response status code: " + result); // Display response LOG.debug("[newEntry] Response body: "); LOG.debug("[newEntry] " + put.getResponseBodyAsString()); } .... FORM_DATA_ID is calculated as: ... String formDataId = null; double d = Math.random(); String str = String.valueOf(d); MessageDigest md = MessageDigest.getInstance("SHA-1"); String text = value; md.update(text.getBytes("UTF-8")); byte[] mdbytes = md.digest(); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < mdbytes.length; i++) { hexString.append(Integer.toHexString(0xFF & mdbytes[i])); } //FORM_DATA_ID formDataId = hexString.toString(); an example of FORM_DATA_ID calculated is: efdad1e0bdf6c852f939a05a80f67984e4e8b8d2 The problem is that the status code returned is 400 and nothing is created. If I use the PUT method to modify a forms everything is ok (in this case I use a FORM_DATA_ID already created). I use orbeon 4.7 with storage mysql. What I'm doing wrong? Thanks, Massimo You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. |
PUT should only be used for updating an existing resource. In a REST API new records should be created using POST and the location of the newly created record should be returned in the Location header of the response.
I posted a question about this on stackoverflow.com here: http://stackoverflow.com/questions/30632135/orbeon-does-the-persistence-api-not-support-a-post-to-create-form-data |
Administrator
|
And for reference, if someone finds this thread, there are some follow-ups on the Stack Overflow question linked earlier by Andrew. Alex On Wed, Jun 3, 2015 at 3:29 PM, ajw625 <[hidden email]> wrote: PUT should only be used for updating an existing resource. In a REST API new You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
I still haven't got it working, though. Did you see my comments? I'm getting a 400 - Bad Request when trying to do a PUT to create new form data. On Thu, Jun 4, 2015 at 5:26 PM, Alessandro Vernet [via Orbeon Forms community mailing list] <[hidden email]> wrote:
|
Administrator
|
Hi Andrew, Are you saying that this still isn't working for you? That you're getting a 201 when doing a PUT for an existing id, but a 400 when using a new id? Could that be a permissions problem (does the form have permissions enabled)? Could you send us the relevant part of the orbeon.log? Alex On Fri, Jun 5, 2015 at 7:14 AM, ajw625 <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
I figured out that the reason I was getting a 400 when using a new ID is that I was not including the Orbeon-Form-Definition-Version header. This header is not required for updating an existing ID since the version is already stored in the database. The requirement for this header is not mentioned in the Persistence API documentation (http://wiki.orbeon.com/forms/doc/developer-guide/form-runner/persistence-api). This doc only mentions that the header is passed when publishing. On Mon, Jun 8, 2015 at 4:58 PM, Alessandro Vernet [via Orbeon Forms community mailing list] <[hidden email]> wrote:
|
In reply to this post by Alessandro Vernet
By the way, what we're really looking to do is create an empty form data record programmatically so that we know the document ID ahead of time. A user will be filling out multiple forms as a set and the document IDs will be stored in a database as part of the form data set. The /new page does not seem like a good candidate for this since it requires displaying the page and a user clicking Save for a record to be created. When doing a PUT to the Persistence API, we are required to submit empty XML data. Ideally we would just create a record without needing to submit empty XML data. It seems that the only way to accomplish what we want is to use the API to get the schema, generate empty form data XML from the schema, and do a PUT with a new document ID. On Tue, Jun 9, 2015 at 9:50 AM, Andrew Wilkinson <[hidden email]> wrote:
|
Administrator
|
In reply to this post by ajw625
Hi Andrew, Good point; I added a note about this to the documentation, under: Alex On Tue, Jun 9, 2015 at 9:31 AM, ajw625 <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Thanks. Do you agree that the approach I described seems the best fit for what we're trying to do? On Tue, Jun 9, 2015 at 11:16 AM, Alessandro Vernet [via Orbeon Forms community mailing list] <[hidden email]> wrote:
|
Administrator
|
Andrew, I see. Another approach, maybe, would be to just use the /new, but have the "submit" button also call send() sending the document id of the data that was just created to a service you provide. You most likely want to send some other data to your service, so you know who did that action. You can do by calling send(uri = "<a href="http://your-service?param={encode-for-uri(">http://your-service?param={encode-for-uri(…)}") in the process. In the "…", you can use XPath to get a request parameter, header, etc. Would something like this work for you? Alex On Tue, Jun 9, 2015 at 11:36 AM, ajw625 <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Thanks. I had considered using send() on a button, but we decided that we want to create the form data before the user sees the form. I think we'll plan to go with the "get schema, generate empty form data, PUT with a new document ID" solution. On Tue, Jun 9, 2015 at 2:33 PM, Alessandro Vernet [via Orbeon Forms community mailing list] <[hidden email]> wrote:
|
Generating empty XML data from XSD seems to be more complicated than we had expected.
There seem to be a lot of tools out there. For example, Eclipse will do this though its output is slightly different (namespaces included, ordering, open and closing nodes instead of an empty node). It looks like JAXB can do this, but seems to require code generation as part of the process, which is definitely not ideal. What we really want is to create an empty XML instance the same way Orbeon does. How does Orbeon do it? Is there any way we can get Orbeon to do it programmatically? 1. Would it be easy for you to expose a REST endpoint that creates an empty document in the form data table and returns the document ID? 2. Or a REST endpoint that simply returns an empty XML instance, much like the /schema endpoint? 3. Or is there Orbeon code that we could call? |
Administrator
|
Hi Andrew, Orbeon Forms doesn't try to create an empty document from a schema. Instead, Form Builder maintains such an empty document (not a schema) for your form, and updates it as you edit the form in Form Builder. If you want such an empty document, you can extract it from form definition. However, have you given some thoughts to my suggestion in the previous message, namely *not* to attempt to create empty documents, and instead to use the /new page, along with a process that sends the data to a service you provide? Alex On Fri, Jun 26, 2015 at 10:55 AM, ajw625 <[hidden email]> wrote: Generating empty XML data from XSD seems to be more complicated than we had You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Hi Alex,
We have thought about using the /new page. However, we need to be able to prepopulate the form with data. We will have sets of forms that may share data. We considered the possibility of using request parameters to pass in values, but determined that wouldn't solve the problem. Calculated Value is read-only and Initial Value will only be populated the first time, not after it has been edited on another form. For example, Form A and Form B might include contact-name. The user enters a value on Form A which we must then prepopulate on Form B. The user may then edit contact-name on Form B. That must then be reflected on Form A. We will actually be persisting data outside of Orbeon in a different format and converting it to the Orbeon format each time a form is displayed. I compared the empty document in the form definition with empty form data that created by going to /new and hitting save without entering anything. The format is slightly different for repeated grids. In the form definition, each iteration of a repeated grid is encapsulated with a <*-iteration> node. Saved empty form data: <section-with-repeated-grid> <repeated-grid-1> <cat-name /> <cat-breed /> </repeated-grid-1> </section-with-repeated-grid> Form definition: <section-with-repeated-grid> <repeated-grid-1> <repeated-grid-1-iteration> <cat-name /> <cat-breed /> </repeated-grid-1-iteration> </repeated-grid-1> </section-with-repeated-grid> It looks like the form definition has the latest (edge) format and Form Runner is saving the 4.0.0 format. I figured this out from testing the send() feature with the data-format-version parameter. Issue #2104 - POST to /new handles missing data-format-version incorrectly seems to indicate that this might be configurable somehow. But I can't find any documentation on data-format-version anywhere but in the send() documentation. Is there a global property for form runner? |
Administrator
|
Hi Andrew, Yes, you're correct on the data format for repeats. The idea is that, ideally, we should have had that additional "iteration" element from the beginning. Since we didn't, not to require existing data in the database to be "upgraded", and potentially custom implementations of the persistence API to be changed, we're adding it "on read" and removing it "on write". Since to some service might benefit from having that extra element, you can have send() send the data with the extra element with data-format-version = "edge". Does this make sense? Alex On Fri, Jul 3, 2015 at 4:34 PM, ajw625 <[hidden email]> wrote: Hi Alex, You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Hi Alex, Yes, that makes sense. That's exactly what it looked like. Is there a way to prevent it from being added "on read" and removed "on write"? That is, is there a property I can add to my properties-local.xml to turn off that feature and have the "edge" format written to the database? I realize that would break any existing form data, but we only have test data at this point. I'm not sure if we would want to do this. I'm just exploring options. On Wed, Jul 8, 2015 at 4:40 PM, Alessandro Vernet [via Orbeon Forms community mailing list] <[hidden email]> wrote:
|
Administrator
|
Hi Andrew, Right now we don't have a property for this, but it wouldn't necessarily be hard to do, as it is just a matter or not doing that conversion back and forth when we get the data from / send the data to the database. Alex On Wed, Jul 8, 2015 at 4:53 PM, ajw625 <[hidden email]> wrote:
You received this message because you are subscribed to the Google Groups "Orbeon Forms" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email].
--
Follow Orbeon on Twitter: @orbeon Follow me on Twitter: @avernet |
Thanks, Alex. On Thu, Jul 9, 2015 at 11:01 AM, Alessandro Vernet [via Orbeon Forms community mailing list] <[hidden email]> wrote:
|
Free forum by Nabble | Edit this page |