Service de requête définie

Les requêtes définies sont des requêtes stockées qui peuvent être exécutées et mises à jour en fonction des besoins.

La fonction des requêtes définies permet aux administrateurs de définir une requête au format XML via le service REST et de la lier à un URI. Cette requête est utilisée pour obtenir les résultats en envoyant une demande GET à l'URI lié.

Créer

Vous pouvez créer une requête définie en envoyant une demande POST à l'URI suivant :
/DefinedQueryComponent/
Par exemple:
HTTP/1.1 POST 
http://host:port/wps/mycontenthandler/wcmrest/DefinedQueryComponent
Content-Type: application/atom+xml
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:wcm="wcm/namespace">
    <atom:title>defined query title-1712115665</atom:title>
    <wcm:name>query-name</wcm:name>
    <wcm:description>defined query description</wcm:description>
</atom:entry>

201 Created
Le format de l'URI lié à cette requête est le suivant :
/definedquery/component-name
Par exemple, l'URI utilisé pour obtenir les résultats de l'exemple de requête précédent est :
/definedquery/query-name
La réponse à une opération de création contient une relation de lien "query-results" qui spécifie cet URI.
<atom:link atom:rel="query-results" 
atom:href="/wps/mycontenthandler/!ut/p/wcmrest/definedquery/query-name"/>
Remarque : Le seul moyen de mettre à jour cet URI consiste à modifier le nom du composant.

Lire

Pour extraire la liste des requêtes définies, envoyez une demande GET à l'URI suivant :
/DefinedQueryComponent/

Par exemple:

HTTP/1.1 GET
http://host:port/wps/mycontenthandler/wcmrest/DefinedQueryComponent
Accept-Type: application/atom+xml

<atom:feed xmlns:atom="http://www.w3.org/2005/Atom" xmlns:wcm="wcm/namespace">
    <atom:title>Custom Queries</atom:title>
    <atom:updated>2011-07-04T01:19:27.126Z</atom:updated>
    <atom:entry>
        <atom:id>wcmrest:a5d4f72f-a7b7-4576-a7d3-5a4e15c66f01</atom:id>
        <wcm:name>query-one-name</wcm:name>
        <atom:title>Query 1</atom:title>
        <atom:updated>2011-07-04T01:19:27.159Z</atom:updated>
        <atom:link atom:rel="query-results" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/definedquery/query-one-name
        <atom:link atom:rel="edit-media" atom:type="application/vnd.ibm.wcm+xml" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/DefinedQueryComponent/a5d4f72f-a7b7-4576-a7d3-5a4e15c66f01"/>
        <atom:link atom:rel="edit" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/DefinedQueryComponent/a5d4f72f-a7b7-4576-a7d3-5a4e15c66f01"/>
    </atom:entry>
    <atom:entry>
        <atom:id>wcmrest:6276ff18-f370-45eb-89c3-053d335aba88</atom:id>
        <atom:title>defined query title-1280236937</atom:title>
        <wcm:name>query-two-name</wcm:name>
        <atom:updated>2011-07-04T01:19:27.167Z</atom:updated>
        <atom:link atom:rel="query-results" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/definedquery/query-two-name"/>
        <atom:link atom:rel="edit-media" atom:type="application/vnd.ibm.wcm+xml" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/DefinedQueryComponent/6276ff18-f370-45eb-89c3-053d335aba88"/>
        <atom:link atom:rel="edit" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/DefinedQueryComponent/6276ff18-f370-45eb-89c3-053d335aba88"/>
    </atom:entry>
</atom:feed>
Pour extraire le code XML d'une requête définie spécifique, envoyez une demande GET à l'URI suivant :
/DefinedQueryComponent/item-uuid
query-name
Par exemple:
HTTP/1.1 GET
http://host:port/wps/mycontenthandler/wcmrest/DefinedQueryComponent/6276ff18-f370-45eb-89c3-053d335aba88
Accept-Type: application/atom+xml

200 OK

<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:wcm="wcm/namespace">
    <atom:id>wcmrest:6276ff18-f370-45eb-89c3-053d335aba88</atom:id>
    <wcm:type>DefinedQueryComponent</wcm:type>
    <atom:title>defined query title-1460391124</atom:title>
    <wcm:name>query-name</wcm:name>
    <atom:updated>2011-07-04T01:34:01.051Z</atom:updated>
    <wcm:description>defined query description</wcm:description>
    <atom:link atom:rel="edit" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/DefinedQueryComponent/6276ff18-f370-45eb-89c3-053d335aba88"/>
    <atom:link atom:rel="edit-media" atom:type="application/vnd.ibm.wcm+xml" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/DefinedQueryComponent/6276ff18-f370-45eb-89c3-053d335aba88"/>
    <atom:link atom:rel="query-results" atom:href="/wps/mycontenthandler/!ut/p/wcmrest/definedquery/query-name"/>
</atom:entry>
Pour extraire les données brutes d'une requête définie spécifique, envoyez une demande GET à la relation de lien edit-media :
/DefinedQueryComponent/item-id
Par exemple:
HTTP/1.1 GET
http://host:port/wps/mycontenthandler/wcmrest/DefinedQueryComponent/items-id
Accept-Type: application/vnd.ibm.wcm+xml

200 OK

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definedQuery restrictParameters="true" page="1" pageSize="10" depth="DESCENDANTS">
    <select>
        <typeEquals>
            <type>com.ibm.workplace.wcm.api.Content</type>
        </typeEquals>
        <nameLike>
            <name>article%</name>
        </nameLike>
        <titleLike>
            <title>product%</title>
        </titleLike>
    </select>
    <allowParameters>
        <parameter>lastmodifiedbefore</parameter>
        <parameter>workflowid</parameter>
        <parameter>createdbefore</parameter>
        <parameter>authoringtemplateid</parameter>
    </allowParameters>
</definedQuery>

Mettre à jour

Pour mettre à jour les métadonnées d'une requête, envoyez une demande PUT contenant la nouvelle spécification à l'URI suivant :
/DefinedQueryComponent/item-uuid
Par exemple:
HTTP/1.1 PUT
http://host:port/wps/mycontenthandler/wcmrest/DefinedQueryComponent/6276ff18-f370-45eb-89c3-053d335aba88
Content-Type: application/atom+xml
(… atom data … )

200 OK
Pour mettre à jour les données brutes d'une requête qui spécifie les paramètres utilisés pour exécuter la requête, envoyez une demande PUT contenant la nouvelle spécification à l'URI suivant :
/DefinedQueryComponent/item-uuid
Par exemple:
HTTP/1.1 PUT
http://host:port/wps/mycontenthandler/wcmrest/DefinedQueryComponent/6276ff18-f370-45eb-89c3-053d335aba88
Content-Type: application/vnd.ibm.wcm+xml
(… xml data … )

200 OK

Supprimer

Pour supprimer une requête définie, envoyez une demande DELETE à l'URI suivant :
/DefinedQueryComponent/item-id
Par exemple:
HTTP/1.1 DELETE
http://host:port/wps/mycontenthandler/wcmrest/definedquery/6276ff18-f370-45eb-89c3-053d335aba88

200 OK

Liste blanche

La liste blanche est une liste de paramètres de requête supplémentaires pouvant être utilisés pour affiner la portée de la requête définie. Il s'agit des seuls paramètres ayant un effet lorsqu'ils sont ajoutés à l'URI lié.

Par exemple, si la liste blanche inclut le paramètre name, la demande suivante renvoie les résultats de la requête définie dont le nom est "hello world" :
HTTP/1.1 GET
http://host:port/wps/mycontenthandler/wcmrest/query-name?name=hello+world

200 OK