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.appointmentgru.services;
35
36 import java.util.List;
37
38 import org.apache.commons.lang.StringUtils;
39
40 import fr.paris.lutece.plugins.appointment.business.appointment.Appointment;
41 import fr.paris.lutece.plugins.appointment.service.AppointmentResponseService;
42 import fr.paris.lutece.plugins.appointmentgru.business.AppointmentGru;
43 import fr.paris.lutece.plugins.genericattributes.business.Entry;
44 import fr.paris.lutece.plugins.genericattributes.business.EntryHome;
45 import fr.paris.lutece.plugins.genericattributes.business.Response;
46 import fr.paris.lutece.plugins.modulenotifygrumappingmanager.business.NotifygruMappingManager;
47 import fr.paris.lutece.plugins.modulenotifygrumappingmanager.business.NotifygruMappingManagerHome;
48 import fr.paris.lutece.portal.service.spring.SpringContextService;
49 import fr.paris.lutece.portal.service.util.AppLogService;
50
51
52
53
54 public class AppointmentGruService
55 {
56
57 public static final String BEAN_NAME = "appointmentgru.appointmentGruService";
58
59
60 private static volatile AppointmentGruService _instance;
61
62
63
64
65
66
67 public static AppointmentGruService getService( )
68 {
69 if ( _instance == null )
70 {
71 _instance = SpringContextService.getBean( BEAN_NAME );
72 }
73
74 return _instance;
75 }
76
77
78
79
80
81
82
83
84
85
86 public AppointmentGru getAppointmentGru( Appointment appointment, String strMappingKey )
87 {
88 AppointmentGru/business/AppointmentGru.html#AppointmentGru">AppointmentGru appointmentGru = new AppointmentGru( appointment );
89 if ( AppLogService.isDebugEnabled( ) )
90 {
91 AppLogService.debug( "AppointmentGru : GUID from appointment Cuid: " + appointment.getGuid( ) );
92 }
93
94
95 if ( appointment != null )
96 {
97 appointmentGru.setGuid( appointment.getGuid( ) );
98
99 String strMobilePhone = getMobilePhoneNumber( appointment, strMappingKey );
100
101 if ( strMobilePhone != null )
102 {
103 appointmentGru.setMobilePhoneNumber( strMobilePhone );
104 }
105 }
106 appointmentGru.setDemandeTypeId( getDemandeTypeId( strMappingKey ) );
107
108 return appointmentGru;
109 }
110
111
112
113
114
115
116
117
118
119
120 private String getMobilePhoneNumber( Appointment appointment, String strMappingKey )
121 {
122 NotifygruMappingManager mapping = NotifygruMappingManagerHome.findByPrimaryKey( strMappingKey );
123 String strPhoneNumber = StringUtils.EMPTY;
124 List<Response> listResponses = AppointmentResponseService.findListResponse( appointment.getIdAppointment( ) );
125
126 if ( mapping != null )
127 {
128 for ( Response response : listResponses )
129 {
130 Entry entry = EntryHome.findByPrimaryKey( response.getEntry( ).getIdEntry( ) );
131
132
133 if ( entry.getFieldDepend( ) == null && entry.getPosition( ) == mapping.getMobilePhoneNumber( ) )
134 {
135 strPhoneNumber = response.getResponseValue( );
136 break;
137 }
138 }
139 }
140 return strPhoneNumber;
141 }
142
143
144
145
146
147
148 private int getDemandeTypeId( String strMappingKey )
149 {
150 NotifygruMappingManager mapping = NotifygruMappingManagerHome.findByPrimaryKey( strMappingKey );
151
152 if ( mapping != null )
153 {
154 return mapping.getDemandeTypeId( );
155 }
156 else
157 {
158 return 0;
159 }
160 }
161 }