forked from GeoCat/daobs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
daobs-task-routes.xml
228 lines (196 loc) · 9.93 KB
/
daobs-task-routes.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="bridgePropertyPlaceholder"
class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/config.properties"/>
</bean>
<bean id="pagination" class="org.daobs.routing.utility.Pagination">
<property name="recordsPerPage" value="${task.data-indexer.records.per.page}"/>
</bean>
<bean id="utility" class="org.daobs.routing.utility.Utility"/>
<bean id="dataIndexer" class="org.daobs.tasks.DataIndexer"/>
<bean id="urlEncoder" class="java.net.URLEncoder"/>
<cm:errorHandler id="loggingErrorHandler"
type="LoggingErrorHandler"
logName="daobs.tasks.data-indexer"
level="DEBUG"/>
<cm:camelContext
id="task.data-indexer"
errorHandlerRef="loggingErrorHandler"
useMDCLogging="true">
<cm:threadPoolProfile id="myDefaultProfile"
defaultProfile="true"
poolSize="10"
maxPoolSize="10"/>
<cm:onException>
<cm:exception>org.apache.camel.component.http4.HttpOperationFailedException</cm:exception>
<cm:continued>
<cm:constant>true</cm:constant>
</cm:continued>
<cm:log message="Oops, something went wrong: $simple{exception.message}."
loggingLevel="ERROR"
logName="org.daobs.task.DataIndexer"/>
<cm:log message="$simple{exception.responseBody}"
loggingLevel="ERROR"
logName="org.daobs.task.DataIndexer"/>
<cm:log message="$simple{exception.stacktrace}"
loggingLevel="ERROR"
logName="org.daobs.task.DataIndexer"/>
<cm:to uri="log:org.daobs.task.DataIndexer?showBody=true"/>
</cm:onException>
<cm:route id="route-data-indexer-run-cli" autoStartup="{{task.data-indexer.startup.cli}}">
<cm:from uri="timer://start?repeatCount=1"/>
<cm:setHeader headerName="documentFilter">
<cm:simple>{{task.data-indexer.filter}}</cm:simple>
</cm:setHeader>
<cm:to uri="direct:data-indexer-start"/>
</cm:route>
<cm:route id="route-data-indexer-run-jms" autoStartup="{{task.data-indexer.startup.jms}}">
<cm:from uri="activemq:data-indexer"/>
<cm:setHeader headerName="documentFilter">
<cm:groovy>'{{task.data-indexer.filter}}' + ' ' + exchange.in.body</cm:groovy>
</cm:setHeader>
<cm:to uri="direct:data-indexer-start"/>
</cm:route>
<!--<cm:route id="route-data-indexer-reset">
<cm:description>
Reset data field.
</cm:description>
</cm:route>-->
<cm:route id="route-data-indexer-start">
<cm:description>
</cm:description>
<cm:from uri="direct:data-indexer-start"/>
<cm:log message="Background task indexing related data ..."
loggingLevel="INFO"
logName="org.daobs.task.DataIndexer"/>
<!-- Get number of records to validate -->
<cm:setHeader headerName="CamelHttpMethod">
<cm:constant>GET</cm:constant>
</cm:setHeader>
<cm:setHeader headerName="Exchange.HTTP_URI">
<cm:simple>{{solr.server.url}}/{{solr.server.core}}/select?q=$simple{header.documentFilter}&fl={{task.data-indexer.fields}}&wt=xml&start=0&rows=0</cm:simple>
</cm:setHeader>
<cm:to uri="http4://solr.server.url?authUsername={{solr.server.user}}&authPassword={{solr.server.password}}&authenticationPreemptive=true&throwExceptionOnFailure=false"/>
<cm:convertBodyTo type="org.w3c.dom.Document"/>
<cm:setHeader headerName="numberOfRecordsMatched">
<cm:xpath resultType="java.lang.String">
//result/@numFound
</cm:xpath>
</cm:setHeader>
<cm:log message="$simple{header.numberOfRecordsMatched} record(s) with data to index."
loggingLevel="INFO"
logName="org.daobs.task.DataIndexer"/>
<cm:split parallelProcessing="false">
<cm:method bean="pagination" method="getPages"/>
<cm:setHeader headerName="start">
<cm:simple>${bean:pagination?method=getStart}</cm:simple>
</cm:setHeader>
<cm:setHeader headerName="row">
<cm:simple>{{task.data-indexer.records.per.page}}</cm:simple>
</cm:setHeader>
<cm:log message="Page #$simple{property.CamelSplitIndex} - start: $simple{header.start} | row: $simple{header.row}."
loggingLevel="INFO"
logName="org.daobs.task.DataIndexer"/>
<cm:setHeader headerName="CamelHttpMethod">
<cm:constant>GET</cm:constant>
</cm:setHeader>
<cm:setHeader headerName="Exchange.HTTP_URI">
<cm:simple>{{solr.server.url}}/{{solr.server.core}}/select</cm:simple>
</cm:setHeader>
<cm:setHeader headerName="Exchange.HTTP_QUERY">
<cm:groovy>'q=' + URLEncoder.encode(exchange.in.headers.documentFilter, 'UTF-8') +
'&fl={{task.data-indexer.fields}}&wt=xml&sort=id+desc&start=' + exchange.in.headers.start + '&rows=' + exchange.in.headers.row</cm:groovy>
</cm:setHeader>
<cm:to uri="http4://solr.server.url?authUsername={{solr.server.user}}&authPassword={{solr.server.password}}&authenticationPreemptive=true&throwExceptionOnFailure=false"/>
<cm:convertBodyTo type="org.w3c.dom.Document"/>
<cm:split parallelProcessing="true">
<cm:xpath>//doc</cm:xpath>
<!-- Retrieve UUID from Solr response -->
<cm:setHeader headerName="documentIdentifier">
<cm:xpath resultType="java.lang.String">doc/str[@name = 'id']</cm:xpath>
</cm:setHeader>
<cm:log message="Record identifier is '$simple{header.documentIdentifier}'."
loggingLevel="INFO"
logName="org.daobs.task.DataIndexer"/>
<cm:setBody>
<cm:xpath>doc/arr[@name = 'link']</cm:xpath>
</cm:setBody>
<cm:split parallelProcessing="false">
<cm:xpath>//str</cm:xpath>
<cm:to uri="direct:analyse-link"/>
</cm:split>
</cm:split>
</cm:split>
</cm:route>
<cm:route id="route-analyse-link">
<cm:from uri="direct:analyse-link"/>
<cm:setHeader headerName="beginTime">
<cm:simple>${date:now:yyyyMMdd'T'HH':'mm':'SS}</cm:simple>
</cm:setHeader>
<cm:convertBodyTo type="org.w3c.dom.Document"/>
<cm:log message="Record '$simple{header.documentIdentifier}' contains link '${body}' for document '$simple{header.documentIdentifier}'. Start at $simple{header.beginTime}."
loggingLevel="INFO"
logName="org.daobs.task.DataIndexer"/>
<cm:bean ref="dataIndexer" method="splitLink"/>
<cm:log message="Analyzing URL '$simple{header.linkUrl}', protocol '$simple{header.linkProtocol}', name '$simple{header.linkName}', description '$simple{header.linkDescription}'."
loggingLevel="INFO"
logName="org.daobs.task.DataIndexer"/>
<cm:setHeader headerName="stringToEncrypt">
<cm:simple>$simple{header.linkUrl}</cm:simple>
</cm:setHeader>
<cm:setHeader headerName="fileNameSuffix">
<cm:simple>bean:utility?method=encrypt</cm:simple>
</cm:setHeader>
<!-- TODO: Tika works fine for most of the format (eg. XLS, PDF, ZIP)
but for WFS specific processing should be done. -->
<cm:bean ref="dataIndexer" method="parseDocument"/>
<cm:log message="Extracted content '${body}'."
loggingLevel="INFO"
logName="org.daobs.task.DataIndexer"/>
<cm:setBody>
<cm:simple>
<![CDATA[<add commitWithin="10000">
<doc>
<field name="id"><![CDATA[$simple{header.documentIdentifier}]]><![CDATA[]]]]><![CDATA[>]]><![CDATA[</field>
<field name="analyzeddocument" update="add">$simple{header.linkUrl}</field>
<field name="documenttext" update="add">
<![CDATA[${body}]]><![CDATA[]]]]><![CDATA[>]]><![CDATA[
</field>
</doc>
</add>]]>
</cm:simple>
</cm:setBody>
<!-- TODO: Then we should try to create features depening on the
file type. A row in an excel document, a feature in a WFS response... -->
<cm:to uri="file:{{task.data-indexer.folder}}?fileName=document-data-$simple{header.fileNameSuffix}.xml&charset=utf-8"/>
</cm:route>
<cm:route id="route-index-data">
<!--<cm:from uri="direct:save-validation-status"/>-->
<cm:from uri="file:{{task.data-indexer.folder}}?consumer.delay={{task.data-indexer.delay}}"/>
<cm:log message="Updating index with '$simple{body}' ..."
loggingLevel="INFO"
logName="org.daobs.task.DataIndexer"/>
<cm:setHeader headerName="Exchange.HTTP_URI">
<cm:simple>{{solr.server.url}}/{{solr.server.core}}/update</cm:simple>
</cm:setHeader>
<cm:setHeader headerName="camelHttpMethod">
<cm:constant>POST</cm:constant>
</cm:setHeader>
<cm:setHeader headerName="Content-Type">
<cm:constant>application/xml</cm:constant>
</cm:setHeader>
<cm:to uri="http4://solr.server.url?authUsername={{solr.server.user}}&authPassword={{solr.server.password}}&authenticationPreemptive=true&throwExceptionOnFailure=false"/>
<cm:log message="Solr response: ${body}."
loggingLevel="DEBUG"
logName="org.daobs.task.DataIndexer"/>
</cm:route>
</cm:camelContext>
</beans>