build_get_wfs.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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="http_first_input">
  59. <echo message="FETCHING '${url}' ..."/>
  60. <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
  61. <arg line="--cookie 'PHPSESSID=${php_session_id}' '${url}&amp;REQUEST=GetFeature'"/>
  62. </exec>
  63. <echo message="OUTPUT__TYPE__XML"/>
  64. <echo message="OUTPUT__START"/>
  65. <echo message="${wfs_output}"/>
  66. <echo message="webRootUrl"></echo>
  67. <echo message="${webRootUrl}"></echo>
  68. <echo message="OUTPUT__END"/>
  69. <echo message="RESULT__START"/>
  70. <echo message="${wfs_result}"/>
  71. <echo message="RESULT__END"/>
  72. <echo message="ERROR__START"/>
  73. <echo message="${wfs_error}"/>
  74. <echo message="ERROR__END"/>
  75. </target>
  76. <target name="DescribeFeatureType" description="URL_TASK Target DescribeFeatureType">
  77. <echo message="FETCHING '${url}' ..." level="debug"/>
  78. <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
  79. <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' &#34;${url}&amp;REQUEST=DescribeFeatureType&#34;"/>
  80. </exec>
  81. <echo message="OUTPUT__TYPE__XML"/>
  82. <echo message="OUTPUT__START"/>
  83. <echo message="${wfs_output}"/>
  84. <echo message="webRootUrl"></echo>
  85. <echo message="${webRootUrl}"></echo>
  86. <echo message="OUTPUT__END"/>
  87. <echo message="RESULT__START"/>
  88. <echo message="${wfs_result}"/>
  89. <echo message="RESULT__END"/>
  90. <echo message="ERROR__START"/>
  91. <echo message="${wfs_error}"/>
  92. <echo message="ERROR__END"/>
  93. </target>
  94. <target name="Filter_cond">
  95. <condition property="Filter_cond" taskname="Filter_check">
  96. <or>
  97. <equals arg1="${xpath}" arg2=""/>
  98. <equals arg1="${xpath}" arg2="$${uuid}"/>
  99. </or>
  100. </condition>
  101. </target>
  102. <target name="Filter_check" depends="Filter_cond,Filter_fail,Filter_ok"/>
  103. <target name="Filter_ok" unless="${Filter_cond}">
  104. <!--<mkdir dir="${get_wfs_basedir.temp}"/>
  105. <tempfile destdir="${get_wfs_basedir.temp}" suffix=".xml" prefix="Filter_ok" property="Filter.xml"/>
  106. <echoxml file="${Filter.xml}"></echoxml>
  107. <loadfile property="Filter.xml_file" srcfile="${Filter.xml}"/>-->
  108. <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;"/>
  109. </target>
  110. <target name="Filter_fail" if="${Filter_cond}">
  111. <echo level="debug">#94 filter not set</echo>
  112. </target>
  113. <target name="GetFeature" description="URL_TASK Target GetFeature" depends="read_build_properties,Filter_check">
  114. <property name="get_url" value="${api_url}/${namespace_prefix}?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=GetFeature&amp;typeName=${typeName}&amp;${Filter}"/>
  115. <echo message="FETCHING '${get_url}'" /> <!-- level="debug" -->
  116. <tstamp>
  117. <format property="wfs.timestamp" pattern="yyyy-MM-dd HH:mm:ss"/>
  118. </tstamp>
  119. <exec executable="curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result">
  120. <arg line="-H 'Authorization: Basic ${passwordBase64Basic}' '${get_url}'"/><!-- ${Filter} -->
  121. </exec>
  122. <!--<echo message="${wfs_output}" />-->
  123. <echo file="${wfs_output.xml}" message="${wfs_output}"/>
  124. <echo file="${wfs_result.xml}" message="${wfs_result}"/>
  125. <echo file="${wfs_error.xml}" message="${wfs_error}"/>
  126. <echoxml file="${wfs_timestamp.xml}"><wfs_timestamp>${wfs.timestamp}</wfs_timestamp></echoxml>
  127. </target>
  128. <target name="PostXmlTransaction" description="TODO to post transaction based on build__for_post_to_wfs and curl_post_wfst">
  129. <exec executable="$curl" outputproperty="wfs_output" errorproperty="wfs_error" resultproperty="wfs_result" failonerror="true">
  130. <arg value="-H 'Authorization: Basic ${passwordBase64Basic_tested}'"/>
  131. <arg value="-X"/>
  132. <arg value="POST"/>
  133. <arg value="-d"/>
  134. <arg value="${wfs_input.xml}"/>
  135. <arg value="${api_url}"/>
  136. <!--<arg value="-\-user {$Types__x3A__wfs:username}:{$Types__x3A__wfs:username-pass} "/>-->
  137. <arg value="-v"/>
  138. <arg value="--insecure"/>
  139. <!--<arg value="-O"/>
  140. <arg value="{@Target_file}"/>-->
  141. </exec>
  142. <echo file="${wfs_output.xml}" message="${wfs_output}"/>
  143. <echo file="${wfs_result.xml}" message="${wfs_result}"/>
  144. <echo file="${wfs_error.xml}" message="${wfs_error}"/>
  145. </target>
  146. <target name="GetFeatureByLastMod" description="URL_TASK Target GetFeatureByLastMod - should do incremental retrievement" depends="read_build_properties,Filter_check"/>
  147. <target name="GetXmlByUrlVerifyRetry" description="To use from recruse ant and be verified">
  148. <!--<echo>GetXmlByUrlVerifyRetry #154 we used </echo>-->
  149. <exec executable="curl" output="${output}" errorproperty="wfs_error">
  150. <arg line="${cookie_curl_option} &quot;${url}&quot;"/>
  151. <arg line="--connect-timeout 5"/>
  152. <arg line="--max-time 240"/>
  153. <arg line="--retry 5"/>
  154. <arg line="--retry-max-time 1200"/>
  155. </exec>
  156. <!--<echo message="ERROR__START"/>-->
  157. <!--<echo>${wfs_error}</echo>-->
  158. <!--<echo message="ERROR__END"/>-->
  159. <antcall target="GetXmlByUrlVerifyRetry.validate_length"/>
  160. <!--<antcall target="GetXmlByUrlVerifyRetry_verify"/>
  161. <echo> Validate $GetXmlByUrlVerifyRetry_verify: ${GetXmlByUrlVerifyRetry_verify}</echo>
  162. <echo> Validate $warn: ${warn}</echo>-->
  163. </target>
  164. <target name="GetXmlByUrlVerifyRetry.validate_length.condition" description="To verify if downloaded file is correct" >
  165. <length file="${output}" property="output.length"/>
  166. <!--<echo> $output.length = ${output.length}</echo>-->
  167. <condition property="output.length.failed" taskname="GetXmlByUrlVerifyRetry.validate_length">
  168. <equals arg1="${output.length}" arg2="128"/>
  169. </condition>
  170. <condition property="output.length.failed.0" taskname="GetXmlByUrlVerifyRetry.validate_length.0">
  171. <equals arg1="${output.length}" arg2="0"/>
  172. </condition>
  173. </target>
  174. <target name="GetXmlByUrlVerifyRetry.validate_length" depends="GetXmlByUrlVerifyRetry.validate_length.condition">
  175. <antcall target="GetXmlByUrlVerifyRetry.validate_length.failed"/>
  176. <antcall target="GetXmlByUrlVerifyRetry.validate_length.failed.0"/>
  177. </target>
  178. <target name="GetXmlByUrlVerifyRetry.validate_length.failed" if="${output.length.failed}">
  179. <echo>GetXmlByUrlVerifyRetry.validate_length.failed #182 - first retry ! </echo>
  180. <delete file="${output}" quiet="true"/>
  181. <exec executable="curl" output="${output}" errorproperty="wfs_error">
  182. <arg line="${cookie_curl_option} &quot;${url}&quot;"/>
  183. <arg line="--connect-timeout 5"/>
  184. <arg line="--max-time 240"/>
  185. <arg line="--retry 5"/>
  186. <arg line="--retry-max-time 1200"/>
  187. </exec>
  188. <length file="${output}" property="output.length.try1"/>
  189. <echo> $output.length.try1 = ${output.length.try1}</echo>
  190. </target>
  191. <target name="GetXmlByUrlVerifyRetry.validate_length.failed.0" if="${output.length.failed.0}">
  192. <echo>GetXmlByUrlVerifyRetry.validate_length.failed #198 - first retry - zero length ! </echo>
  193. <delete file="${output}" quiet="true"/>
  194. <exec executable="curl" output="${output}" errorproperty="wfs_error">
  195. <arg line="${cookie_curl_option} &quot;${url}&quot;"/>
  196. <arg line="--connect-timeout 5"/>
  197. <arg line="--max-time 240"/>
  198. <arg line="--retry 5"/>
  199. <arg line="--retry-max-time 1200"/>
  200. </exec>
  201. <length file="${output}" property="output.length.try.0"/>
  202. <echo> $output.length.try.0 = ${output.length.try.0}</echo>
  203. </target>
  204. <target name="GetXmlByUrlVerifyRetry_verify" description="To verify if downloaded file is correct" >
  205. <xmlvalidate file="${output}" lenient="yes" failonerror="false" warn="warn" />
  206. <echo>#169 after validated ? not set any?</echo>
  207. </target>
  208. </project>