<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/webflow
      http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

  <secured attributes="ROLE_USER, ROLE_ADMIN"/>

  <on-start>
    <set name="flowScope.communityCode" value="requestParameters.communityCode"/>
    <set name="requestScope.threadId" value="requestParameters.threadId" type="int"/>
    <set name="requestScope.entryCode" value="requestParameters.entryCode"/>
    <set name="requestScope.user" value="externalContext.requestMap._user"/>
    <set name="flowScope.community" value="communityTable.findByCode(communityCode)"/>
    <set name="flowScope.thread" value="community.getThread(threadId)"/>
    <evaluate expression="thread.findEntryByEntryCodeForWrite(entryCode, user).delete()"/>
  </on-start>

  <decision-state id="decision">
    <if test="community.class.simpleName == 'SingleThreadCommunity'" then="singleThreadView"/>
    <if test="community.class.simpleName == 'MultiThreadCommunity'" then="multiThreadView"/>
  </decision-state>

  <end-state id="singleThreadView" view="externalRedirect:contextRelative:/community/${flowScope.community.code}/index.html"/>
  <end-state id="multiThreadView" view="externalRedirect:contextRelative:/community/${flowScope.community.code}/${flowScope.thread.id}/index.html"/>

</flow>
