build_get_wfs.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns:ogc="http://www.opengis.net/ogc"
  3. basedir="../../." name="get_wfs" default="http_first_input">
  4. <description>
  5. Based on ant-url-action module to ordinary retrieve feature from WMF
  6. To be called from CRM_PROCES_Tree etc
  7. </description>
  8. <!-- file:/SE/schema/ant-url_action/default_db.in7_dziennik_koresp/test-get-wfs-xml/build.xml -->
  9. <!-- sample URL which call this exact variables in this ANT build -->
  10. <!-- przykladowy URL ktory przekazuje parametry do tego ANT -->
  11. <!--https://biuro.biall-net.pl/SE/version-git/index.php?_route=UrlAction_Ant&_task=ant&
  12. path=${default_db.in7_dziennik_koresp/test-get-wfs-xml} - this is the place to keep ant build (directory name with build.xml)
  13. &namespace=p5_default_db:Rozdzielcza_test_bzyk_PE&featureID=123 - this is setting the <property name="url" value="${url}"/> - to point what is record/table to download
  14. <property name="uuid" value="${uuid}"/> it is automatically also set to enable uinque transaction and to allow to save data with user
  15. <property name="passwordBase64Basic" value="${passwordBase64Basic}"/> - this is also set - to enable communicate with API -
  16. <property name="DwebRootUrl" value="${$webRootUrl}"/> - this is the place where script is localized to easyli to target user GUI by href to generated output
  17. />
  18. -->
  19. <!-- modules WPS_Functions - to be copied to any module needed -->
  20. <property name="WPS_Functions" location="${basedir}/WPS_Functions"/>
  21. <property name="build_WPS_Functions.xml" location="${WPS_Functions}/build_WPS_Functions.xml"/> <!-- call it to get properties -->
  22. <property name="build_WPS_Functions.xml.properties" location="${build_WPS_Functions.xml}.properties"/>
  23. <!-- eof modules WPS_Functions -->
  24. <!-- module local properties -->
  25. <property name="get_wfs_basedir" location="${basedir}/WPS_Functions/get_wfs"/><!-- to ordinary retrieve wfs data -->
  26. <property name="get_wfs_basedir.temp" location="${get_wfs_basedir}/temp"/>
  27. <property name="get_wfs" location="${get_wfs_basedir}/build_get_wfs.xml"/><!-- to ordinary retrieve wfs data -->
  28. <property name="build_get_wfs.childproperties" location="${WPS_Functions.childproperties}/build_get_wfs.properties"/>
  29. <property name="uuid" value="${uuid}"/>
  30. <property name="wfs_output.xml" location="${get_wfs_basedir.temp}/${uuid}.wfs_output.xml"/>
  31. <property name="wfs_result.xml" location="${get_wfs_basedir.temp}/${uuid}.wfs_result.xml"/>
  32. <property name="wfs_error.xml" location="${get_wfs_basedir.temp}/${uuid}.wfs_error.xml"/>
  33. <property name="wfs_timestamp.xml" location="${get_wfs_basedir.temp}/${uuid}.wfs_timestamp.xml"/>
  34. <!-- for sending xml - param inputs -->
  35. <property name="wfs_input.xml" location="${get_wfs_basedir.temp}/${uuid}.wfs_input.xml"/>
  36. <!-- eof module local properties -->
  37. <property name="passwordBase64Basic" value="${passwordBase64Basic}"/>
  38. <!--<property name="url" value="${url}"/>-->
  39. <!--<property name="api_url" value="${api_url}"/>-->
  40. <property name="typeName" value="${typeName}" />
  41. <property name="xpath" value="${xpath}"/>
  42. <property name="xpath_value" value="${xpath_value}" />
  43. <property name="php_session_id" value="${php_session_id}"/>
  44. <property name="webRootUrl" value="${webRootUrl}"/>
  45. <target name="write_child_props_to_config_dir" depends="read_build_properties">
  46. <echoproperties destfile="${build_get_wfs.childproperties}"/>
  47. </target>
  48. <target name="read_build_properties" >
  49. <ant antfile="${build_WPS_Functions.xml}" target="save_build_properties"/>
  50. <loadproperties srcfile="${build_WPS_Functions.xml.properties}"/>
  51. <echo level="debug">$api_url to ${api_url} $namespace_prefix ${namespace_prefix}
  52. passwordBase64Basic=${passwordBase64Basic}
  53. </echo>
  54. </target>
  55. <target name="clean" description="Clean all output and temp files">
  56. <delete dir="${get_wfs_basedir.temp}" failonerror="false"/>
  57. </target>
  58. <target name="create_tempdir">
  59. <mkdir dir="${get_wfs_basedir.temp}"/>
  60. </target>
  61. <target name="http_first_input">
  62. <echo message="FETCHING '${url}' ..."/>
  63. <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
  64. <arg line="--cookie 'PHPSESSID=${php_session_id}' '${url}&amp;REQUEST=GetFeature'"/>
  65. </exec>
  66. <echo message="OUTPUT__TYPE__XML"/>
  67. <echo message="OUTPUT__START"/>
  68. <echo message="${wfs_output}"/>
  69. <echo message="webRootUrl"></echo>
  70. <echo message="${webRootUrl}"></echo>
  71. <echo message="OUTPUT__END"/>
  72. <echo message="RESULT__START"/>
  73. <echo message="${wfs_result}"/>
  74. <echo message="RESULT__END"/>
  75. <echo message="ERROR__START"/>
  76. <echo message="${wfs_error}"/>
  77. <echo message="ERROR__END"/>
  78. </target>
  79. <target name="DescribeFeatureType" description="URL_TASK Target DescribeFeatureType">
  80. <echo message="FETCHING '${url}' ..." level="debug"/>
  81. <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
  82. <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' &#34;${url}&amp;REQUEST=DescribeFeatureType&#34;"/>
  83. </exec>
  84. <echo message="OUTPUT__TYPE__XML"/>
  85. <echo message="OUTPUT__START"/>
  86. <echo message="${wfs_output}"/>
  87. <echo message="webRootUrl"></echo>
  88. <echo message="${webRootUrl}"></echo>
  89. <echo message="OUTPUT__END"/>
  90. <echo message="RESULT__START"/>
  91. <echo message="${wfs_result}"/>
  92. <echo message="RESULT__END"/>
  93. <echo message="ERROR__START"/>
  94. <echo message="${wfs_error}"/>
  95. <echo message="ERROR__END"/>
  96. </target>
  97. <target name="Filter_cond">
  98. <condition property="Filter_cond" taskname="Filter_check">
  99. <or>
  100. <equals arg1="${xpath}" arg2=""/>
  101. <equals arg1="${xpath}" arg2="$${uuid}"/>
  102. </or>
  103. </condition>
  104. </target>
  105. <target name="Filter_check" depends="Filter_cond,Filter_fail,Filter_ok"/>
  106. <target name="Filter_ok" unless="${Filter_cond}">
  107. <!--<mkdir dir="${get_wfs_basedir.temp}"/>
  108. <tempfile destdir="${get_wfs_basedir.temp}" suffix=".xml" prefix="Filter_ok" property="Filter.xml"/>
  109. <echoxml file="${Filter.xml}"></echoxml>
  110. <loadfile property="Filter.xml_file" srcfile="${Filter.xml}"/>-->
  111. <property name="Filter" value="&amp;Filter=&lt;ogc:Filter&gt;&lt;ogc:PropertyIsEqualTo&gt;&lt;ogc:PropertyName&gt;${xpath}&lt;/ogc:PropertyName&gt;&lt;ogc:Literal&gt;${xpath_value}&lt;/ogc:Literal&gt;&lt;/ogc:PropertyIsEqualTo&gt;&lt;/ogc:Filter&gt;"/>
  112. </target>
  113. <target name="Filter_fail" if="${Filter_cond}">
  114. <echo level="debug">#94 filter not set</echo>
  115. </target>
  116. <target name="GetFeature" description="URL_TASK Target GetFeature" depends="read_build_properties,Filter_check">
  117. <property name="get_url" value="${api_url}/${namespace_prefix}?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=GetFeature&amp;typeName=${typeName}&amp;${Filter}"/>
  118. <echo message="FETCHING '${get_url}'" /> <!-- level="debug" -->
  119. <tstamp>
  120. <format property="wfs.timestamp" pattern="yyyy-MM-dd HH:mm:ss"/>
  121. </tstamp>
  122. <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
  123. <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' '${get_url}'"/><!-- ${Filter} -->
  124. </exec>
  125. <!--<echo message="${wfs_output}" />-->
  126. <echo file="${wfs_output.xml}" message="${wfs_output}"/>
  127. <echo file="${wfs_result.xml}" message="${wfs_result}"/>
  128. <echo file="${wfs_error.xml}" message="${wfs_error}"/>
  129. <echoxml file="${wfs_timestamp.xml}"><wfs_timestamp>${wfs.timestamp}</wfs_timestamp></echoxml>
  130. </target>
  131. <target name="PostXmlTransaction" description="TODO to post transaction based on build__for_post_to_wfs and curl_post_wfst">
  132. <exec executable="$curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result" failonerror="true">
  133. <arg value="-H 'Authorization: Basic ${passwordBase64Basic_tested}'"/>
  134. <arg value="-X"/>
  135. <arg value="POST"/>
  136. <arg value="-d"/>
  137. <arg value="${wfs_input.xml}"/>
  138. <arg value="${api_url}"/>
  139. <!--<arg value="-\-user {$Types__x3A__wfs:username}:{$Types__x3A__wfs:username-pass} "/>-->
  140. <arg value="-v"/>
  141. <arg value="--insecure"/>
  142. <!--<arg value="-O"/>
  143. <arg value="{@Target_file}"/>-->
  144. </exec>
  145. <echo file="${wfs_output.xml}" message="${wfs_output}"/>
  146. <echo file="${wfs_result.xml}" message="${wfs_result}"/>
  147. <echo file="${wfs_error.xml}" message="${wfs_error}"/>
  148. </target>
  149. <target name="GetFeatureByLastMod" description="URL_TASK Target GetFeatureByLastMod - should do incremental retrievement" depends="read_build_properties,Filter_check"/>
  150. <target name="GetXmlByUrlVerifyRetry" description="To use from recruse ant and be verified">
  151. <!--<echo>GetXmlByUrlVerifyRetry #154 we used </echo>-->
  152. <exec executable="curl" output="${output}" errorproperty="wfs_error">
  153. <arg line="${cookie_curl_option} &quot;${url}&quot;"/>
  154. <arg line="--connect-timeout 5"/>
  155. <arg line="--max-time 240"/>
  156. <arg line="--retry 5"/>
  157. <arg line="--retry-max-time 1200"/>
  158. </exec>
  159. <!--<echo message="ERROR__START"/>-->
  160. <!--<echo>${wfs_error}</echo>-->
  161. <!--<echo message="ERROR__END"/>-->
  162. <antcall target="GetXmlByUrlVerifyRetry.validate_length"/>
  163. <!--<antcall target="GetXmlByUrlVerifyRetry_verify"/>
  164. <echo> Validate $GetXmlByUrlVerifyRetry_verify: ${GetXmlByUrlVerifyRetry_verify}</echo>
  165. <echo> Validate $warn: ${warn}</echo>-->
  166. </target>
  167. <target name="GetXmlByUrlVerifyRetry.validate_length.condition" description="To verify if downloaded file is correct" >
  168. <length file="${output}" property="output.length"/>
  169. <!--<echo> $output.length = ${output.length}</echo>-->
  170. <condition property="output.length.failed" taskname="GetXmlByUrlVerifyRetry.validate_length">
  171. <equals arg1="${output.length}" arg2="128"/>
  172. </condition>
  173. <condition property="output.length.failed.0" taskname="GetXmlByUrlVerifyRetry.validate_length.0">
  174. <equals arg1="${output.length}" arg2="0"/>
  175. </condition>
  176. </target>
  177. <target name="GetXmlByUrlVerifyRetry.validate_length" depends="GetXmlByUrlVerifyRetry.validate_length.condition">
  178. <antcall target="GetXmlByUrlVerifyRetry.validate_length.failed"/>
  179. <antcall target="GetXmlByUrlVerifyRetry.validate_length.failed.0"/>
  180. </target>
  181. <target name="GetXmlByUrlVerifyRetry.validate_length.failed" if="${output.length.failed}">
  182. <echo>GetXmlByUrlVerifyRetry.validate_length.failed #182 - first retry ! </echo>
  183. <delete file="${output}" quiet="true"/>
  184. <exec executable="curl" output="${output}" errorproperty="wfs_error">
  185. <arg line="${cookie_curl_option} &quot;${url}&quot;"/>
  186. <arg line="--connect-timeout 5"/>
  187. <arg line="--max-time 240"/>
  188. <arg line="--retry 5"/>
  189. <arg line="--retry-max-time 1200"/>
  190. </exec>
  191. <length file="${output}" property="output.length.try1"/>
  192. <echo> $output.length.try1 = ${output.length.try1}</echo>
  193. </target>
  194. <target name="GetXmlByUrlVerifyRetry.validate_length.failed.0" if="${output.length.failed.0}">
  195. <echo>GetXmlByUrlVerifyRetry.validate_length.failed #198 - first retry - zero length ! </echo>
  196. <delete file="${output}" quiet="true"/>
  197. <exec executable="curl" output="${output}" errorproperty="wfs_error">
  198. <arg line="${cookie_curl_option} &quot;${url}&quot;"/>
  199. <arg line="--connect-timeout 5"/>
  200. <arg line="--max-time 240"/>
  201. <arg line="--retry 5"/>
  202. <arg line="--retry-max-time 1200"/>
  203. </exec>
  204. <length file="${output}" property="output.length.try.0"/>
  205. <echo> $output.length.try.0 = ${output.length.try.0}</echo>
  206. </target>
  207. <target name="GetXmlByUrlVerifyRetry_verify" description="To verify if downloaded file is correct" >
  208. <xmlvalidate file="${output}" lenient="yes" failonerror="false" warn="warn" />
  209. <echo>#169 after validated ? not set any?</echo>
  210. </target>
  211. <target name="GetFeature.WithVerifyUnauthorized" depends="GetFeature"> <!-- GetFeature.VerifyUnauthorized.failed -->
  212. <loadfile property="GetFeature.WithVerifyUnauthorized.srcfile" srcfile="${wfs_output.xml}" />
  213. <condition property="GetFeature.VerifyUnauthorized.condition" taskname="GetFeature.VerifyUnauthorized.failed">
  214. <contains string="${GetFeature.WithVerifyUnauthorized.srcfile}" substring="Unauthorized" />
  215. </condition>
  216. </target>
  217. <target name="GetFeature.VerifyUnauthorized.failed" if="${GetFeature.VerifyUnauthorized.condition}">
  218. <fail>
  219. #258 Cannot properly download ${get_url}
  220. Propably unset -DpasswordBase64Basic parameter!
  221. generate it with :
  222. echo "username:password" |base64
  223. </fail>
  224. </target>
  225. <!-- @2017-12-14 copied from recurse_ant to be there only! -->
  226. <target name="php_session_id_cond">
  227. <condition property="php_session_id_fail" taskname="php_session_id_check">
  228. <or>
  229. <equals arg1="${php_session_id}" arg2=""/>
  230. <equals arg1="${php_session_id}" arg2="$${php_session_id}"/>
  231. </or>
  232. </condition>
  233. </target>
  234. <target name="php_session_id_check" depends="php_session_id_cond,php_session_id_ok,php_session_id_fail" description="To create property php_session_id_tested for use in api calls"/>
  235. <target name="php_session_id_ok" unless="${php_session_id_fail}" description="use php_session_id from parameter ">
  236. <property name="php_session_id_tested" value="--cookie 'PHPSESSID=${php_session_id}'"/>
  237. </target>
  238. <target name="php_session_id_fail" if="${php_session_id_fail}" description="retrieve php_session_id from API to use it after for fasten api requests" depends="read_build_properties,create_tempdir">
  239. <tempfile destdir="${get_wfs_basedir.temp}" prefix="usernameandpass" deleteonexit="yes" property="username_and_pass_from_passwordBase64Basic.properties" />
  240. <ant antfile="${build_username_and_pass_from_passwordBase64Basic.xml}" target="username_and_pass_from_passwordBase64Basic.properties"/>
  241. <loadproperties srcfile="${username_and_pass_from_passwordBase64Basic.properties}"/>
  242. <echo> retrieved $username=${username}
  243. php_session_id_check.properties=${php_session_id_check.properties}
  244. $api_url = ${api_url}
  245. </echo>
  246. <!-- retrieve new properties -username , username.pass -->
  247. <property name="cookie_file" value="${get_wfs_basedir.temp}/${username}.cookie"/>
  248. <!--<property name="cookie_file" value="${get_wfs_basedir.temp}/${username}.cookie"/>-->
  249. <delete file="${cookie_file}" failonerror="no"/>
  250. <exec executable="curl"> <!-- errorproperty="wfs_error" resultproperty="wfs_result" -->
  251. <arg line=" -c ${cookie_file} -H 'Authorization: Basic ${passwordBase64Basic_tested}' &#34;${api_url}&#34;"/> <!-- /default_db/?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=GetCapabilities&#34; -->
  252. </exec>
  253. <echo> runned: curl -c ${cookie_file} -H 'Authorization: Basic ${passwordBase64Basic_tested}' &#34;${api_url}&#34;</echo>
  254. <property name="php_session_id_tested" value=" -b ${cookie_file}"/>
  255. <!-- detecting from cookie file just phpsesssid string
  256. # Netscape HTTP Cookie File
  257. # https://curl.haxx.se/docs/http-cookies.html
  258. # This file was generated by libcurl! Edit at your own risk.
  259. biuro.biall-net.pl FALSE / FALSE 0 PHPSESSID ndosk8faaskrfvdcbge8ki571l0oukdqtg7bmjht43b0cslohpbua2g5ouoi3b2vm6l14avvgna8bq6j6ufranhu77mtjplc1dthat2
  260. -->
  261. <loadfile property="php_session_id_tested.loadfile" srcfile="${cookie_file}" />
  262. <exec executable="bash" outputproperty="php_session_id_ok.string" >
  263. <arg value="-c" />
  264. <arg value="echo '${php_session_id_tested.loadfile}'|grep PHPSESSID |sed 's/.*PHPSESSID[ |\t]*//'"/>
  265. </exec>
  266. <property name="php_session_id_ok.string.test" value="test"/>
  267. <echo> #289 we set php_session_id_tested=(${php_session_id_tested})
  268. $php_session_id_ok.string = ${php_session_id_ok.string};
  269. $cookie_file = ${cookie_file}
  270. $username = ${username}
  271. </echo>
  272. </target>
  273. <target name="php_session_id_check.properties" depends="php_session_id_check">
  274. <echo>#329 saving properties to ${php_session_id_check.properties}</echo>
  275. <echoproperties destfile="${php_session_id_check.properties}" regex="(php_session_id_ok*)|(username*)"/>
  276. </target>
  277. </project>