1 | /** |
---|
2 | * SynchronizationService Service |
---|
3 | * |
---|
4 | * Description of my service |
---|
5 | * |
---|
6 | * @author your email (+name?) |
---|
7 | * @since 2010mmdd |
---|
8 | * @package ??? |
---|
9 | * |
---|
10 | * Revision information: |
---|
11 | * $Rev: 1442 $ |
---|
12 | * $Author: robert@isdat.nl $ |
---|
13 | * $Date: 2011-01-26 17:02:05 +0100 (Wed, 26 Jan 2011) $ |
---|
14 | */ |
---|
15 | package dbnp.modules |
---|
16 | |
---|
17 | import nl.grails.plugins.gdt.* |
---|
18 | import dbnp.studycapturing.* |
---|
19 | |
---|
20 | class ModuleNotificationService implements Serializable { |
---|
21 | boolean transactional = false |
---|
22 | |
---|
23 | /** |
---|
24 | * Sends a notification to assay modules that some part of a study has changed. |
---|
25 | * |
---|
26 | * Only modules that have the notify flag set to true will be notified. They will be notified on the URL |
---|
27 | * |
---|
28 | * [moduleUrl]/rest/notifyStudyChange?studyToken=abc |
---|
29 | * |
---|
30 | * Errors that occur when calling this URL are ignored. The module itself is responsible of |
---|
31 | * maintaining a synchronized state. |
---|
32 | * |
---|
33 | * @param study |
---|
34 | * @return |
---|
35 | */ |
---|
36 | def invalidateStudy( Study study ) { |
---|
37 | if( !study ) |
---|
38 | return |
---|
39 | |
---|
40 | log.info( "Invalidate " + study.code ) |
---|
41 | |
---|
42 | def modules = AssayModule.findByNotify(true); |
---|
43 | |
---|
44 | def urls = [] |
---|
45 | modules.each { module -> |
---|
46 | urls << module.url + '/rest/notifyStudyChange?studyToken=' + study.giveUUID() |
---|
47 | } |
---|
48 | |
---|
49 | Thread.start { |
---|
50 | urls.each { url -> |
---|
51 | try { |
---|
52 | def connection = url.toURL().openConnection() |
---|
53 | if( connection.responseCode == 200 ) { |
---|
54 | log.info( "GSCF NOTIFY-CALL SUCCEEDED: ${url}" ) |
---|
55 | } else { |
---|
56 | log.info( "GSCF NOTIFY-CALL FAILED: ${url}: " + connection.responseCode ) |
---|
57 | } |
---|
58 | } catch( Exception ignore) { |
---|
59 | log.info( "GSCF NOTIFY-CALL ERROR: ${url} - " + ignore.getMessage() ) |
---|
60 | } |
---|
61 | } |
---|
62 | }; |
---|
63 | } |
---|
64 | } |
---|