using the xml:db API in XPL - datasource.xml

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

using the xml:db API in XPL - datasource.xml

Vlad
Hello,

I'm getting the following error when trying to perform queries on built-in eXist database :

ERROR ProcessorService  - Exception at line 40, column 68 of oxf:/apps/master-thesis/xpl/update-specializations.xpl (reading processor output: name='data', id='result', ref='data')
java.net.URISyntaxException: Expected authority at index 8: exist://
        at java.net.URI$Parser.fail(URI.java:2829)
        at java.net.URI$Parser.failExpecting(URI.java:2835)
        at java.net.URI$Parser.parseHierarchical(URI.java:3083)
        at java.net.URI$Parser.parse(URI.java:3034)
        at java.net.URI.<init>(URI.java:595)


The code in the .xpl file :

        <p:processor xmlns:xdb="http://orbeon.org/oxf/xml/xmldb" name="oxf:xmldb-query">
            <p:input name="datasource" href="datasource.xml"/>
            <p:input name="query">
                <xdb:query collection="/db/orbeon/master-thesis/specializations.xml" create-collection="false">
                    xquery version "1.0";
                    <specializations>
                        {
                        for $x in /specializations/specialization return
                        <specialization>
                        <name>{$x/name}</name>
                        <faculty-refid>{$x/faculty-refid}</faculty-refid>
                        <cycle>{$x/cycle}</cycle>
                        </specialization>
                        }
                    </specializations>
                </xdb:query>
            </p:input>
            <p:output name="data" id="result" debug="results" ref="data"/>
        </p:processor>


Content of datasource.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<datasource>
    <driver-class-name>org.exist.xmldb.DatabaseImpl</driver-class-name>
    <uri>xmldb:exist://</uri>
    <username>admin</username>
    <password>admin</password>
</datasource>


I guess it's an authentication issue . I also tried without <username> and <password> tags .
What's the default username and password for the built-in eXist database ? Or how can I define them ? (I know that properties-local.xml is used , but I didn't find any examples)

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: using the xml:db API in XPL - datasource.xml

Erik Bruchez
Administrator
Vlad,

It might be "admin" with a blank password.

To set a proper admin password, you probably have to connect to eXist
with the eXist client. We have some information here relevant to a
separate eXist:

http://wiki.orbeon.com/forms/doc/developer-guide/exist-configuration

-Erik

On Tue, Jun 26, 2012 at 6:30 PM, Vlad <[hidden email]> wrote:

> Hello,
>
> I'm getting the following error when trying to perform queries on built-in
> eXist database :
>
> /ERROR ProcessorService  - Exception at line 40, column 68 of
> oxf:/apps/master-thesis/xpl/update-specializations.xpl (reading processor
> output: name='data', id='result', ref='data')
> java.net.URISyntaxException: Expected authority at index 8: exist://
>        at java.net.URI$Parser.fail(URI.java:2829)
>        at java.net.URI$Parser.failExpecting(URI.java:2835)
>        at java.net.URI$Parser.parseHierarchical(URI.java:3083)
>        at java.net.URI$Parser.parse(URI.java:3034)
>        at java.net.URI.<init>(URI.java:595)/
>
> The code in the .xpl file :
>
>        /<p:processor xmlns:xdb="http://orbeon.org/oxf/xml/xmldb"
> name="oxf:xmldb-query">
>            <p:input name="datasource" href="datasource.xml"/>
>            <p:input name="query">
>                <xdb:query
> collection="/db/orbeon/master-thesis/specializations.xml"
> create-collection="false">
>                    xquery version "1.0";
>                    <specializations>
>                        {
>                        for $x in /specializations/specialization return
>                        <specialization>
>                                <name>{$x/name}</name>
>                                <faculty-refid>{$x/faculty-refid}</faculty-refid>
>                                <cycle>{$x/cycle}</cycle>
>                        </specialization>
>                        }
>                    </specializations>
>                </xdb:query>
>            </p:input>
>            <p:output name="data" id="result" debug="results" ref="data"/>
>        </p:processor>/
>
> Content of datasource.xml :
>
> /<?xml version="1.0" encoding="UTF-8" ?>
> <datasource>
>    <driver-class-name>org.exist.xmldb.DatabaseImpl</driver-class-name>
>    <uri>xmldb:exist://</uri>
>    <username>admin</username>
>    <password>admin</password>
> </datasource>/
>
> I guess it's an authentication issue . I also tried without <username> and
> <password> tags .
> What's the default username and password for the built-in eXist database ?
> Or how can I define them ? (I know that properties-local.xml is used , but I
> didn't find any examples)
>
> Thanks!
>
> --
> View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/using-the-xml-db-API-in-XPL-datasource-xml-tp4655360.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws
>


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: using the xml:db API in XPL - datasource.xml

Vlad
The problem was here :

Content of datasource.xml :

<?xml version="1.0" encoding="UTF-8" ?>
<datasource>
   <driver-class-name>org.exist.xmldb.DatabaseImpl</driver-class-name>
   <uri>xmldb:exist://</uri>
   <username>admin</username>
   <password>admin</password>
</datasource>

There were supposed to be 3 slashes:

<uri>xmldb:exist:///</uri>

Quite tricky..


Other questions :

1.
can I access the instance data inside oxf:xmldb-query processor (in the query) ?
I tried something like :

                <xdb:query collection="/db/orbeon/master-thesis">
                    xquery version "1.0";
                    <specializations>
                        {
                        for $x in /specializations/specialization
                        where $x/faculty-refid = doc('input:instance')/students/student/faculty-refid
                        return
                        <specialization id="{$x/@id}">
                        <name>{$x/name}</name>
                        <faculty-refid>{$x/faculty-refid}</faculty-refid>
                        <cycle>{$x/cycle}</cycle>
                        </specialization>
                        }
                    </specializations>
                </xdb:query>

..and also tried with XPointer , but it didn't work.


2.
The instance sent from XForms is not recognized in the pipeline

I defined the input at the beginning of the xpl file :

<p:param name="instance" type="input" debug="instancedata" />

Nothing is printed in the log file , like it doesn't exist . Also tried with an identity processor and put the debug attribute there . Still didn;t work.

..and this is the submission in XForms :

                        <xforms:submission id="update-specializations" ref="instance('add-edit-student-instance')"
                                   validate="false" method="post" resource="/master-thesis/update-specializations"
                                   replace="instance" instance="specializations-instance" />


I guess it's a small detail that messes it up.



Thanks !
Reply | Threaded
Open this post in threaded view
|

Re: using the xml:db API in XPL - datasource.xml

Vlad
I found the solution , I'll post it here , maybe it'll help others  :

I firstly passed the instance data (some values from it are used in a few conditions in the query) to an XSLT processor which returns the query , which is passed as an input to xmldb-query processor :

<p:processor name="oxf:xslt">
    <p:input name="data" href="#instance" />
        <p:input name="config" href="oxf:/apps/appName/xsl/xsltFile.xsl" />
        <p:output name="data" id="query" debug="query-debug" />
</p:processor>

<p:processor xmlns:xdb="http://orbeon.org/oxf/xml/xmldb" name="oxf:xmldb-query">
        <p:input name="datasource" href="datasource.xml"/>
        <p:input name="query" href="#query" debug="query" />
        <p:output name="data" debug="results" ref="data"/>
</p:processor>


xsltFile.xsl :

<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:f="http://orbeon.org/oxf/xml/formatting"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:xforms="http://www.w3.org/2002/xforms"
    xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
    xmlns:version="java:org.orbeon.oxf.common.Version"
    xmlns:xdb="http://orbeon.org/oxf/xml/xmldb">
    <xsl:output encoding="utf8" omit-xml-declaration="yes" indent="yes" />
        <xsl:template match="/students/student">
                <xsl:element name="xdb:query">
                        <xsl:attribute name="collection">/db/orbeon/master-thesis</xsl:attribute>
                        <xsl:text disable-output-escaping="no">
                                xquery version "1.0";
                        </xsl:text>
                        <xsl:element name="specializations">
                                <xsl:text disable-output-escaping="no">{
                                for $x in /specializations/specialization
                              where $x/faculty-refid=</xsl:text>
                            <xsl:value-of select="faculty-refid" />
                            <xsl:text>and $x/cycle="</xsl:text>
                          <xsl:value-of select="cycle" />
                            <xsl:text>" return</xsl:text>
                                <xsl:element name="specialization">
                                        <xsl:attribute name="id"><xsl:text>{$x/@id}</xsl:text></xsl:attribute>
                              <xsl:element name="name">
                              <xsl:text>{$x/name}</xsl:text>
                              </xsl:element>
                              <xsl:element name="faculty-refid">
                              <xsl:text>{$x/faculty-refid}</xsl:text>
                              </xsl:element>
                              <xsl:element name="cycle">
                              <xsl:text>{$x/cycle}</xsl:text>
                              </xsl:element>
                                </xsl:element>
                                <xsl:text disable-output-escaping="no">}</xsl:text>
                    </xsl:element>
            </xsl:element>
        </xsl:template>
</xsl:stylesheet>
Reply | Threaded
Open this post in threaded view
|

Re: using the xml:db API in XPL - datasource.xml

Vlad
Another problem , somehow connected to the one above , so I didn't start a new topic :

I didn't find any documentation on how to specify the exact file in the eXist collection on which to perform xmldb-query , xmldb-insert , xmldb-update or xmldb-delete processor operations .

The only thing that I found is how to create that file :
http://wiki.orbeon.com/forms/doc/developer-guide/processors-xml-databases#TOC-Create-a-named-file-with-the-xml:db-processor


For example , I have a collection in /db/orbeon/master-thesis and different files (documents) in it :

/db/orbeon/master-thesis/students.xml
/db/orbeon/master-thesis/faculties.xml
/db/orbeon/master-thesis/specializations.xml



I need some concrete examples on how I can specify the exact document , not only the collection .
doc() , document() functions  - are these useful ?


Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: using the xml:db API in XPL - datasource.xml

Vlad
Can anybody give me an answer on this ?

It shouldn't be too complex , it's about basic/CRUD operations ..
DL
Reply | Threaded
Open this post in threaded view
|

Re: using the xml:db API in XPL - datasource.xml

DL
This post was updated on .
I'm not sure if this helps you ..

but in the /xforms-bookcast/  view.xhtml there are some CRUD examples for books (use as template for thesis) ..

<!-- Submission to get the document containing all the books -->
            <xforms:submission id="list-submission" serialization="none"
                       method="get" action="/exist/rest/db/orbeon/xforms-bookcast/books.xml"
                       replace="instance" instance="books-instance"/>

<!-- Submission to save the document containing all the books -->
            <xforms:submission id="save-submission" ref="instance('books-instance')"
                    action="/exist/rest/db/orbeon/xforms-bookcast/books.xml"
                    method="put" replace="none">
                <xforms:message ev:event="xforms-submit-error" level="modal">An error occurred while saving!</xforms:message>
            </xforms:submission>

<!-- Submission to load the sample data -->
            <xforms:submission id="sample-data-submission" serialization="none"
                       method="get" action="oxf:/apps/xforms-bookcast/sample-data.xml"
                       replace="instance" instance="books-instance"/>

Reply | Threaded
Open this post in threaded view
|

Re: using the xml:db API in XPL - datasource.xml

Vlad
That's the xforms:submission processor , it can only return/replace the whole content of a document .

I want to perform queries , to select/insert/update/delete certain parts of files from eXist database. And the documentation on xmldb processors is incomplete.
Reply | Threaded
Open this post in threaded view
|

Re: Re: using the xml:db API in XPL - datasource.xml

Eric van der Vlist
Hi,

Le mardi 03 juillet 2012 à 12:19 -0700, Vlad a écrit :
> That's the xforms:submission processor , it can only return/replace the whole
> content of a document .

Yes and no.

You can use it to POST XQuery requests that select specific node sets
from a collection, a document or the whole database and you can even use
the XQuery update facility to insert or update nodes.

Eric

> I want to perform queries , to select/insert/update/delete certain parts of
> files from eXist database. And the documentation on xmldb processors is
> incomplete.
>
> --
> View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/using-the-xml-db-API-in-XPL-datasource-xml-tp4655360p4655423.html
> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
> pièce jointe document texte brut (message-footer.txt)
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: using the xml:db API in XPL - datasource.xml

Gerrit Boers
Hi,

I use  POST submissions to xqueries a lot for exactly this purpose. Besides the ability to submit parts of an xml instance this approach is also very useful for all kinds of post processing actions on the data.
The data is often retrieved with an xquery so that extra nodes/attributes can be added that are necessary for the UI, these extra item are removed when the data is saved.

Retrieving xml with xqueries and saving with a POST submission to an xquery gives you far more control than just retrieving and submitting xml documents.

regards,

Gerrit

On Jul 3, 2012, at 10:26 PM, Eric van der Vlist wrote:

> Hi,
>
> Le mardi 03 juillet 2012 à 12:19 -0700, Vlad a écrit :
>> That's the xforms:submission processor , it can only return/replace the whole
>> content of a document .
>
> Yes and no.
>
> You can use it to POST XQuery requests that select specific node sets
> from a collection, a document or the whole database and you can even use
> the XQuery update facility to insert or update nodes.
>
> Eric
>
>> I want to perform queries , to select/insert/update/delete certain parts of
>> files from eXist database. And the documentation on xmldb processors is
>> incomplete.
>>
>> --
>> View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/using-the-xml-db-API-in-XPL-datasource-xml-tp4655360p4655423.html
>> Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.
>> pièce jointe document texte brut (message-footer.txt)
>> --
>> You receive this message as a subscriber of the [hidden email] mailing list.
>> To unsubscribe: mailto:[hidden email]
>> For general help: mailto:[hidden email]?subject=help
>> OW2 mailing lists service home page: http://www.ow2.org/wws
>
>
>
> --
> You receive this message as a subscriber of the [hidden email] mailing list.
> To unsubscribe: mailto:[hidden email]
> For general help: mailto:[hidden email]?subject=help
> OW2 mailing lists service home page: http://www.ow2.org/wws


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: using the xml:db API in XPL - datasource.xml

Vlad
Where does the xquery have to be put ? In the request input of the xforms:submission processor ?
An example would be great .
Or if there is any documentation available on this , please post a link.
Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: using the xml:db API in XPL - datasource.xml

Gerrit Boers
Hi Vlad,


the xquery needs to be in de exist database, make sure it is executable ( see: http://www.exist-db.org/exist/devguide_xquery.xml )

In your submission the resource points to the xquery. In this example the variable $art-exist contains the URL to the database ( e.g. http://localhost:8877).

 <xforms:submission id="save-decor-dataset" ref="instance('dataset-instance')" resource="{$art-exist}/modules/save-decor-dataset.xquery" method="post" replace="instance"
           
 xxforms:username="{xxforms:get-session-attribute('username')}" xxforms:password="{xxforms:get-session-attribute('password')}">
           
<xforms:message ev:event="xforms-submit-error" level="modal">A submission error occurred: <xforms:output value="event('error-type')"/>
              
<xforms:output value="event('response-body')"/>
           
</xforms:message>
        
</xforms:submission>

the save-decor-dataset.xquery starts with retrieving the data form the post request (in this example the root element of the posted xml is 'dataset'):

let $editedDataset := request:get-data()/dataset


This works because of a very nice feature of the exist database: If the URL of an HTTP request points to an xquery, the query will be executed and the result will be returned.

hope this helps

regards,

Gerrit

On Jul 4, 2012, at 11:45 AM, Vlad wrote:

Where does the xquery have to be put ? In the request input of the
xforms:submission processor ?
An example would be great .
Or if there is any documentation available on this , please post a link.
Thanks!

--
View this message in context: http://orbeon-forms-ops-users.24843.n4.nabble.com/using-the-xml-db-API-in-XPL-datasource-xml-tp4655360p4655427.html
Sent from the Orbeon Forms (ops-users) mailing list archive at Nabble.com.

--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: [hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws



--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: using the xml:db API in XPL - datasource.xml

Vlad
Thanks for the answers . Maybe I'll ultimately try this method (if I can't do it in other ways) , even though it seems a little too complex to me , for some simple CRUD operations . I didn't even install a separate eXist database by now , I'm working with the built-in one.

So I insist :

is there a way of selecting/updating/inserting/deleting from certain files in the eXist database with the xmldb or xquery processors ? Preferably without storing the queries in eXist , just writing XQuery in XPL.

Thanks again.
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Re: using the xml:db API in XPL - datasource.xml

Erik Bruchez
Administrator
> So I insist :
>
> is there a way of selecting/updating/inserting/deleting from certain files
> in the eXist database with the xmldb or xquery processors ? Preferably
> without storing the queries in eXist , just writing XQuery in XPL.

Looking at the source code:

https://github.com/orbeon/orbeon-forms/blob/master/src/java/org/orbeon/oxf/processor/xmldb/XMLDBProcessor.java

there is a "resource-id" attribute which you can put at the same level
as the "collection" and "create-collection" attributes. Something to
try.

-Erik


--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: Re: using the xml:db API in XPL - datasource.xml (my solution to the problem)

Vlad
Thanks.
Finally , I used resource-id attribute to implement what I wanted , but only for selecting(xmldb-query) and updating(xmldb-update)

For inserting a new element , I aggregated it with the rest of the content of the resource (retrieved by a query) and then made a submission to the resource.

For deleting an element , I submitted to the resource its own content without that certain element (this data also retrieved by performing a query)


This is the solution I found for the "CRUD" operations in eXist . If anybody else has found others , you are welcome to post them here.

Another question related to this topic : how can there be checked if a resource exists (in eXist database for example) ?