<?xml version="1.0" encoding="UTF-8"?>
<!--

    The contents of this file are subject to the license and copyright
    detailed in the LICENSE and NOTICE files at the root of the source
    tree and available online at

    http://www.dspace.org/license/

-->

<!--

  The Workflow the workflow process, and finally ingesting the new items into the
  DSpace repository.

-->
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">

  <map:components>
    <map:transformers>
      <!--<map:transformer name="Navigation" src="org.dspace.app.xmlui.aspect.submission.Navigation"/>-->
      <map:transformer name="Submissions" src="org.dspace.app.xmlui.aspect.workflow.Submissions"/>
      <map:transformer name="RejectTaskStep" src="org.dspace.app.xmlui.aspect.workflow.RejectTaskStep"/>
      <map:transformer name="PerformTaskStep" src="org.dspace.app.xmlui.aspect.workflow.PerformTaskStep"/>
    </map:transformers>

    <map:selectors>
      <map:selector name="AuthenticatedSelector" src="org.dspace.app.xmlui.aspect.general.AuthenticatedSelector"/>
    </map:selectors>

    <map:matchers default="wildcard">
      <map:matcher name="HandleTypeMatcher" src="org.dspace.app.xmlui.aspect.general.HandleTypeMatcher"/>
      <map:matcher name="HandleAuthorizedMatcher" src="org.dspace.app.xmlui.aspect.general.HandleAuthorizedMatcher"/>
      <map:matcher name="regexp" src="org.apache.cocoon.matching.RegexpURIMatcher"/>
    </map:matchers>

    <map:actions>
      <map:action name="ClaimTasksAction" src="org.dspace.app.xmlui.aspect.workflow.ClaimTasksAction"/>
      <map:action name="UnclaimTasksAction" src="org.dspace.app.xmlui.aspect.workflow.UnclaimTasksAction"/>
    </map:actions>

  </map:components>


  <map:flow language="javascript">
    <map:script src="workflow.js"/>
  </map:flow>

  <map:pipelines>
    <map:pipeline>

      <!-- Make sure the user is atleast logged in -->
      <map:select type="AuthenticatedSelector">
        <map:when test="eperson">

          <!--
              There are two major flows that are present in the submissions & workflow
              aspects, one for new submissions to the repository, and another for reviewing
              those submissions in a 3-stage workflow processes. Below are the starting
              points and re-entry points for those workflows.

              /submit               -> New submissions that have not selected a collection yet.
              /handle/*/*/submit    -> Submitting a new item to the repository..
              /handle/*/*/workflow  -> Performing workflow tasks to review submissions
              -->
          <!-- Workflow task "flow" -->
          <map:match pattern="handle/*/*/workflow">
            <map:match type="request" pattern="submission-continue">
              <map:call continuation="{1}"/>
            </map:match>
            <map:call function="doWorkflow"/>
          </map:match>


          <map:generate/>


          <!--<map:transform type="Navigation"/>-->


          <!--
              The submissions page provides a list of all submission
              related tasks/items/thingys. It is used by both those
              who are submitting new items to dspace and those who are
              reviewing those submissions.
              -->
          <map:match pattern="submissions">

            <map:match type="request" pattern="submit_take_tasks">
              <map:act type="ClaimTasksAction"/>
            </map:match>

            <map:match type="request" pattern="submit_return_tasks">
              <map:act type="UnclaimTasksAction"/>
            </map:match>

            <map:transform type="Submissions"/>
          </map:match>


          <!--

              Flow pages Steps

              -->
          <map:match type="WildcardParameterMatcher" pattern="true">
            <map:parameter name="parameter-name" value="flow"/>
            <map:parameter name="flow" value="{flow-attribute:flow}"/>


            <!--  Workflow related steps -->

            <!--
                This step will display the item and present the user
                with a set of options such as approve or reject the item,
                in some cases the user may also edit the item's metadata.
                -->
            <map:match pattern="handle/*/*/workflow/performTaskStep">
              <map:transform type="PerformTaskStep">
                <map:parameter name="id" value="{flow-attribute:id}"/>
                <map:parameter name="step" value="{flow-attribute:step}"/>
              </map:transform>
            </map:match>

            <!--
                This step will ask the user for a reason why they are
                rejecting the item.
                -->
            <map:match pattern="handle/*/*/workflow/rejectTaskStep">
              <map:transform type="RejectTaskStep">
                <map:parameter name="id" value="{flow-attribute:id}"/>
                <map:parameter name="step" value="{flow-attribute:step}"/>
              </map:transform>
            </map:match>

          </map:match> <!-- flow match-->

          <map:serialize type="xml"/>

        </map:when>
        <map:otherwise>

          <!-- non-authenticated users -->
          <map:generate/>

          <!--
              If the user is going to the submissions page and they are
              not logged in then ask them to login first. This will also
              handle cases where user's sessions are timed out, after logging
              back in they will be able to resume their flow.
              -->
          <map:match pattern="submissions">
            <map:act type="StartAuthentication"/>
          </map:match>

          <map:match pattern="handle/*/*/workflow">
            <map:act type="StartAuthentication"/>
          </map:match>

          <map:serialize/>

        </map:otherwise>
      </map:select>

    </map:pipeline>
  </map:pipelines>


</map:sitemap>
