comparison artifacts/src/main/java/org/dive4elements/river/artifacts/datacage/Recommendations.java @ 9232:5030c46d8cb4

Implemented xpath function that selectes the 'mean year' of a fixation-artifact. Needs to provide the ArtifactDatabase to the builder implementation.
author gernotbelger
date Fri, 06 Jul 2018 13:09:54 +0200
parents 468d9ebda4ce
children 1d59da89b00d
comparison
equal deleted inserted replaced
9231:082e8e808902 9232:5030c46d8cb4
29 29
30 import org.hibernate.Session; 30 import org.hibernate.Session;
31 import org.hibernate.SessionFactory; 31 import org.hibernate.SessionFactory;
32 32
33 import org.hibernate.jdbc.Work; 33 import org.hibernate.jdbc.Work;
34 34 import org.dive4elements.artifacts.CallContext;
35 import org.dive4elements.artifacts.common.utils.Config; 35 import org.dive4elements.artifacts.common.utils.Config;
36 import org.dive4elements.artifacts.common.utils.XMLUtils; 36 import org.dive4elements.artifacts.common.utils.XMLUtils;
37 import org.dive4elements.artifacts.common.utils.StringUtils; 37 import org.dive4elements.artifacts.common.utils.StringUtils;
38 38
39 import org.dive4elements.river.artifacts.D4EArtifact; 39 import org.dive4elements.river.artifacts.D4EArtifact;
173 173
174 174
175 /** 175 /**
176 * Append recommendations to \param result. 176 * Append recommendations to \param result.
177 * @param extraParameters parameters (typical example: 'recommended') 177 * @param extraParameters parameters (typical example: 'recommended')
178 * @param context
178 */ 179 */
179 public void recommend( 180 public void recommend(
180 D4EArtifact artifact, 181 D4EArtifact artifact,
181 String userId, 182 String userId,
182 String [] outs, 183 String [] outs,
183 Map<String, Object> extraParameters, 184 Map<String, Object> extraParameters,
184 Node result 185 Node result,
186 final CallContext context
185 ) { 187 ) {
186 Map<String, Object> parameters = new HashMap<String, Object>(); 188 Map<String, Object> parameters = new HashMap<String, Object>();
187 189
188 if (extraParameters != null) { 190 if (extraParameters != null) {
189 convertKeysToUpperCase(extraParameters, parameters); 191 convertKeysToUpperCase(extraParameters, parameters);
199 201
200 parameters.put("ARTIFACT-OUTS", StringUtils.toUpperCase(outs)); 202 parameters.put("ARTIFACT-OUTS", StringUtils.toUpperCase(outs));
201 203
202 parameters.put("PARAMETERS", parameters); 204 parameters.put("PARAMETERS", parameters);
203 205
204 recommend(parameters, userId, result); 206 recommend(parameters, userId, result, context);
205 } 207 }
206 208
207 209
208 /** 210 /**
209 * Append recommendations to \param result. 211 * Append recommendations to \param result.
212 * @param context
210 */ 213 */
211 public void recommend( 214 public void recommend( final Map<String, Object> parameters, final String userId, final Node result, final CallContext context ) {
212 Map<String, Object> parameters, 215 recommend(parameters, userId, result, SessionHolder.HOLDER.get(), context);
213 String userId, 216 }
214 Node result 217
215 ) { 218 public void recommend( final Map<String, Object> parameters, final String userId, final Node result, final Session systemSession, final CallContext context ) {
216 recommend(parameters, userId, result, SessionHolder.HOLDER.get());
217 }
218
219 public void recommend(
220 final Map<String, Object> parameters,
221 final String userId,
222 final Node result,
223 Session systemSession
224 ) {
225 systemSession.doWork(new Work() { 219 systemSession.doWork(new Work() {
226 @Override 220 @Override
227 public void execute(final Connection systemConnection) 221 public void execute(final Connection systemConnection)
228 throws SQLException 222 throws SQLException
229 { 223 {
235 sedDBSession.doWork(new Work() { 229 sedDBSession.doWork(new Work() {
236 @Override 230 @Override
237 public void execute(Connection sedDBConnection) 231 public void execute(Connection sedDBConnection)
238 throws SQLException 232 throws SQLException
239 { 233 {
240 recommend( 234 recommend( parameters, userId, result, systemConnection, sedDBConnection, context);
241 parameters, userId, result,
242 systemConnection,
243 sedDBConnection);
244 } 235 }
245 }); 236 });
246 } 237 }
247 finally { 238 finally {
248 sedDBSession.close(); 239 sedDBSession.close();
250 } 241 }
251 }); 242 });
252 } 243 }
253 244
254 public void recommend( 245 public void recommend(
255 Map<String, Object> parameters, 246 final Map<String, Object> parameters,
256 String userId, 247 final String userId,
257 Node result, 248 final Node result,
258 Connection systemConnection, 249 final Connection systemConnection,
259 Connection seddbConnection 250 final Connection seddbConnection,
251 final CallContext context
260 ) throws SQLException 252 ) throws SQLException
261 { 253 {
262 List<Builder.NamedConnection> connections = 254 List<Builder.NamedConnection> connections =
263 new ArrayList<Builder.NamedConnection>(3); 255 new ArrayList<Builder.NamedConnection>(3);
264 256
283 if (userConnection != null) { 275 if (userConnection != null) {
284 connections.add(new Builder.NamedConnection( 276 connections.add(new Builder.NamedConnection(
285 CONNECTION_USER, userConnection, false)); 277 CONNECTION_USER, userConnection, false));
286 } 278 }
287 279
288 getBuilderPool().build(connections, result, parameters); 280 getBuilderPool().build(connections, result, parameters, context);
289 } 281 }
290 finally { 282 finally {
291 if (userConnection != null) { 283 if (userConnection != null) {
292 userConnection.close(); 284 userConnection.close();
293 } 285 }

http://dive4elements.wald.intevation.org