Skip to content

Commit

Permalink
Ajout d'un cheduler pour anonymiser les tables de demandes
Browse files Browse the repository at this point in the history
  • Loading branch information
jusabatier committed Mar 3, 2023
1 parent 1a0235e commit 529c2ca
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,11 @@ public interface RequestRepository
@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")
int sumObjectNumberByUserCniAndUserTypeAndRequestDateAfter(String cni, String type, Date date);


/**
* Return all informationRequest done before the specified date
*
* @param date The date to use
* @return The list of informationRequest done before the date
*/
List<InformationRequest> findAllByRequestDateBefore(Date date);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.georchestra.cadastrapp.scheduler;

import java.util.Calendar;
import java.util.List;

import org.georchestra.cadastrapp.model.request.InformationRequest;
import org.georchestra.cadastrapp.model.request.ObjectRequest;
import org.georchestra.cadastrapp.repository.ObjectRequestRepository;
import org.georchestra.cadastrapp.repository.RequestRepository;
import org.georchestra.cadastrapp.repository.UserRequestRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("anonymizationSchedulerBean")
public class AnonymizationScheduler {
@Autowired
RequestRepository requestRepository;

@Autowired
ObjectRequestRepository objectRequestRepository;

@Autowired
UserRequestRepository userRequestRepository;

public void anonymize() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
List<InformationRequest> ls = requestRepository.findAllByRequestDateBefore(cal.getTime());
for (InformationRequest informationRequest : ls) {
for (ObjectRequest objectRequest : informationRequest.getObjectsRequest()) {
objectRequestRepository.delete(objectRequest);

This comment has been minimized.

Copy link
@pierrejego

pierrejego Jul 3, 2023

Member

En fait on anonymise pas mais on purge.

}
userRequestRepository.delete(informationRequest.getUser());

This comment has been minimized.

Copy link
@pierrejego

pierrejego Jul 3, 2023

Member

ici on supprime potentiellement un utilisateur qui aurait une autre demande en cours de moins de 30 jours

}
}
}
12 changes: 11 additions & 1 deletion cadastrapp/src/main/webapp/WEB-INF/beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.3.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.3.xsd">

<context:component-scan base-package="org.georchestra.cadastrapp" />
<mvc:annotation-driven />
Expand Down Expand Up @@ -144,4 +146,12 @@
</property>
</bean>

<!-- ============================= -->
<!-- Request's database Anonymization -->
<!-- 0 0 0 L * * => last day of the month at midnight -->
<!-- ============================= -->
<task:scheduled-tasks scheduler="anonymizationScheduler">
<task:scheduled ref="anonymizationSchedulerBean" method="anonymize" cron="0 0 0 L * *" />
</task:scheduled-tasks>
<task:scheduler id="anonymizationScheduler"/>
</beans>
6 changes: 3 additions & 3 deletions database/sql/tables/request_information.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ALTER TABLE #schema_cadastrapp.request_information
ALTER TABLE #schema_cadastrapp.request_information
ADD CONSTRAINT foreingKeyUserId FOREIGN KEY (userid)
REFERENCES #schema_cadastrapp.request_user_information (userid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
ON UPDATE NO ACTION ON DELETE CASCADE;

ALTER TABLE #schema_cadastrapp.request_information
OWNER TO #user_cadastrapp;
Expand Down Expand Up @@ -93,12 +93,12 @@ ALTER TABLE #schema_cadastrapp.request_information_object_request
ALTER TABLE #schema_cadastrapp.request_information_object_request
ADD CONSTRAINT foreingKeyRequestObjectRequestId FOREIGN KEY (request_information_requestid)
REFERENCES #schema_cadastrapp.request_information (requestid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
ON UPDATE NO ACTION ON DELETE CASCADE;

ALTER TABLE #schema_cadastrapp.request_information_object_request
ADD CONSTRAINT foreingKeyRequestObjectRequestObjectId FOREIGN KEY (objectsrequest_objectid)
REFERENCES #schema_cadastrapp.object_request (objectid) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
ON UPDATE NO ACTION ON DELETE CASCADE;

ALTER TABLE #schema_cadastrapp.request_information_object_request
ADD CONSTRAINT request_information_object_request_objectsrequest_objectid_key UNIQUE (objectsrequest_objectid );
Expand Down

0 comments on commit 529c2ca

Please sign in to comment.