Dixit Singla
Dixit Singla

Reputation: 2620

MarkLogic CPF not performing an action on document delete

I am using MarkLogic CPF.

I have configured CPF for the below 3 states

http://marklogic.com/states/initial

http://marklogic.com/states/updated

http://marklogic.com/states/deleted

Everything is working fine when initial & updated states

but when I delete a document CPF is not executing the configured module.

please find below the pipeline configuration (pasted only for deleted state)

<state-transition>
    <annotation>
            when document is deleted in 'abc' collection
    </annotation>
    <state>http://marklogic.com/states/deleted</state>
    <on-success>http://marklogic.com/states/done</on-success>
    <on-failure>http://marklogic.com/states/error</on-failure>
    <execute>
        <condition>
            <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
            <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
                <root-element>head</root-element>
                <namespace>https://www.head.org/Schema/head/hd</namespace>
            </options>
        </condition>
        <action>
            <module>delete-record.xqy</module>
        </action>
    </execute>
</state-transition>

CPF is configured for abc collection.

When I delete a document with root node as head with namespace as https://www.head.org/Schema/head/hd

delete-record.xqy module is not getting executed.

Please help me to find the issue, If need more detail please let me know.

Update:

Complete pipeline configuration

<pipeline xmlns="http://marklogic.com/cpf/pipelines">
    <pipeline-name>Combined Search</pipeline-name>
    <pipeline-description>Make a single copy</pipeline-description>
    <success-action>
        <module>/MarkLogic/cpf/actions/success-action.xqy</module>
    </success-action>
    <failure-action>
        <module>/MarkLogic/cpf/actions/failure-action.xqy</module>
    </failure-action>
    <state-transition>
        <annotation>
            on creation
        </annotation>
        <state>http://marklogic.com/states/initial</state>
        <on-success>http://marklogic.com/states/done</on-success>
        <on-failure>http://marklogic.com/states/error</on-failure>
        <execute>
            <condition>
                <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
                <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
                    <root-element>head</root-element>
                    <namespace>https://www.head.org/Schema/head/hd
                    </namespace>
                </options>
            </condition>
            <action>
                <module>create-full-record.xqy</module>
            </action>
        </execute>
    </state-transition>
    <state-transition>
        <annotation>
            on update
        </annotation>
        <state>http://marklogic.com/states/updated</state>
        <on-success>http://marklogic.com/states/done</on-success>
        <on-failure>http://marklogic.com/states/error</on-failure>
        <execute>
            <condition>
                <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
                <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
                    <root-element>head</root-element>
                    <namespace>https://www.head.org/Schema/head/hd
                    </namespace>
                </options>
            </condition>
            <action>
                <module>update-record-biblio.xqy</module>
            </action>
        </execute>
        <execute>
            <condition>
                <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
                <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
                    <root-element>media</root-element>
                    <namespace>https://www.media.org/Schema/Media/md</namespace>
                </options>
            </condition>
            <action>
                <module>update-media.xqy</module>
            </action>
        </execute>
        <execute>
            <condition>
                <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
                <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
                    <root-element>tracking</root-element>
                    <namespace>https://www.tracking.org/Schema/Tracking/tr</namespace>
                </options>
            </condition>
            <action>
                <module>update-tracking.xqy</module>
            </action>
        </execute>
    </state-transition>
    <status-transition>
        <annotation>
            on deletion
        </annotation>
        <status>deleted</status>
        <on-success>http://marklogic.com/states/done</on-success>
        <on-failure>http://marklogic.com/states/error</on-failure>
        <always>true</always>
        <execute>
            <condition>
                <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
                <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
                    <root-element>head</root-element>
                    <namespace>https://www.head.org/Schema/head/hd
                    </namespace>
                </options>
            </condition>
            <action>
                <module>delete-record.xqy</module>
            </action>
        </execute>
    </status-transition>
</pipeline>

No action is performed on document creation, updation & deletetion. Please help me to find the mistakes I am doing.

I have attached two pipelines to the domain.

above one & Status Change Handling

Update:

Analysis:

I put a log in namespace-condition.xqy file. On deleting a document above file will be called and When I checked the fn:doc-available($cpf:document-uri) it is returning me false. which means the doc is already gone (deleted) hence no trigger.

For status-transition & state-transition it is not working, please help me to understand the mistake and how I can resolve it.

Upvotes: 0

Views: 255

Answers (2)

mholstege
mholstege

Reputation: 4912

Do you have the Status Change Handling pipeline attached to your domain? It is the one responsible for handling the status events of creation and update to set those states so that the state transitions can respond.

Upvotes: 0

mholstege
mholstege

Reputation: 4912

The state names are not in themselves meaningful. If you look at the definitions in the Status Change Handling pipeline you'll see that it happens to set the state to http://marklogic.com/states/initial on a creation (and similarly for an update), but for deletion it doesn't set the state, it runs an action. If you want your own actions in response to a deletion you'll need a status transition, not a state transition. Something like:

<status-transition>
  <annotation>
  Do some extra work.
  </annotation>
  <status>deleted</status>
  <priority>5000</priority>
  <always>true</always>     
  <execute>
    <condition>
        <module>/MarkLogic/cpf/actions/namespace-condition.xqy</module>
        <options xmlns="/MarkLogic/cpf/actions/namespace-condition.xqy">
            <root-element>head</root-element>
            <namespace>https://www.head.org/Schema/head/hd</namespace>
        </options>
    </condition>
    <action>
        <module>delete-record.xqy</module>
    </action>
</execute>

The "always" says to do this in addition to the normal deletion processing in the status change handling pipeline.

Upvotes: 2

Related Questions