Skip to content

Commit 529c2ca

Browse files
committed
Ajout d'un cheduler pour anonymiser les tables de demandes
1 parent 1a0235e commit 529c2ca

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

cadastrapp/src/main/java/org/georchestra/cadastrapp/repository/RequestRepository.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,11 @@ public interface RequestRepository
5656
@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")
5757
int sumObjectNumberByUserCniAndUserTypeAndRequestDateAfter(String cni, String type, Date date);
5858

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);
6066
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

cadastrapp/src/main/webapp/WEB-INF/beans.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
xmlns:tx="http://www.springframework.org/schema/tx"
77
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
88
xmlns:mvc="http://www.springframework.org/schema/mvc"
9+
xmlns:task="http://www.springframework.org/schema/task"
910
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
1011
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
1112
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
1213
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
1314
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">
1517

1618
<context:component-scan base-package="org.georchestra.cadastrapp" />
1719
<mvc:annotation-driven />
@@ -144,4 +146,12 @@
144146
</property>
145147
</bean>
146148

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"/>
147157
</beans>

database/sql/tables/request_information.sql

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ALTER TABLE #schema_cadastrapp.request_information
5151
ALTER TABLE #schema_cadastrapp.request_information
5252
ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid)
5353
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;
5555

5656
ALTER TABLE #schema_cadastrapp.request_information
5757
OWNER TO #user_cadastrapp;
@@ -93,12 +93,12 @@ ALTER TABLE #schema_cadastrapp.request_information_object_request
9393
ALTER TABLE #schema_cadastrapp.request_information_object_request
9494
ADD CONSTRAINT foreingKeyRequestObjectRequestId FOREIGN KEY (request_information_requestid)
9595
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;
9797

9898
ALTER TABLE #schema_cadastrapp.request_information_object_request
9999
ADD CONSTRAINT foreingKeyRequestObjectRequestObjectId FOREIGN KEY (objectsrequest_objectid)
100100
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;
102102

103103
ALTER TABLE #schema_cadastrapp.request_information_object_request
104104
ADD CONSTRAINT request_information_object_request_objectsrequest_objectid_key UNIQUE (objectsrequest_objectid );

0 commit comments

Comments
 (0)