File tree 4 files changed +57
-5
lines changed
java/org/georchestra/cadastrapp
4 files changed +57
-5
lines changed Original file line number Diff line number Diff line change @@ -56,5 +56,11 @@ public interface RequestRepository
56
56
@ Query (value ="select COALESCE(SUM(ir.objectNumber),0) from InformationRequest ir inner join ir.user u where u.cni= ?1 and u.type = ?2 and ir.requestDate >= ?3" )
57
57
int sumObjectNumberByUserCniAndUserTypeAndRequestDateAfter (String cni , String type , Date date );
58
58
59
-
59
+ /**
60
+ * Return all informationRequest done before the specified date
61
+ *
62
+ * @param date The date to use
63
+ * @return The list of informationRequest done before the date
64
+ */
65
+ List <InformationRequest > findAllByRequestDateBefore (Date date );
60
66
}
Original file line number Diff line number Diff line change
1
+ package org .georchestra .cadastrapp .scheduler ;
2
+
3
+ import java .util .Calendar ;
4
+ import java .util .List ;
5
+
6
+ import org .georchestra .cadastrapp .model .request .InformationRequest ;
7
+ import org .georchestra .cadastrapp .model .request .ObjectRequest ;
8
+ import org .georchestra .cadastrapp .repository .ObjectRequestRepository ;
9
+ import org .georchestra .cadastrapp .repository .RequestRepository ;
10
+ import org .georchestra .cadastrapp .repository .UserRequestRepository ;
11
+ import org .springframework .beans .factory .annotation .Autowired ;
12
+ import org .springframework .stereotype .Component ;
13
+
14
+ @ Component ("anonymizationSchedulerBean" )
15
+ public class AnonymizationScheduler {
16
+ @ Autowired
17
+ RequestRepository requestRepository ;
18
+
19
+ @ Autowired
20
+ ObjectRequestRepository objectRequestRepository ;
21
+
22
+ @ Autowired
23
+ UserRequestRepository userRequestRepository ;
24
+
25
+ public void anonymize () {
26
+ Calendar cal = Calendar .getInstance ();
27
+ cal .add (Calendar .MONTH , -1 );
28
+ List <InformationRequest > ls = requestRepository .findAllByRequestDateBefore (cal .getTime ());
29
+ for (InformationRequest informationRequest : ls ) {
30
+ for (ObjectRequest objectRequest : informationRequest .getObjectsRequest ()) {
31
+ objectRequestRepository .delete (objectRequest );
32
+ }
33
+ userRequestRepository .delete (informationRequest .getUser ());
34
+ }
35
+ }
36
+ }
Original file line number Diff line number Diff line change 6
6
xmlns:tx=" http://www.springframework.org/schema/tx"
7
7
xmlns:jpa=" http://www.springframework.org/schema/data/jpa"
8
8
xmlns:mvc=" http://www.springframework.org/schema/mvc"
9
+ xmlns : task =" http://www.springframework.org/schema/task"
9
10
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
10
11
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
11
12
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
12
13
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
13
14
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
14
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd" >
15
+ http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
16
+ http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd" >
15
17
16
18
<context : component-scan base-package =" org.georchestra.cadastrapp" />
17
19
<mvc : annotation-driven />
144
146
</property >
145
147
</bean >
146
148
149
+ <!-- ============================= -->
150
+ <!-- Request's database Anonymization -->
151
+ <!-- 0 0 0 L * * => last day of the month at midnight -->
152
+ <!-- ============================= -->
153
+ <task : scheduled-tasks scheduler =" anonymizationScheduler" >
154
+ <task : scheduled ref =" anonymizationSchedulerBean" method =" anonymize" cron =" 0 0 0 L * *" />
155
+ </task : scheduled-tasks >
156
+ <task : scheduler id =" anonymizationScheduler" />
147
157
</beans >
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ ALTER TABLE #schema_cadastrapp.request_information
51
51
ALTER TABLE # schema_cadastrapp.request_information
52
52
ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid)
53
53
REFERENCES # schema_cadastrapp.request_user_information (userid) MATCH SIMPLE
54
- ON UPDATE NO ACTION ON DELETE NO ACTION ;
54
+ ON UPDATE NO ACTION ON DELETE CASCADE ;
55
55
56
56
ALTER TABLE # schema_cadastrapp.request_information
57
57
OWNER TO # user_cadastrapp;
@@ -93,12 +93,12 @@ ALTER TABLE #schema_cadastrapp.request_information_object_request
93
93
ALTER TABLE # schema_cadastrapp.request_information_object_request
94
94
ADD CONSTRAINT foreingKeyRequestObjectRequestId FOREIGN KEY (request_information_requestid)
95
95
REFERENCES # schema_cadastrapp.request_information (requestid) MATCH SIMPLE
96
- ON UPDATE NO ACTION ON DELETE NO ACTION ;
96
+ ON UPDATE NO ACTION ON DELETE CASCADE ;
97
97
98
98
ALTER TABLE # schema_cadastrapp.request_information_object_request
99
99
ADD CONSTRAINT foreingKeyRequestObjectRequestObjectId FOREIGN KEY (objectsrequest_objectid)
100
100
REFERENCES # schema_cadastrapp.object_request (objectid) MATCH SIMPLE
101
- ON UPDATE NO ACTION ON DELETE NO ACTION ;
101
+ ON UPDATE NO ACTION ON DELETE CASCADE ;
102
102
103
103
ALTER TABLE # schema_cadastrapp.request_information_object_request
104
104
ADD CONSTRAINT request_information_object_request_objectsrequest_objectid_key UNIQUE (objectsrequest_objectid );
You can’t perform that action at this time.
0 commit comments