1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.crm.service.daemon;
35
36 import fr.paris.lutece.plugins.crm.business.demand.Demand;
37 import fr.paris.lutece.plugins.crm.business.demand.DemandFilter;
38 import fr.paris.lutece.plugins.crm.business.demand.DemandType;
39 import fr.paris.lutece.plugins.crm.business.demand.DemandTypeFilter;
40 import fr.paris.lutece.plugins.crm.service.demand.DemandService;
41 import fr.paris.lutece.plugins.crm.service.demand.DemandTypeService;
42 import fr.paris.lutece.plugins.crm.util.OperatorEnum;
43 import fr.paris.lutece.plugins.crm.util.constants.CRMConstants;
44 import fr.paris.lutece.portal.service.daemon.Daemon;
45 import fr.paris.lutece.portal.service.util.AppPropertiesService;
46
47 import java.util.Calendar;
48 import java.util.GregorianCalendar;
49
50
51
52
53
54
55 public class DemandCleanerDaemon extends Daemon
56 {
57
58
59
60 public void run( )
61 {
62 int nExpirationDays = AppPropertiesService.getPropertyInt( CRMConstants.PROPERTY_DAEMON_NB_EXPIRATION_DAYS, 7 );
63 Calendar calendar = new GregorianCalendar( );
64 calendar.add( Calendar.DATE, -nExpirationDays );
65
66
67 DemandTypeFilteriness/demand/DemandTypeFilter.html#DemandTypeFilter">DemandTypeFilter dtFilter = new DemandTypeFilter( );
68 dtFilter.setDateEnd( calendar.getTime( ) );
69 dtFilter.setOperatorDateEnd( OperatorEnum.LOWER_OR_EQUAL );
70
71 for ( DemandType demandType : DemandTypeService.getService( ).findByFilter( dtFilter ) )
72 {
73 DemandFilterm/business/demand/DemandFilter.html#DemandFilter">DemandFilter dFilter = new DemandFilter( );
74 dFilter.setIdDemandType( demandType.getIdDemandType( ) );
75
76 dFilter.setIdStatusCRM( 0 );
77
78 for ( Demand demand : DemandService.getService( ).findByFilter( dFilter ) )
79 {
80 DemandService.getService( ).removeWithItsResource( demand.getIdDemand( ), true );
81 }
82 }
83
84
85 for ( DemandType demandType : DemandTypeService.getService( ).findNoDateEndDemandTypes( ) )
86 {
87 DemandFilterm/business/demand/DemandFilter.html#DemandFilter">DemandFilter dFilter = new DemandFilter( );
88 dFilter.setIdDemandType( demandType.getIdDemandType( ) );
89
90 dFilter.setIdStatusCRM( 0 );
91 dFilter.setDateModification( calendar.getTime( ) );
92 dFilter.setOperatorDateModification( OperatorEnum.LOWER_OR_EQUAL );
93
94 for ( Demand demand : DemandService.getService( ).findByFilter( dFilter ) )
95 {
96 DemandService.getService( ).removeWithItsResource( demand.getIdDemand( ), true );
97 }
98 }
99 }
100 }