| 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.form.utils; |
| 35 | |
|
| 36 | |
import java.awt.Color; |
| 37 | |
import java.sql.Timestamp; |
| 38 | |
import java.text.DateFormat; |
| 39 | |
import java.util.ArrayList; |
| 40 | |
import java.util.Calendar; |
| 41 | |
import java.util.Collection; |
| 42 | |
import java.util.Date; |
| 43 | |
import java.util.GregorianCalendar; |
| 44 | |
import java.util.HashMap; |
| 45 | |
import java.util.LinkedHashMap; |
| 46 | |
import java.util.List; |
| 47 | |
import java.util.Locale; |
| 48 | |
import java.util.Map; |
| 49 | |
|
| 50 | |
import javax.servlet.http.HttpServletRequest; |
| 51 | |
import javax.servlet.http.HttpServletResponse; |
| 52 | |
import javax.servlet.http.HttpSession; |
| 53 | |
|
| 54 | |
import org.apache.commons.codec.binary.Base64; |
| 55 | |
import org.apache.commons.lang.StringUtils; |
| 56 | |
import org.apache.commons.lang3.math.NumberUtils; |
| 57 | |
import org.jfree.chart.ChartFactory; |
| 58 | |
import org.jfree.chart.JFreeChart; |
| 59 | |
import org.jfree.chart.plot.XYPlot; |
| 60 | |
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; |
| 61 | |
import org.jfree.data.time.Day; |
| 62 | |
import org.jfree.data.time.Month; |
| 63 | |
import org.jfree.data.time.TimeSeries; |
| 64 | |
import org.jfree.data.time.TimeSeriesCollection; |
| 65 | |
import org.jfree.data.time.Week; |
| 66 | |
import org.jfree.data.xy.XYDataset; |
| 67 | |
|
| 68 | |
import fr.paris.lutece.plugins.form.business.Category; |
| 69 | |
import fr.paris.lutece.plugins.form.business.ConditionalEntriesFieldMapper; |
| 70 | |
import fr.paris.lutece.plugins.form.business.Form; |
| 71 | |
import fr.paris.lutece.plugins.form.business.FormFilter; |
| 72 | |
import fr.paris.lutece.plugins.form.business.FormHome; |
| 73 | |
import fr.paris.lutece.plugins.form.business.FormSubmit; |
| 74 | |
import fr.paris.lutece.plugins.form.business.StatisticFormSubmit; |
| 75 | |
import fr.paris.lutece.plugins.form.business.iteration.IterationGroup; |
| 76 | |
import fr.paris.lutece.plugins.form.service.FormPlugin; |
| 77 | |
import fr.paris.lutece.plugins.form.service.draft.FormDraftBackupService; |
| 78 | |
import fr.paris.lutece.plugins.form.service.entrytype.EntryTypeMyLuteceUser; |
| 79 | |
import fr.paris.lutece.plugins.form.service.parameter.FormParameterService; |
| 80 | |
import fr.paris.lutece.plugins.form.web.http.GroupHttpServletRequestWrapper; |
| 81 | |
import fr.paris.lutece.plugins.genericattributes.business.Entry; |
| 82 | |
import fr.paris.lutece.plugins.genericattributes.business.EntryFilter; |
| 83 | |
import fr.paris.lutece.plugins.genericattributes.business.EntryHome; |
| 84 | |
import fr.paris.lutece.plugins.genericattributes.business.EntryType; |
| 85 | |
import fr.paris.lutece.plugins.genericattributes.business.EntryTypeHome; |
| 86 | |
import fr.paris.lutece.plugins.genericattributes.business.Field; |
| 87 | |
import fr.paris.lutece.plugins.genericattributes.business.FieldHome; |
| 88 | |
import fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError; |
| 89 | |
import fr.paris.lutece.plugins.genericattributes.business.Response; |
| 90 | |
import fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeArray; |
| 91 | |
import fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeGroup; |
| 92 | |
import fr.paris.lutece.plugins.genericattributes.service.entrytype.AbstractEntryTypeUpload; |
| 93 | |
import fr.paris.lutece.plugins.genericattributes.service.entrytype.EntryTypeServiceManager; |
| 94 | |
import fr.paris.lutece.plugins.genericattributes.service.entrytype.IEntryTypeService; |
| 95 | |
import fr.paris.lutece.portal.business.file.File; |
| 96 | |
import fr.paris.lutece.portal.business.file.FileHome; |
| 97 | |
import fr.paris.lutece.portal.business.mailinglist.Recipient; |
| 98 | |
import fr.paris.lutece.portal.business.physicalfile.PhysicalFile; |
| 99 | |
import fr.paris.lutece.portal.business.physicalfile.PhysicalFileHome; |
| 100 | |
import fr.paris.lutece.portal.business.user.AdminUser; |
| 101 | |
import fr.paris.lutece.portal.service.captcha.CaptchaSecurityService; |
| 102 | |
import fr.paris.lutece.portal.service.content.XPageAppService; |
| 103 | |
import fr.paris.lutece.portal.service.i18n.I18nService; |
| 104 | |
import fr.paris.lutece.portal.service.mail.MailService; |
| 105 | |
import fr.paris.lutece.portal.service.mailinglist.AdminMailingListService; |
| 106 | |
import fr.paris.lutece.portal.service.plugin.Plugin; |
| 107 | |
import fr.paris.lutece.portal.service.plugin.PluginService; |
| 108 | |
import fr.paris.lutece.portal.service.security.LuteceUser; |
| 109 | |
import fr.paris.lutece.portal.service.security.SecurityService; |
| 110 | |
import fr.paris.lutece.portal.service.security.UserNotSignedException; |
| 111 | |
import fr.paris.lutece.portal.service.template.AppTemplateService; |
| 112 | |
import fr.paris.lutece.portal.service.util.AppLogService; |
| 113 | |
import fr.paris.lutece.portal.service.util.AppPathService; |
| 114 | |
import fr.paris.lutece.portal.service.util.AppPropertiesService; |
| 115 | |
import fr.paris.lutece.portal.service.workgroup.AdminWorkgroupService; |
| 116 | |
import fr.paris.lutece.util.ReferenceList; |
| 117 | |
import fr.paris.lutece.util.filesystem.FileSystemUtil; |
| 118 | |
import fr.paris.lutece.util.html.HtmlTemplate; |
| 119 | |
import fr.paris.lutece.util.url.UrlItem; |
| 120 | |
import fr.paris.lutece.util.xml.XmlUtil; |
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
public final class FormUtils |
| 126 | |
{ |
| 127 | |
|
| 128 | |
public static final String BEAN_ENTRY_TYPE_SERVICE = "form.entryTypeService"; |
| 129 | |
public static final String BEAN_FORM_RESPONSE_SERVICE = "form.responseService"; |
| 130 | |
public static final String BEAN_EXPORT_DAEMON_TYPE_FACTORY = "form.exportTypeFactory"; |
| 131 | |
|
| 132 | |
|
| 133 | |
private static final String SESSION_FORM_LIST_SUBMITTED_RESPONSES = "form_list_submitted_responses"; |
| 134 | |
public static final String SESSION_VALIDATE_REQUIREMENT = "session_validate_requirement"; |
| 135 | |
|
| 136 | |
|
| 137 | |
private static final String PARAMETER_ID_ENTRY_TYPE = "id_type"; |
| 138 | |
|
| 139 | |
|
| 140 | |
private static final String MARK_LOCALE = "locale"; |
| 141 | |
private static final String MARK_ENTRY = "entry"; |
| 142 | |
private static final String MARK_FIELD = "field"; |
| 143 | |
private static final String MARK_JCAPTCHA = "jcaptcha"; |
| 144 | |
private static final String MARK_STR_ENTRY = "str_entry"; |
| 145 | |
private static final String MARK_CATEGORY_LIST = "category_list"; |
| 146 | |
private static final String MARK_LIST_RESPONSES = "list_responses"; |
| 147 | |
private static final String MARK_VALIDATE_REQUIREMENT = "validate_requirement"; |
| 148 | |
private static final String MARK_DRAFT_SUPPORTED = "draft_supported"; |
| 149 | |
private static final String MARK_USER = "user"; |
| 150 | |
private static final String MARK_UPLOAD_HANDLER = "uploadHandler"; |
| 151 | |
private static final String MARK_WEBAPP_URL = "webapp_url"; |
| 152 | |
private static final String MARK_ENTRY_ITERATION_NUMBER = "entry_iteration_number"; |
| 153 | |
private static final String MARK_ENTRY_ITERATION_LIMIT_REACHED = "entry_iteration_limit_reached"; |
| 154 | |
private static final String MARK_FORM_ERRORS = "form_errors"; |
| 155 | |
|
| 156 | |
|
| 157 | |
private static final String JCAPTCHA_PLUGIN = "jcaptcha"; |
| 158 | |
|
| 159 | |
|
| 160 | |
private static final String TAG_FORM = "form"; |
| 161 | |
private static final String TAG_FORM_TITLE = "form-title"; |
| 162 | |
private static final String TAG_FORM_SUBMIT = "submit"; |
| 163 | |
private static final String TAG_FORM_SUBMITS = "submits"; |
| 164 | |
private static final String TAG_FORM_SUBMIT_ID = "submit-id"; |
| 165 | |
private static final String TAG_FORM_SUBMIT_DATE = "submit-date"; |
| 166 | |
private static final String TAG_FORM_SUBMIT_IP = "submit-ip"; |
| 167 | |
private static final String TAG_QUESTIONS = "questions"; |
| 168 | |
private static final String TAG_QUESTION = "question"; |
| 169 | |
private static final String TAG_QUESTION_TITLE = "question-title"; |
| 170 | |
private static final String TAG_QUESTION_ID = "question-id"; |
| 171 | |
private static final String TAG_QUESTION_ITERATION_NUMBER = "iteration-number"; |
| 172 | |
private static final String TAG_RESPONSES = "responses"; |
| 173 | |
private static final String TAG_RESPONSE = "response"; |
| 174 | |
private static final String TAG_FORM_ENTRIES = "form-entries"; |
| 175 | |
private static final String TAG_FORM_ENTRY = "form-entry"; |
| 176 | |
private static final String TAG_FORM_ENTRY_ID = "form-entry-id"; |
| 177 | |
private static final String TAG_FORM_ENTRY_TITLE = "form-entry-title"; |
| 178 | |
private static final String TAG_FORM_ENTRY_ITERATION_NUMBER = "form-entry-iteration-number"; |
| 179 | |
|
| 180 | |
|
| 181 | |
private static final String TEMPLATE_DIV_CONDITIONAL_ENTRY = "skin/plugins/form/html_code_div_conditional_entry.html"; |
| 182 | |
private static final String TEMPLATE_HTML_CODE_FORM = "skin/plugins/form/html_code_form.html"; |
| 183 | |
private static final String TEMPLATE_NOTIFICATION_MAIL_END_DISPONIBILITY = "admin/plugins/form/notification_mail_end_disponibility.html"; |
| 184 | |
private static final String TEMPLATE_NOTIFICATION_MAIL_FORM_SUBMIT = "admin/plugins/form/notification_mail_form_submit.html"; |
| 185 | |
|
| 186 | |
|
| 187 | |
private static final String PROPERTY_NOTIFICATION_MAIL_END_DISPONIBILITY_SUBJECT = "form.notificationMailEndDisponibility.subject"; |
| 188 | |
private static final String PROPERTY_NOTIFICATION_MAIL_END_DISPONIBILITY_SENDER_NAME = "form.notificationMailEndDisponibility.senderName"; |
| 189 | |
private static final String PROPERTY_NOTIFICATION_MAIL_FORM_SUBMIT_SUBJECT = "form.notificationMailFormSubmit.subject"; |
| 190 | |
private static final String PROPERTY_NOTIFICATION_MAIL_FORM_SUBMIT_SENDER_NAME = "form.notificationMailFormSubmit.senderName"; |
| 191 | |
private static final String PROPERTY_CHOOSE_CATEGORY = "form.form.choose.category"; |
| 192 | |
private static final String PROPERTY_LUTECE_ADMIN_PROD_URL = "lutece.admin.prod.url"; |
| 193 | |
private static final String PROPERTY_LUTECE_BASE_URL = "lutece.base.url"; |
| 194 | |
private static final String PROPERTY_LUTECE_PROD_URL = "lutece.prod.url"; |
| 195 | |
public static final String CONSTANT_MYLUTECE_ATTRIBUTE_I18N_PREFIX = "form.entrytype.myluteceuserattribute.attribute."; |
| 196 | |
public static final String PROPERTY_MY_LUTECE_ATTRIBUTES_LIST = "entrytype.myluteceuserattribute.attributes.list"; |
| 197 | |
|
| 198 | |
|
| 199 | |
private static final String MARK_UPLOAD_FRONT_OFFICE_PICTURE_SRC = "frontOfficePictureSource"; |
| 200 | |
|
| 201 | |
|
| 202 | |
public static final String CONSTANT_UNDERSCORE = "_"; |
| 203 | |
public static final String CONSTANT_COMMA = ","; |
| 204 | |
public static final String CONSTANT_GROUP_BY_DAY = "0"; |
| 205 | |
public static final String CONSTANT_GROUP_BY_WEEK = "1"; |
| 206 | |
public static final String CONSTANT_GROUP_BY_MONTH = "2"; |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
private FormUtils( ) |
| 213 | 0 | { |
| 214 | 0 | } |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
public static void sendNotificationMailEndDisponibility( Form form, Locale locale ) |
| 225 | |
{ |
| 226 | |
try |
| 227 | |
{ |
| 228 | 0 | String strSubject = I18nService.getLocalizedString( PROPERTY_NOTIFICATION_MAIL_END_DISPONIBILITY_SUBJECT, locale ); |
| 229 | 0 | String strSenderName = I18nService.getLocalizedString( PROPERTY_NOTIFICATION_MAIL_END_DISPONIBILITY_SENDER_NAME, locale ); |
| 230 | 0 | String strSenderEmail = MailService.getNoReplyEmail( ); |
| 231 | |
|
| 232 | 0 | Collection<Recipient> listRecipients = AdminMailingListService.getRecipients( form.getIdMailingList( ) ); |
| 233 | 0 | Map<String, Object> model = new HashMap<String, Object>( ); |
| 234 | 0 | model.put( FormConstants.MARK_FORM, form ); |
| 235 | |
|
| 236 | 0 | HtmlTemplate t = AppTemplateService.getTemplate( TEMPLATE_NOTIFICATION_MAIL_END_DISPONIBILITY, locale, model ); |
| 237 | |
|
| 238 | |
|
| 239 | 0 | for ( Recipient recipient : listRecipients ) |
| 240 | |
{ |
| 241 | |
|
| 242 | 0 | MailService.sendMailHtml( recipient.getEmail( ), strSenderName, strSenderEmail, strSubject, t.getHtml( ) ); |
| 243 | 0 | } |
| 244 | |
} |
| 245 | 0 | catch( Exception e ) |
| 246 | |
{ |
| 247 | 0 | AppLogService.error( "Error during Notify end disponibilty of form : " + e.getMessage( ) ); |
| 248 | 0 | } |
| 249 | 0 | } |
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
public static void sendNotificationMailFormSubmit( FormSubmit formSubmit, Locale locale ) |
| 260 | |
{ |
| 261 | 0 | Collection<Recipient> listRecipients = AdminMailingListService.getRecipients( formSubmit.getForm( ).getIdMailingList( ) ); |
| 262 | 0 | Map<String, Object> model = new HashMap<String, Object>( ); |
| 263 | 0 | model.put( FormConstants.MARK_FORM, formSubmit.getForm( ) ); |
| 264 | 0 | model.put( FormConstants.MARK_FORM_SUBMIT, formSubmit ); |
| 265 | 0 | sendNotificationMailFormSubmit( model, listRecipients, locale ); |
| 266 | 0 | } |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
private static void sendNotificationMailFormSubmit( Map<String, Object> model, Collection<Recipient> listRecipients, Locale locale ) |
| 279 | |
{ |
| 280 | |
try |
| 281 | |
{ |
| 282 | 0 | String strSubject = I18nService.getLocalizedString( PROPERTY_NOTIFICATION_MAIL_FORM_SUBMIT_SUBJECT, locale ); |
| 283 | 0 | String strSenderName = I18nService.getLocalizedString( PROPERTY_NOTIFICATION_MAIL_FORM_SUBMIT_SENDER_NAME, locale ); |
| 284 | 0 | String strSenderEmail = MailService.getNoReplyEmail( ); |
| 285 | |
|
| 286 | 0 | HtmlTemplate t = AppTemplateService.getTemplate( TEMPLATE_NOTIFICATION_MAIL_FORM_SUBMIT, locale, model ); |
| 287 | |
|
| 288 | |
|
| 289 | 0 | for ( Recipient recipient : listRecipients ) |
| 290 | |
{ |
| 291 | |
|
| 292 | 0 | MailService.sendMailHtml( recipient.getEmail( ), strSenderName, strSenderEmail, strSubject, t.getHtml( ) ); |
| 293 | 0 | } |
| 294 | |
} |
| 295 | 0 | catch( Exception e ) |
| 296 | |
{ |
| 297 | 0 | AppLogService.error( "Error during Notify a new form submit" + e.getMessage( ) ); |
| 298 | 0 | } |
| 299 | 0 | } |
| 300 | |
|
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
public static Timestamp getDateLastMinute( Date date, Locale locale ) |
| 311 | |
{ |
| 312 | 0 | if ( date == null ) |
| 313 | |
{ |
| 314 | 0 | return null; |
| 315 | |
} |
| 316 | |
|
| 317 | 0 | Calendar caldate = new GregorianCalendar( ); |
| 318 | 0 | caldate.setTime( date ); |
| 319 | 0 | caldate.set( Calendar.MILLISECOND, 0 ); |
| 320 | 0 | caldate.set( Calendar.SECOND, 0 ); |
| 321 | 0 | caldate.set( Calendar.HOUR_OF_DAY, caldate.getActualMaximum( Calendar.HOUR_OF_DAY ) ); |
| 322 | 0 | caldate.set( Calendar.MINUTE, caldate.getActualMaximum( Calendar.MINUTE ) ); |
| 323 | |
|
| 324 | 0 | Timestamp timeStamp = new Timestamp( caldate.getTimeInMillis( ) ); |
| 325 | |
|
| 326 | 0 | return timeStamp; |
| 327 | |
} |
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
public static Timestamp getDateFirstMinute( Date date, Locale locale ) |
| 339 | |
{ |
| 340 | 0 | if ( date == null ) |
| 341 | |
{ |
| 342 | 0 | return null; |
| 343 | |
} |
| 344 | |
|
| 345 | 0 | Calendar caldate = new GregorianCalendar( ); |
| 346 | 0 | caldate.setTime( date ); |
| 347 | 0 | caldate.set( Calendar.MILLISECOND, 0 ); |
| 348 | 0 | caldate.set( Calendar.SECOND, 0 ); |
| 349 | 0 | caldate.set( Calendar.HOUR_OF_DAY, caldate.getActualMinimum( Calendar.HOUR_OF_DAY ) ); |
| 350 | 0 | caldate.set( Calendar.MINUTE, caldate.getActualMinimum( Calendar.MINUTE ) ); |
| 351 | |
|
| 352 | 0 | Timestamp timeStamp = new Timestamp( caldate.getTimeInMillis( ) ); |
| 353 | |
|
| 354 | 0 | return timeStamp; |
| 355 | |
} |
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
public static int getDay( Timestamp timestamp ) |
| 365 | |
{ |
| 366 | 0 | Calendar caldate = new GregorianCalendar( ); |
| 367 | 0 | caldate.setTime( timestamp ); |
| 368 | |
|
| 369 | 0 | return caldate.get( Calendar.DAY_OF_MONTH ); |
| 370 | |
} |
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
public static int getWeek( Timestamp timestamp ) |
| 380 | |
{ |
| 381 | 0 | Calendar caldate = new GregorianCalendar( ); |
| 382 | 0 | caldate.setTime( timestamp ); |
| 383 | |
|
| 384 | 0 | return caldate.get( Calendar.WEEK_OF_YEAR ); |
| 385 | |
} |
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
public static int getMonth( Timestamp timestamp ) |
| 395 | |
{ |
| 396 | 0 | Calendar caldate = new GregorianCalendar( ); |
| 397 | 0 | caldate.setTime( timestamp ); |
| 398 | |
|
| 399 | 0 | return caldate.get( Calendar.MONTH ); |
| 400 | |
} |
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
public static int getYear( Timestamp timestamp ) |
| 410 | |
{ |
| 411 | 0 | Calendar caldate = new GregorianCalendar( ); |
| 412 | 0 | caldate.setTime( timestamp ); |
| 413 | |
|
| 414 | 0 | return caldate.get( Calendar.YEAR ); |
| 415 | |
} |
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
public static Timestamp addStatisticInterval( Timestamp timestamp, String strTimesUnit, int nDecal ) |
| 430 | |
{ |
| 431 | 0 | int nTimesUnit = Calendar.DAY_OF_MONTH; |
| 432 | |
|
| 433 | 0 | if ( strTimesUnit.equals( CONSTANT_GROUP_BY_WEEK ) ) |
| 434 | |
{ |
| 435 | 0 | nTimesUnit = Calendar.WEEK_OF_MONTH; |
| 436 | |
} |
| 437 | |
else |
| 438 | 0 | if ( strTimesUnit.equals( CONSTANT_GROUP_BY_MONTH ) ) |
| 439 | |
{ |
| 440 | 0 | nTimesUnit = Calendar.MONTH; |
| 441 | |
} |
| 442 | |
|
| 443 | 0 | Calendar caldate = new GregorianCalendar( ); |
| 444 | 0 | caldate.setTime( timestamp ); |
| 445 | 0 | caldate.set( Calendar.MILLISECOND, 0 ); |
| 446 | 0 | caldate.set( Calendar.SECOND, 0 ); |
| 447 | 0 | caldate.set( Calendar.HOUR_OF_DAY, caldate.getActualMaximum( Calendar.HOUR_OF_DAY ) ); |
| 448 | 0 | caldate.set( Calendar.MINUTE, caldate.getActualMaximum( Calendar.MINUTE ) ); |
| 449 | 0 | caldate.add( nTimesUnit, nDecal ); |
| 450 | |
|
| 451 | 0 | Timestamp timeStamp1 = new Timestamp( caldate.getTimeInMillis( ) ); |
| 452 | |
|
| 453 | 0 | return timeStamp1; |
| 454 | |
} |
| 455 | |
|
| 456 | |
|
| 457 | |
|
| 458 | |
|
| 459 | |
|
| 460 | |
|
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | |
|
| 466 | |
|
| 467 | |
public static boolean sameDate( Timestamp timestamp1, Timestamp timestamp2, String strTimesUnit ) |
| 468 | |
{ |
| 469 | 0 | Calendar caldate1 = new GregorianCalendar( ); |
| 470 | 0 | caldate1.setTime( timestamp1 ); |
| 471 | |
|
| 472 | 0 | Calendar caldate2 = new GregorianCalendar( ); |
| 473 | 0 | caldate2.setTime( timestamp2 ); |
| 474 | |
|
| 475 | 0 | if ( strTimesUnit.equals( CONSTANT_GROUP_BY_DAY ) && ( caldate1.get( Calendar.YEAR ) == caldate2.get( Calendar.YEAR ) ) |
| 476 | 0 | && ( caldate1.get( Calendar.DAY_OF_YEAR ) == caldate2.get( Calendar.DAY_OF_YEAR ) ) ) |
| 477 | |
{ |
| 478 | 0 | return true; |
| 479 | |
} |
| 480 | |
else |
| 481 | 0 | if ( strTimesUnit.equals( CONSTANT_GROUP_BY_WEEK ) && ( caldate1.get( Calendar.YEAR ) == caldate2.get( Calendar.YEAR ) ) |
| 482 | 0 | && ( caldate1.get( Calendar.WEEK_OF_YEAR ) == caldate2.get( Calendar.WEEK_OF_YEAR ) ) ) |
| 483 | |
{ |
| 484 | 0 | return true; |
| 485 | |
} |
| 486 | |
else |
| 487 | 0 | if ( strTimesUnit.equals( CONSTANT_GROUP_BY_MONTH ) && ( caldate1.get( Calendar.YEAR ) == caldate2.get( Calendar.YEAR ) ) |
| 488 | 0 | && ( caldate1.get( Calendar.MONTH ) == caldate2.get( Calendar.MONTH ) ) ) |
| 489 | |
{ |
| 490 | 0 | return true; |
| 491 | |
} |
| 492 | |
|
| 493 | 0 | return false; |
| 494 | |
} |
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
|
| 501 | |
|
| 502 | |
|
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
public static String getDateString( Timestamp date, Locale locale ) |
| 507 | |
{ |
| 508 | 0 | DateFormat dateFormat = DateFormat.getDateInstance( DateFormat.SHORT, locale ); |
| 509 | |
|
| 510 | 0 | return dateFormat.format( date ); |
| 511 | |
} |
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
public static Timestamp getCurrentTimestamp( ) |
| 519 | |
{ |
| 520 | 0 | return new Timestamp( GregorianCalendar.getInstance( ).getTimeInMillis( ) ); |
| 521 | |
} |
| 522 | |
|
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | |
|
| 527 | |
|
| 528 | |
public static Date getCurrentDate( ) |
| 529 | |
{ |
| 530 | 0 | Calendar cal1 = Calendar.getInstance( ); |
| 531 | 0 | cal1.setTime( new Date( ) ); |
| 532 | 0 | cal1.set( Calendar.HOUR_OF_DAY, 0 ); |
| 533 | 0 | cal1.set( Calendar.MINUTE, 0 ); |
| 534 | 0 | cal1.set( Calendar.SECOND, 0 ); |
| 535 | 0 | cal1.set( Calendar.MILLISECOND, 0 ); |
| 536 | |
|
| 537 | 0 | return cal1.getTime( ); |
| 538 | |
} |
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
public static Entry createEntryByType( HttpServletRequest request, Plugin plugin ) |
| 550 | |
{ |
| 551 | 0 | String strIdType = request.getParameter( PARAMETER_ID_ENTRY_TYPE ); |
| 552 | 0 | int nIdType = -1; |
| 553 | 0 | Entry entry = null; |
| 554 | |
EntryType entryType; |
| 555 | |
|
| 556 | 0 | if ( ( strIdType != null ) && !strIdType.equals( StringUtils.EMPTY ) ) |
| 557 | |
{ |
| 558 | |
try |
| 559 | |
{ |
| 560 | 0 | nIdType = Integer.parseInt( strIdType ); |
| 561 | |
} |
| 562 | 0 | catch( NumberFormatException ne ) |
| 563 | |
{ |
| 564 | 0 | AppLogService.error( ne ); |
| 565 | |
|
| 566 | 0 | return null; |
| 567 | 0 | } |
| 568 | |
} |
| 569 | |
|
| 570 | 0 | if ( nIdType == -1 ) |
| 571 | |
{ |
| 572 | 0 | return null; |
| 573 | |
} |
| 574 | |
|
| 575 | 0 | entryType = EntryTypeHome.findByPrimaryKey( nIdType ); |
| 576 | |
|
| 577 | 0 | entry = new Entry( ); |
| 578 | 0 | entry.setEntryType( entryType ); |
| 579 | |
|
| 580 | 0 | return entry; |
| 581 | |
} |
| 582 | |
|
| 583 | |
|
| 584 | |
|
| 585 | |
|
| 586 | |
|
| 587 | |
|
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
public static int getIndexFieldInTheFieldList( int nIdField, List<Field> listField ) |
| 593 | |
{ |
| 594 | 0 | int nIndex = 0; |
| 595 | |
|
| 596 | 0 | for ( Field field : listField ) |
| 597 | |
{ |
| 598 | 0 | if ( field.getIdField( ) == nIdField ) |
| 599 | |
{ |
| 600 | 0 | return nIndex; |
| 601 | |
} |
| 602 | |
|
| 603 | 0 | nIndex++; |
| 604 | 0 | } |
| 605 | |
|
| 606 | 0 | return nIndex; |
| 607 | |
} |
| 608 | |
|
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | |
|
| 616 | |
|
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
|
| 624 | |
public static String getHtmlForm( Form form, String strUrlAction, Locale locale, boolean bDisplayFront, HttpServletRequest request ) |
| 625 | |
{ |
| 626 | |
List<Entry> listEntryFirstLevel; |
| 627 | 0 | Map<String, Object> model = new HashMap<String, Object>( ); |
| 628 | |
HtmlTemplate template; |
| 629 | |
EntryFilter filter; |
| 630 | 0 | StringBuffer strBuffer = new StringBuffer( ); |
| 631 | 0 | filter = new EntryFilter( ); |
| 632 | 0 | filter.setIdResource( form.getIdForm( ) ); |
| 633 | 0 | filter.setResourceType( Form.RESOURCE_TYPE ); |
| 634 | 0 | filter.setEntryParentNull( EntryFilter.FILTER_TRUE ); |
| 635 | 0 | filter.setFieldDependNull( EntryFilter.FILTER_TRUE ); |
| 636 | 0 | listEntryFirstLevel = EntryHome.getEntryList( filter ); |
| 637 | 0 | HttpSession session = request.getSession( ); |
| 638 | |
|
| 639 | 0 | ArrayList<Category> listCats = new ArrayList<Category>( ); |
| 640 | 0 | Category category = new Category( ); |
| 641 | |
|
| 642 | 0 | category.setIdCategory( -2 ); |
| 643 | 0 | category.setTitle( I18nService.getLocalizedString( PROPERTY_CHOOSE_CATEGORY, locale ) ); |
| 644 | |
|
| 645 | 0 | if ( form.getCategory( ) != null ) |
| 646 | |
{ |
| 647 | 0 | listCats.add( category ); |
| 648 | |
} |
| 649 | |
|
| 650 | 0 | ReferenceList refCategoryList = getRefListCategory( listCats ); |
| 651 | |
|
| 652 | 0 | for ( Entry entry : listEntryFirstLevel ) |
| 653 | |
{ |
| 654 | 0 | FormUtils.getHtmlEntry( entry.getIdEntry( ), strBuffer, locale, bDisplayFront, request ); |
| 655 | 0 | } |
| 656 | |
|
| 657 | 0 | if ( form.isActiveCaptcha( ) && PluginService.isPluginEnable( JCAPTCHA_PLUGIN ) ) |
| 658 | |
{ |
| 659 | 0 | CaptchaSecurityService captchaSecurityService = new CaptchaSecurityService( ); |
| 660 | 0 | model.put( MARK_JCAPTCHA, captchaSecurityService.getHtmlCode( ) ); |
| 661 | |
} |
| 662 | |
|
| 663 | 0 | model.put( MARK_CATEGORY_LIST, refCategoryList ); |
| 664 | 0 | model.put( FormConstants.MARK_FORM, form ); |
| 665 | 0 | model.put( FormConstants.MARK_URL_ACTION, strUrlAction ); |
| 666 | 0 | model.put( MARK_STR_ENTRY, strBuffer.toString( ) ); |
| 667 | 0 | model.put( MARK_LOCALE, locale ); |
| 668 | |
|
| 669 | 0 | Object objectSessionValidateRequirement = session.getAttribute( SESSION_VALIDATE_REQUIREMENT ); |
| 670 | 0 | if ( objectSessionValidateRequirement != null ) |
| 671 | |
{ |
| 672 | 0 | boolean bValidateRequirement = (Boolean) objectSessionValidateRequirement; |
| 673 | 0 | model.put( MARK_VALIDATE_REQUIREMENT, bValidateRequirement ); |
| 674 | |
} |
| 675 | |
|
| 676 | |
|
| 677 | 0 | LuteceUser user = retrieveLuteceUserFromRequest( request ); |
| 678 | 0 | model.put( MARK_USER, user ); |
| 679 | |
|
| 680 | |
|
| 681 | 0 | model.put( MARK_DRAFT_SUPPORTED, FormDraftBackupService.isDraftSupported( ) ); |
| 682 | |
|
| 683 | |
|
| 684 | 0 | int nIdPictureFile = form.getIdPictureFile( ); |
| 685 | 0 | if ( nIdPictureFile != NumberUtils.INTEGER_ZERO ) |
| 686 | |
{ |
| 687 | 0 | model.put( MARK_UPLOAD_FRONT_OFFICE_PICTURE_SRC, getFrontOfficePictureSource( nIdPictureFile ) ); |
| 688 | |
} |
| 689 | |
|
| 690 | |
|
| 691 | 0 | model.put( MARK_FORM_ERRORS, FormUtils.getFormErrors( session ) ); |
| 692 | |
|
| 693 | 0 | template = AppTemplateService.getTemplate( TEMPLATE_HTML_CODE_FORM, locale, model ); |
| 694 | |
|
| 695 | 0 | return template.getHtml( ); |
| 696 | |
} |
| 697 | |
|
| 698 | |
|
| 699 | |
|
| 700 | |
|
| 701 | |
|
| 702 | |
|
| 703 | |
|
| 704 | |
|
| 705 | |
public static ReferenceList getRefListCategory( List<Category> listCategories ) |
| 706 | |
{ |
| 707 | 0 | ReferenceList refListCategories = new ReferenceList( ); |
| 708 | |
|
| 709 | 0 | for ( Category category : listCategories ) |
| 710 | |
{ |
| 711 | 0 | refListCategories.addItem( category.getIdCategory( ), category.getTitle( ) ); |
| 712 | 0 | } |
| 713 | |
|
| 714 | 0 | return refListCategories; |
| 715 | |
} |
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
|
| 720 | |
|
| 721 | |
|
| 722 | |
|
| 723 | |
|
| 724 | |
|
| 725 | |
|
| 726 | |
|
| 727 | |
|
| 728 | |
|
| 729 | |
|
| 730 | |
|
| 731 | |
public static void getHtmlEntry( int nIdEntry, StringBuffer stringBuffer, Locale locale, boolean bDisplayFront, HttpServletRequest request ) |
| 732 | |
{ |
| 733 | 0 | getHtmlEntry( nIdEntry, stringBuffer, locale, bDisplayFront, request, FormConstants.DEFAULT_ITERATION_NUMBER ); |
| 734 | 0 | } |
| 735 | |
|
| 736 | |
|
| 737 | |
|
| 738 | |
|
| 739 | |
|
| 740 | |
|
| 741 | |
|
| 742 | |
|
| 743 | |
|
| 744 | |
|
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
|
| 750 | |
|
| 751 | |
|
| 752 | |
public static void getHtmlEntry( int nIdEntry, StringBuffer stringBuffer, Locale locale, boolean bDisplayFront, HttpServletRequest request, |
| 753 | |
int nIterationNumber ) |
| 754 | |
{ |
| 755 | 0 | Map<String, Object> model = new HashMap<String, Object>( ); |
| 756 | 0 | List<ConditionalEntriesFieldMapper> lstConditionalFieldMapper = null; |
| 757 | |
HtmlTemplate template; |
| 758 | 0 | Entry entry = EntryHome.findByPrimaryKey( nIdEntry ); |
| 759 | |
|
| 760 | 0 | if ( entry.isRoleAssociated( ) ) |
| 761 | |
{ |
| 762 | 0 | entry.setFields( FormUtils.getAuthorizedFieldsByRole( request, entry.getFields( ) ) ); |
| 763 | |
} |
| 764 | |
|
| 765 | 0 | if ( entry.getEntryType( ).getGroup( ) ) |
| 766 | |
{ |
| 767 | |
|
| 768 | 0 | EntryTypeGroupUtils.getHtmlGroupEntry( request, entry, model, bDisplayFront ); |
| 769 | |
} |
| 770 | |
else |
| 771 | |
{ |
| 772 | 0 | if ( entry.getNumberConditionalQuestion( ) != 0 ) |
| 773 | |
{ |
| 774 | 0 | for ( Field field : entry.getFields( ) ) |
| 775 | |
{ |
| 776 | 0 | field.setConditionalQuestions( FieldHome.findByPrimaryKey( field.getIdField( ) ).getConditionalQuestions( ) ); |
| 777 | 0 | } |
| 778 | |
} |
| 779 | |
} |
| 780 | |
|
| 781 | 0 | if ( entry.getNumberConditionalQuestion( ) != 0 ) |
| 782 | |
{ |
| 783 | 0 | lstConditionalFieldMapper = new ArrayList<ConditionalEntriesFieldMapper>( ); |
| 784 | |
|
| 785 | 0 | for ( Field field : entry.getFields( ) ) |
| 786 | |
{ |
| 787 | 0 | if ( field.getConditionalQuestions( ).size( ) != 0 ) |
| 788 | |
{ |
| 789 | 0 | StringBuffer strGroupStringBuffer = new StringBuffer( ); |
| 790 | |
|
| 791 | 0 | for ( Entry entryConditional : field.getConditionalQuestions( ) ) |
| 792 | |
{ |
| 793 | 0 | getHtmlEntry( entryConditional.getIdEntry( ), strGroupStringBuffer, locale, bDisplayFront, request, nIterationNumber ); |
| 794 | |
|
| 795 | 0 | } |
| 796 | 0 | model.put( FormConstants.MARK_STR_LIST_CHILDREN, strGroupStringBuffer.toString( ) ); |
| 797 | 0 | model.put( MARK_FIELD, field ); |
| 798 | 0 | model.put( MARK_ENTRY_ITERATION_NUMBER, nIterationNumber ); |
| 799 | 0 | template = AppTemplateService.getTemplate( TEMPLATE_DIV_CONDITIONAL_ENTRY, locale, model ); |
| 800 | 0 | lstConditionalFieldMapper.add( new ConditionalEntriesFieldMapper( field.getIdField( ), template.getHtml( ) ) ); |
| 801 | |
} |
| 802 | 0 | } |
| 803 | 0 | model.put( FormConstants.MARK_LIST_MAP_CHILDREN, lstConditionalFieldMapper ); |
| 804 | |
} |
| 805 | |
|
| 806 | 0 | model.put( MARK_ENTRY, entry ); |
| 807 | 0 | model.put( MARK_ENTRY_ITERATION_NUMBER, nIterationNumber ); |
| 808 | 0 | model.put( MARK_LOCALE, locale ); |
| 809 | |
|
| 810 | |
|
| 811 | 0 | LuteceUser user = retrieveLuteceUserFromRequest( request ); |
| 812 | 0 | model.put( MARK_USER, user ); |
| 813 | |
|
| 814 | 0 | Map<Integer, List<Response>> listSubmittedResponses = getResponses( request.getSession( ) ); |
| 815 | 0 | List<Response> listResponses = new ArrayList<>( ); |
| 816 | |
|
| 817 | 0 | if ( listSubmittedResponses != null && !EntryTypeGroupUtils.entryBelongIterableGroup( entry ) ) |
| 818 | |
{ |
| 819 | 0 | listResponses = listSubmittedResponses.get( entry.getIdEntry( ) ); |
| 820 | |
} |
| 821 | |
else |
| 822 | |
{ |
| 823 | 0 | String strEntryParameter = request.getParameter( FormConstants.PREFIX_ATTRIBUTE + entry.getIdEntry( ) ); |
| 824 | |
|
| 825 | 0 | if ( StringUtils.isNotBlank( strEntryParameter ) ) |
| 826 | |
{ |
| 827 | 0 | EntryTypeServiceManager.getEntryTypeService( entry ).getResponseData( entry, request, listResponses, locale ); |
| 828 | |
} |
| 829 | |
|
| 830 | |
|
| 831 | 0 | if ( ( entry != null && entry.getParent( ) != null ) || entry.getFieldDepend( ) != null ) |
| 832 | |
{ |
| 833 | |
|
| 834 | 0 | EntryTypeGroupUtils.manageIterableGroupResponse( request, entry, listResponses, nIterationNumber ); |
| 835 | |
|
| 836 | |
|
| 837 | 0 | if ( EntryTypeGroupUtils.entryBelongIterableGroup( entry ) ) |
| 838 | |
{ |
| 839 | 0 | EntryTypeGroupUtils.populateIterationGroup( request, entry, nIterationNumber, listResponses ); |
| 840 | |
} |
| 841 | |
} |
| 842 | |
} |
| 843 | |
|
| 844 | |
|
| 845 | 0 | if ( listResponses != null && !listResponses.isEmpty( ) ) |
| 846 | |
{ |
| 847 | 0 | model.put( MARK_LIST_RESPONSES, listResponses ); |
| 848 | |
} |
| 849 | |
|
| 850 | 0 | IEntryTypeService entryTypeService = EntryTypeServiceManager.getEntryTypeService( entry ); |
| 851 | |
|
| 852 | 0 | if ( entryTypeService instanceof AbstractEntryTypeUpload ) |
| 853 | |
{ |
| 854 | 0 | model.put( MARK_UPLOAD_HANDLER, ( (AbstractEntryTypeUpload) entryTypeService ).getAsynchronousUploadHandler( ) ); |
| 855 | |
} |
| 856 | |
|
| 857 | 0 | model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) ); |
| 858 | |
|
| 859 | |
|
| 860 | 0 | if ( entryTypeService instanceof AbstractEntryTypeGroup && new IterationGroup( entry ).getNbMaxIteration( ) != FormConstants.DEFAULT_ITERATION_NUMBER ) |
| 861 | |
{ |
| 862 | 0 | Boolean isLimitReached = Boolean.TRUE; |
| 863 | 0 | IterationGroup iterationGroup = EntryTypeGroupUtils.retrieveIterationGroup( request, nIdEntry ); |
| 864 | 0 | if ( iterationGroup != null ) |
| 865 | |
{ |
| 866 | 0 | isLimitReached = iterationGroup.isIterationLimitReached( ); |
| 867 | |
} |
| 868 | |
|
| 869 | 0 | model.put( MARK_ENTRY_ITERATION_LIMIT_REACHED, isLimitReached ); |
| 870 | |
} |
| 871 | |
|
| 872 | 0 | template = AppTemplateService.getTemplate( entryTypeService.getTemplateHtmlForm( entry, bDisplayFront ), locale, model ); |
| 873 | 0 | stringBuffer.append( template.getHtml( ) ); |
| 874 | 0 | } |
| 875 | |
|
| 876 | |
|
| 877 | |
|
| 878 | |
|
| 879 | |
|
| 880 | |
|
| 881 | |
|
| 882 | |
|
| 883 | |
private static LuteceUser retrieveLuteceUserFromRequest( HttpServletRequest request ) |
| 884 | |
{ |
| 885 | 0 | LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request ); |
| 886 | |
|
| 887 | 0 | if ( user == null && SecurityService.isAuthenticationEnable( ) && SecurityService.getInstance( ).isExternalAuthentication( ) ) |
| 888 | |
{ |
| 889 | |
try |
| 890 | |
{ |
| 891 | 0 | user = SecurityService.getInstance( ).getRemoteUser( request ); |
| 892 | |
} |
| 893 | 0 | catch( UserNotSignedException e ) |
| 894 | |
{ |
| 895 | |
|
| 896 | 0 | } |
| 897 | |
} |
| 898 | |
|
| 899 | 0 | return user; |
| 900 | |
} |
| 901 | |
|
| 902 | |
|
| 903 | |
|
| 904 | |
|
| 905 | |
|
| 906 | |
|
| 907 | |
|
| 908 | |
|
| 909 | |
|
| 910 | |
|
| 911 | |
|
| 912 | |
|
| 913 | |
|
| 914 | |
|
| 915 | |
|
| 916 | |
|
| 917 | |
|
| 918 | |
|
| 919 | |
|
| 920 | |
|
| 921 | |
|
| 922 | |
public static List<GenericAttributeError> getResponseEntry( HttpServletRequest request, int nIdEntry, Plugin plugin, FormSubmit formSubmit, |
| 923 | |
boolean bResponseNull, boolean bReturnErrors, Locale locale ) |
| 924 | |
{ |
| 925 | 0 | return getResponseEntry( request, nIdEntry, plugin, formSubmit, bResponseNull, bReturnErrors, locale, FormConstants.DEFAULT_ITERATION_NUMBER ); |
| 926 | |
} |
| 927 | |
|
| 928 | |
|
| 929 | |
|
| 930 | |
|
| 931 | |
|
| 932 | |
|
| 933 | |
|
| 934 | |
|
| 935 | |
|
| 936 | |
|
| 937 | |
|
| 938 | |
|
| 939 | |
|
| 940 | |
|
| 941 | |
|
| 942 | |
|
| 943 | |
|
| 944 | |
|
| 945 | |
|
| 946 | |
|
| 947 | |
|
| 948 | |
|
| 949 | |
|
| 950 | |
public static List<GenericAttributeError> getResponseEntry( HttpServletRequest request, int nIdEntry, Plugin plugin, FormSubmit formSubmit, |
| 951 | |
boolean bResponseNull, boolean bReturnErrors, Locale locale, int nIterationNumber ) |
| 952 | |
{ |
| 953 | 0 | List<GenericAttributeError> listFormErrors = new ArrayList<GenericAttributeError>( ); |
| 954 | 0 | List<Response> listResponse = new ArrayList<Response>( ); |
| 955 | 0 | Entry entry = EntryHome.findByPrimaryKey( nIdEntry ); |
| 956 | |
|
| 957 | 0 | List<Field> listField = new ArrayList<Field>( ); |
| 958 | |
|
| 959 | 0 | for ( Field field : entry.getFields( ) ) |
| 960 | |
{ |
| 961 | 0 | field = FieldHome.findByPrimaryKey( field.getIdField( ) ); |
| 962 | 0 | listField.add( field ); |
| 963 | 0 | } |
| 964 | |
|
| 965 | 0 | entry.setFields( listField ); |
| 966 | |
|
| 967 | 0 | if ( entry.getEntryType( ).getGroup( ) ) |
| 968 | |
{ |
| 969 | |
|
| 970 | 0 | EntryTypeGroupUtils.getResponseGroupEntry( request, listFormErrors, entry, plugin, formSubmit, bReturnErrors, locale ); |
| 971 | |
} |
| 972 | |
else |
| 973 | 0 | if ( !entry.getEntryType( ).getComment( ) ) |
| 974 | |
{ |
| 975 | 0 | GenericAttributeError formError = null; |
| 976 | |
|
| 977 | 0 | if ( !bResponseNull ) |
| 978 | |
{ |
| 979 | |
|
| 980 | 0 | request.setAttribute( FormConstants.ATTRIBUTE_RESPONSE_ITERATION_NUMBER, nIterationNumber ); |
| 981 | |
|
| 982 | |
|
| 983 | 0 | if ( EntryTypeServiceManager.getEntryTypeService( entry ) instanceof AbstractEntryTypeArray |
| 984 | |
&& request instanceof GroupHttpServletRequestWrapper ) |
| 985 | |
{ |
| 986 | 0 | StringBuilder strIterationParameterName = new StringBuilder( ( (GroupHttpServletRequestWrapper) request ).getIterationParameterName( ) ); |
| 987 | 0 | strIterationParameterName.append( FormConstants.PREFIX_ATTRIBUTE ); |
| 988 | 0 | strIterationParameterName.append( entry.getIdEntry( ) ); |
| 989 | 0 | strIterationParameterName.append( FormUtils.CONSTANT_UNDERSCORE ); |
| 990 | |
|
| 991 | 0 | ( (GroupHttpServletRequestWrapper) request ).setIterationParameterName( strIterationParameterName.toString( ) ); |
| 992 | |
} |
| 993 | |
|
| 994 | |
|
| 995 | 0 | formError = EntryTypeServiceManager.getEntryTypeService( entry ).getResponseData( entry, request, listResponse, locale ); |
| 996 | |
|
| 997 | |
|
| 998 | 0 | request.removeAttribute( FormConstants.ATTRIBUTE_RESPONSE_ITERATION_NUMBER ); |
| 999 | |
|
| 1000 | 0 | if ( formError != null ) |
| 1001 | |
{ |
| 1002 | |
|
| 1003 | 0 | if ( EntryTypeGroupUtils.entryBelongIterableGroup( entry ) ) |
| 1004 | |
{ |
| 1005 | 0 | formError.setUrl( EntryTypeGroupUtils.getIterableEntryChildUrl( entry, |
| 1006 | 0 | request.getAttribute( FormConstants.ATTRIBUTE_ITERATION_NUMBER ) ) ); |
| 1007 | |
} |
| 1008 | |
else |
| 1009 | |
{ |
| 1010 | 0 | formError.setUrl( getEntryUrl( entry ) ); |
| 1011 | |
} |
| 1012 | |
} |
| 1013 | |
} |
| 1014 | |
else |
| 1015 | |
{ |
| 1016 | 0 | Response response = new Response( ); |
| 1017 | 0 | response.setEntry( entry ); |
| 1018 | 0 | response.setIterationNumber( nIterationNumber ); |
| 1019 | 0 | listResponse.add( response ); |
| 1020 | |
} |
| 1021 | |
|
| 1022 | 0 | if ( bReturnErrors && ( formError != null ) ) |
| 1023 | |
{ |
| 1024 | 0 | entry.setError( formError ); |
| 1025 | 0 | listFormErrors.add( formError ); |
| 1026 | |
} |
| 1027 | |
|
| 1028 | 0 | if ( request.getSession( ) != null ) |
| 1029 | |
{ |
| 1030 | 0 | Map<Integer, List<Response>> listSubmittedResponses = getResponses( request.getSession( ) ); |
| 1031 | |
|
| 1032 | 0 | if ( listSubmittedResponses != null ) |
| 1033 | |
{ |
| 1034 | 0 | listSubmittedResponses.put( entry.getIdEntry( ), listResponse ); |
| 1035 | 0 | restoreResponses( request.getSession( ), listSubmittedResponses ); |
| 1036 | |
} |
| 1037 | |
} |
| 1038 | |
|
| 1039 | |
|
| 1040 | 0 | if ( EntryTypeGroupUtils.entryBelongIterableGroup( entry ) ) |
| 1041 | |
{ |
| 1042 | |
|
| 1043 | 0 | EntryTypeGroupUtils.populateIterationGroup( request, entry, nIterationNumber, listResponse ); |
| 1044 | |
} |
| 1045 | |
|
| 1046 | 0 | formSubmit.getListResponse( ).addAll( listResponse ); |
| 1047 | |
|
| 1048 | 0 | if ( entry.getNumberConditionalQuestion( ) != 0 ) |
| 1049 | |
{ |
| 1050 | 0 | for ( Field field : entry.getFields( ) ) |
| 1051 | |
{ |
| 1052 | 0 | boolean bIsFieldInResponseList = isFieldInTheResponseList( field.getIdField( ), listResponse ); |
| 1053 | |
|
| 1054 | 0 | for ( Entry conditionalEntry : field.getConditionalQuestions( ) ) |
| 1055 | |
{ |
| 1056 | 0 | listFormErrors.addAll( getResponseEntry( request, conditionalEntry.getIdEntry( ), plugin, formSubmit, !bIsFieldInResponseList, |
| 1057 | |
bReturnErrors, locale, nIterationNumber ) ); |
| 1058 | 0 | } |
| 1059 | 0 | } |
| 1060 | |
} |
| 1061 | |
} |
| 1062 | |
|
| 1063 | 0 | return listFormErrors; |
| 1064 | |
} |
| 1065 | |
|
| 1066 | |
|
| 1067 | |
|
| 1068 | |
|
| 1069 | |
|
| 1070 | |
|
| 1071 | |
|
| 1072 | |
|
| 1073 | |
public static String getEntryUrl( Entry entry ) |
| 1074 | |
{ |
| 1075 | 0 | UrlItem url = new UrlItem( AppPathService.getPortalUrl( ) ); |
| 1076 | 0 | url.addParameter( XPageAppService.PARAM_XPAGE_APP, FormPlugin.PLUGIN_NAME ); |
| 1077 | |
|
| 1078 | 0 | if ( ( entry != null ) && ( entry.getIdResource( ) > 0 ) ) |
| 1079 | |
{ |
| 1080 | 0 | url.addParameter( FormConstants.PARAMETER_ID_FORM, entry.getIdResource( ) ); |
| 1081 | 0 | url.setAnchor( FormConstants.PREFIX_ATTRIBUTE + entry.getIdEntry( ) ); |
| 1082 | |
} |
| 1083 | |
|
| 1084 | 0 | return url.getUrl( ); |
| 1085 | |
} |
| 1086 | |
|
| 1087 | |
|
| 1088 | |
|
| 1089 | |
|
| 1090 | |
|
| 1091 | |
|
| 1092 | |
|
| 1093 | |
|
| 1094 | |
|
| 1095 | |
|
| 1096 | |
public static Boolean isFieldInTheResponseList( int nIdField, List<Response> listResponse ) |
| 1097 | |
{ |
| 1098 | 0 | for ( Response response : listResponse ) |
| 1099 | |
{ |
| 1100 | 0 | if ( ( response.getField( ) != null ) && ( response.getField( ).getIdField( ) == nIdField ) ) |
| 1101 | |
{ |
| 1102 | 0 | return true; |
| 1103 | |
} |
| 1104 | 0 | } |
| 1105 | |
|
| 1106 | 0 | return false; |
| 1107 | |
} |
| 1108 | |
|
| 1109 | |
|
| 1110 | |
|
| 1111 | |
|
| 1112 | |
|
| 1113 | |
|
| 1114 | |
|
| 1115 | |
|
| 1116 | |
|
| 1117 | |
|
| 1118 | |
|
| 1119 | |
|
| 1120 | |
|
| 1121 | |
|
| 1122 | |
|
| 1123 | |
|
| 1124 | |
public static String getXmlResponses( HttpServletRequest request, Form form, List<FormSubmit> listFormSubmit, Locale locale, Plugin plugin ) |
| 1125 | |
{ |
| 1126 | |
|
| 1127 | 0 | StringBuffer buffer = new StringBuffer( ); |
| 1128 | 0 | XmlUtil.beginElement( buffer, TAG_FORM ); |
| 1129 | 0 | XmlUtil.addElementHtml( buffer, TAG_FORM_TITLE, form.getTitle( ) ); |
| 1130 | |
|
| 1131 | |
|
| 1132 | 0 | XmlUtil.beginElement( buffer, TAG_FORM_ENTRIES ); |
| 1133 | 0 | Map<Integer, Integer> mapIdEntryIterationNumber = new LinkedHashMap<>( ); |
| 1134 | |
|
| 1135 | 0 | for ( Entry entry : getAllQuestionList( form.getIdForm( ), plugin ) ) |
| 1136 | |
{ |
| 1137 | 0 | XmlUtil.beginElement( buffer, TAG_FORM_ENTRY ); |
| 1138 | 0 | XmlUtil.addElement( buffer, TAG_FORM_ENTRY_ID, entry.getIdEntry( ) ); |
| 1139 | |
|
| 1140 | |
|
| 1141 | 0 | int nIterationNumber = FormConstants.DEFAULT_ITERATION_NUMBER; |
| 1142 | 0 | if ( EntryTypeGroupUtils.entryBelongIterableGroup( entry ) ) |
| 1143 | |
{ |
| 1144 | 0 | int nIdEntry = entry.getIdEntry( ); |
| 1145 | 0 | if ( !mapIdEntryIterationNumber.containsKey( nIdEntry ) ) |
| 1146 | |
{ |
| 1147 | 0 | mapIdEntryIterationNumber.put( nIdEntry, NumberUtils.INTEGER_ONE ); |
| 1148 | |
} |
| 1149 | |
|
| 1150 | 0 | int nCurrentEntryIterationNumber = mapIdEntryIterationNumber.get( nIdEntry ); |
| 1151 | 0 | nIterationNumber = nCurrentEntryIterationNumber; |
| 1152 | 0 | mapIdEntryIterationNumber.put( nIdEntry, nCurrentEntryIterationNumber + NumberUtils.INTEGER_ONE ); |
| 1153 | |
} |
| 1154 | 0 | XmlUtil.addElement( buffer, TAG_FORM_ENTRY_ITERATION_NUMBER, nIterationNumber ); |
| 1155 | |
|
| 1156 | 0 | XmlUtil.addElementHtml( buffer, TAG_FORM_ENTRY_TITLE, entry.getTitle( ) ); |
| 1157 | 0 | XmlUtil.endElement( buffer, TAG_FORM_ENTRY ); |
| 1158 | 0 | } |
| 1159 | |
|
| 1160 | 0 | XmlUtil.endElement( buffer, TAG_FORM_ENTRIES ); |
| 1161 | |
|
| 1162 | |
|
| 1163 | 0 | XmlUtil.beginElement( buffer, TAG_FORM_SUBMITS ); |
| 1164 | |
|
| 1165 | 0 | for ( FormSubmit formSubmit : listFormSubmit ) |
| 1166 | |
{ |
| 1167 | 0 | getXmlResponse( request, buffer, formSubmit, locale, plugin ); |
| 1168 | 0 | } |
| 1169 | |
|
| 1170 | 0 | XmlUtil.endElement( buffer, TAG_FORM_SUBMITS ); |
| 1171 | 0 | XmlUtil.endElement( buffer, TAG_FORM ); |
| 1172 | |
|
| 1173 | 0 | return buffer.toString( ); |
| 1174 | |
} |
| 1175 | |
|
| 1176 | |
|
| 1177 | |
|
| 1178 | |
|
| 1179 | |
|
| 1180 | |
|
| 1181 | |
|
| 1182 | |
|
| 1183 | |
|
| 1184 | |
|
| 1185 | |
|
| 1186 | |
|
| 1187 | |
|
| 1188 | |
|
| 1189 | |
|
| 1190 | |
|
| 1191 | |
public static String getXmlResponses( HttpServletRequest request, Form form, FormSubmit formSubmit, Locale locale, Plugin plugin ) |
| 1192 | |
{ |
| 1193 | |
|
| 1194 | 0 | StringBuffer buffer = new StringBuffer( ); |
| 1195 | 0 | XmlUtil.beginElement( buffer, TAG_FORM ); |
| 1196 | 0 | XmlUtil.addElementHtml( buffer, TAG_FORM_TITLE, form.getTitle( ) ); |
| 1197 | |
|
| 1198 | |
|
| 1199 | 0 | XmlUtil.beginElement( buffer, TAG_FORM_ENTRIES ); |
| 1200 | |
|
| 1201 | 0 | for ( Entry entry : getAllQuestionList( form.getIdForm( ), plugin ) ) |
| 1202 | |
{ |
| 1203 | 0 | XmlUtil.beginElement( buffer, TAG_FORM_ENTRY ); |
| 1204 | 0 | XmlUtil.addElement( buffer, TAG_FORM_ENTRY_ID, entry.getIdEntry( ) ); |
| 1205 | 0 | XmlUtil.addElementHtml( buffer, TAG_FORM_ENTRY_TITLE, entry.getTitle( ) ); |
| 1206 | 0 | XmlUtil.endElement( buffer, TAG_FORM_ENTRY ); |
| 1207 | 0 | } |
| 1208 | |
|
| 1209 | 0 | XmlUtil.endElement( buffer, TAG_FORM_ENTRIES ); |
| 1210 | |
|
| 1211 | |
|
| 1212 | 0 | XmlUtil.beginElement( buffer, TAG_FORM_SUBMITS ); |
| 1213 | |
|
| 1214 | 0 | getXmlResponse( request, buffer, formSubmit, locale, plugin ); |
| 1215 | |
|
| 1216 | 0 | XmlUtil.endElement( buffer, TAG_FORM_SUBMITS ); |
| 1217 | 0 | XmlUtil.endElement( buffer, TAG_FORM ); |
| 1218 | |
|
| 1219 | 0 | return buffer.toString( ); |
| 1220 | |
} |
| 1221 | |
|
| 1222 | |
|
| 1223 | |
|
| 1224 | |
|
| 1225 | |
|
| 1226 | |
|
| 1227 | |
|
| 1228 | |
|
| 1229 | |
|
| 1230 | |
|
| 1231 | |
|
| 1232 | |
|
| 1233 | |
|
| 1234 | |
|
| 1235 | |
|
| 1236 | |
private static void getXmlResponse( HttpServletRequest request, StringBuffer buffer, FormSubmit formSubmit, Locale locale, Plugin plugin ) |
| 1237 | |
{ |
| 1238 | 0 | XmlUtil.beginElement( buffer, TAG_FORM_SUBMIT ); |
| 1239 | 0 | XmlUtil.addElement( buffer, TAG_FORM_SUBMIT_ID, formSubmit.getIdFormSubmit( ) ); |
| 1240 | |
|
| 1241 | 0 | String strDate = ( locale != null ) ? getDateString( formSubmit.getDateResponse( ), locale ) : StringUtils.EMPTY; |
| 1242 | 0 | XmlUtil.addElement( buffer, TAG_FORM_SUBMIT_DATE, strDate ); |
| 1243 | |
|
| 1244 | 0 | if ( formSubmit.getIp( ) != null ) |
| 1245 | |
{ |
| 1246 | 0 | XmlUtil.addElement( buffer, TAG_FORM_SUBMIT_IP, formSubmit.getIp( ) ); |
| 1247 | |
} |
| 1248 | |
else |
| 1249 | |
{ |
| 1250 | 0 | XmlUtil.addElement( buffer, TAG_FORM_SUBMIT_IP, StringUtils.EMPTY ); |
| 1251 | |
} |
| 1252 | |
|
| 1253 | 0 | Response responseStore = null; |
| 1254 | 0 | XmlUtil.beginElement( buffer, TAG_QUESTIONS ); |
| 1255 | |
|
| 1256 | 0 | if ( ( formSubmit.getListResponse( ) != null ) && !formSubmit.getListResponse( ).isEmpty( ) ) |
| 1257 | |
{ |
| 1258 | 0 | for ( Response response : formSubmit.getListResponse( ) ) |
| 1259 | |
{ |
| 1260 | 0 | if ( response.getField( ) != null ) |
| 1261 | |
{ |
| 1262 | 0 | Field field = FieldHome.findByPrimaryKey( response.getField( ).getIdField( ) ); |
| 1263 | 0 | response.setField( field ); |
| 1264 | |
} |
| 1265 | |
|
| 1266 | 0 | if ( responseStore != null |
| 1267 | 0 | && ( response.getEntry( ).getIdEntry( ) != responseStore.getEntry( ).getIdEntry( ) || response.getIterationNumber( ) != responseStore |
| 1268 | 0 | .getIterationNumber( ) ) ) |
| 1269 | |
{ |
| 1270 | 0 | XmlUtil.endElement( buffer, TAG_RESPONSES ); |
| 1271 | 0 | XmlUtil.endElement( buffer, TAG_QUESTION ); |
| 1272 | |
} |
| 1273 | |
|
| 1274 | 0 | if ( responseStore == null |
| 1275 | 0 | || ( response.getEntry( ).getIdEntry( ) != responseStore.getEntry( ).getIdEntry( ) || response.getIterationNumber( ) != responseStore |
| 1276 | 0 | .getIterationNumber( ) ) ) |
| 1277 | |
{ |
| 1278 | 0 | XmlUtil.beginElement( buffer, TAG_QUESTION ); |
| 1279 | 0 | XmlUtil.addElementHtml( buffer, TAG_QUESTION_TITLE, response.getEntry( ).getTitle( ) ); |
| 1280 | 0 | XmlUtil.addElement( buffer, TAG_QUESTION_ID, response.getEntry( ).getIdEntry( ) ); |
| 1281 | 0 | XmlUtil.addElement( buffer, TAG_QUESTION_ITERATION_NUMBER, response.getIterationNumber( ) ); |
| 1282 | 0 | XmlUtil.beginElement( buffer, TAG_RESPONSES ); |
| 1283 | |
} |
| 1284 | |
|
| 1285 | 0 | if ( StringUtils.isNotBlank( response.getResponseValue( ) ) || ( response.getFile( ) != null ) ) |
| 1286 | |
{ |
| 1287 | 0 | XmlUtil.addElementHtml( buffer, TAG_RESPONSE, EntryTypeServiceManager.getEntryTypeService( response.getEntry( ) ) |
| 1288 | 0 | .getResponseValueForExport( response.getEntry( ), request, response, locale ) ); |
| 1289 | |
} |
| 1290 | |
else |
| 1291 | |
{ |
| 1292 | 0 | XmlUtil.addElement( buffer, TAG_RESPONSE, StringUtils.EMPTY ); |
| 1293 | |
} |
| 1294 | |
|
| 1295 | 0 | responseStore = response; |
| 1296 | 0 | } |
| 1297 | |
|
| 1298 | 0 | XmlUtil.endElement( buffer, TAG_RESPONSES ); |
| 1299 | 0 | XmlUtil.endElement( buffer, TAG_QUESTION ); |
| 1300 | |
} |
| 1301 | |
|
| 1302 | 0 | XmlUtil.endElement( buffer, TAG_QUESTIONS ); |
| 1303 | 0 | XmlUtil.endElement( buffer, TAG_FORM_SUBMIT ); |
| 1304 | 0 | } |
| 1305 | |
|
| 1306 | |
|
| 1307 | |
|
| 1308 | |
|
| 1309 | |
|
| 1310 | |
|
| 1311 | |
|
| 1312 | |
|
| 1313 | |
|
| 1314 | |
|
| 1315 | |
|
| 1316 | |
|
| 1317 | |
|
| 1318 | |
public static void addHeaderResponse( HttpServletRequest request, HttpServletResponse response, String strFileName, String strFileExtension ) |
| 1319 | |
{ |
| 1320 | 0 | response.setHeader( "Content-Disposition", "attachment ;filename=\"" + strFileName + "\"" ); |
| 1321 | |
|
| 1322 | 0 | if ( strFileExtension.equals( "csv" ) ) |
| 1323 | |
{ |
| 1324 | 0 | response.setCharacterEncoding( FormParameterService.getService( ).getExportCSVEncoding( ) ); |
| 1325 | 0 | response.setContentType( "application/csv" ); |
| 1326 | |
} |
| 1327 | |
else |
| 1328 | |
{ |
| 1329 | 0 | response.setCharacterEncoding( FormParameterService.getService( ).getExportXMLEncoding( ) ); |
| 1330 | |
|
| 1331 | 0 | String strMimeType = FileSystemUtil.getMIMEType( strFileName ); |
| 1332 | |
|
| 1333 | 0 | if ( strMimeType != null ) |
| 1334 | |
{ |
| 1335 | 0 | response.setContentType( strMimeType ); |
| 1336 | |
} |
| 1337 | |
else |
| 1338 | |
{ |
| 1339 | 0 | response.setContentType( "application/octet-stream" ); |
| 1340 | |
} |
| 1341 | |
} |
| 1342 | |
|
| 1343 | 0 | response.setHeader( "Pragma", "public" ); |
| 1344 | 0 | response.setHeader( "Expires", "0" ); |
| 1345 | 0 | response.setHeader( "Cache-Control", "must-revalidate,post-check=0,pre-check=0" ); |
| 1346 | 0 | } |
| 1347 | |
|
| 1348 | |
|
| 1349 | |
|
| 1350 | |
|
| 1351 | |
|
| 1352 | |
|
| 1353 | |
|
| 1354 | |
|
| 1355 | |
|
| 1356 | |
|
| 1357 | |
|
| 1358 | |
|
| 1359 | |
|
| 1360 | |
|
| 1361 | |
public static JFreeChart createXYGraph( List<StatisticFormSubmit> listStatistic, String strLabelX, String strLableY, String strTimesUnit ) |
| 1362 | |
{ |
| 1363 | 0 | XYDataset xyDataset = createDataset( listStatistic, strTimesUnit ); |
| 1364 | 0 | JFreeChart jfreechart = ChartFactory.createTimeSeriesChart( StringUtils.EMPTY, strLabelX, strLableY, xyDataset, false, false, false ); |
| 1365 | 0 | jfreechart.setBackgroundPaint( Color.white ); |
| 1366 | |
|
| 1367 | 0 | XYPlot xyplot = jfreechart.getXYPlot( ); |
| 1368 | |
|
| 1369 | 0 | xyplot.setBackgroundPaint( Color.white ); |
| 1370 | 0 | xyplot.setBackgroundPaint( Color.lightGray ); |
| 1371 | 0 | xyplot.setDomainGridlinePaint( Color.white ); |
| 1372 | 0 | xyplot.setRangeGridlinePaint( Color.white ); |
| 1373 | |
|
| 1374 | 0 | XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer( ); |
| 1375 | 0 | renderer.setBaseShapesVisible( true ); |
| 1376 | 0 | renderer.setSeriesFillPaint( 0, Color.RED ); |
| 1377 | 0 | renderer.setUseFillPaint( true ); |
| 1378 | |
|
| 1379 | 0 | return jfreechart; |
| 1380 | |
} |
| 1381 | |
|
| 1382 | |
|
| 1383 | |
|
| 1384 | |
|
| 1385 | |
|
| 1386 | |
|
| 1387 | |
|
| 1388 | |
|
| 1389 | |
|
| 1390 | |
|
| 1391 | |
private static XYDataset createDataset( List<StatisticFormSubmit> listStatistic, String strTimesUnit ) |
| 1392 | |
{ |
| 1393 | 0 | TimeSeries series = null; |
| 1394 | |
|
| 1395 | 0 | if ( strTimesUnit.equals( CONSTANT_GROUP_BY_DAY ) ) |
| 1396 | |
{ |
| 1397 | 0 | series = new TimeSeries( StringUtils.EMPTY, Day.class ); |
| 1398 | |
|
| 1399 | 0 | for ( StatisticFormSubmit statistic : listStatistic ) |
| 1400 | |
{ |
| 1401 | 0 | series.add( new Day( statistic.getStatisticDate( ) ), statistic.getNumberResponse( ) ); |
| 1402 | 0 | } |
| 1403 | |
} |
| 1404 | |
else |
| 1405 | 0 | if ( strTimesUnit.equals( CONSTANT_GROUP_BY_WEEK ) ) |
| 1406 | |
{ |
| 1407 | 0 | series = new TimeSeries( StringUtils.EMPTY, Week.class ); |
| 1408 | |
|
| 1409 | 0 | for ( StatisticFormSubmit statistic : listStatistic ) |
| 1410 | |
{ |
| 1411 | 0 | series.add( new Week( statistic.getStatisticDate( ) ), statistic.getNumberResponse( ) ); |
| 1412 | 0 | } |
| 1413 | |
} |
| 1414 | |
|
| 1415 | |
else |
| 1416 | 0 | if ( strTimesUnit.equals( CONSTANT_GROUP_BY_MONTH ) ) |
| 1417 | |
{ |
| 1418 | 0 | series = new TimeSeries( StringUtils.EMPTY, Month.class ); |
| 1419 | |
|
| 1420 | 0 | for ( StatisticFormSubmit statistic : listStatistic ) |
| 1421 | |
{ |
| 1422 | 0 | series.add( new Month( statistic.getStatisticDate( ) ), statistic.getNumberResponse( ) ); |
| 1423 | 0 | } |
| 1424 | |
} |
| 1425 | |
|
| 1426 | 0 | TimeSeriesCollection dataset = new TimeSeriesCollection( ); |
| 1427 | 0 | dataset.addSeries( series ); |
| 1428 | |
|
| 1429 | 0 | return dataset; |
| 1430 | |
} |
| 1431 | |
|
| 1432 | |
|
| 1433 | |
|
| 1434 | |
|
| 1435 | |
|
| 1436 | |
|
| 1437 | |
|
| 1438 | |
|
| 1439 | |
|
| 1440 | |
|
| 1441 | |
public static ReferenceList getFormList( Plugin plugin, AdminUser user ) |
| 1442 | |
{ |
| 1443 | 0 | List<Form> listForms = FormHome.getFormList( new FormFilter( ), plugin ); |
| 1444 | 0 | listForms = (List<Form>) AdminWorkgroupService.getAuthorizedCollection( listForms, user ); |
| 1445 | |
|
| 1446 | 0 | ReferenceList refListForms = new ReferenceList( ); |
| 1447 | |
|
| 1448 | 0 | for ( Form form : listForms ) |
| 1449 | |
{ |
| 1450 | 0 | refListForms.addItem( form.getIdForm( ), form.getTitle( ) ); |
| 1451 | 0 | } |
| 1452 | |
|
| 1453 | 0 | return refListForms; |
| 1454 | |
} |
| 1455 | |
|
| 1456 | |
|
| 1457 | |
|
| 1458 | |
|
| 1459 | |
|
| 1460 | |
|
| 1461 | |
|
| 1462 | |
|
| 1463 | |
|
| 1464 | |
|
| 1465 | |
public static ReferenceList getRefListAllQuestions( int nIdForm, Plugin plugin ) |
| 1466 | |
{ |
| 1467 | 0 | ReferenceList refListQuestions = new ReferenceList( ); |
| 1468 | |
|
| 1469 | 0 | for ( Entry entry : getAllQuestionList( nIdForm, plugin ) ) |
| 1470 | |
{ |
| 1471 | 0 | if ( entry.getTitle( ) != null ) |
| 1472 | |
{ |
| 1473 | 0 | refListQuestions.addItem( entry.getIdEntry( ), entry.getTitle( ) ); |
| 1474 | |
} |
| 1475 | |
else |
| 1476 | |
{ |
| 1477 | 0 | refListQuestions.addItem( entry.getIdEntry( ), entry.getComment( ) ); |
| 1478 | |
} |
| 1479 | 0 | } |
| 1480 | |
|
| 1481 | 0 | return refListQuestions; |
| 1482 | |
} |
| 1483 | |
|
| 1484 | |
|
| 1485 | |
|
| 1486 | |
|
| 1487 | |
|
| 1488 | |
|
| 1489 | |
|
| 1490 | |
|
| 1491 | |
|
| 1492 | |
|
| 1493 | |
public static List<Entry> getAllQuestionList( int nIdForm, Plugin plugin ) |
| 1494 | |
{ |
| 1495 | 0 | List<Entry> listEntry = new ArrayList<Entry>( ); |
| 1496 | 0 | EntryFilter filter = new EntryFilter( ); |
| 1497 | 0 | filter.setIdResource( nIdForm ); |
| 1498 | 0 | filter.setEntryParentNull( EntryFilter.FILTER_TRUE ); |
| 1499 | 0 | filter.setIdIsComment( EntryFilter.FILTER_FALSE ); |
| 1500 | 0 | filter.setResourceType( Form.RESOURCE_TYPE ); |
| 1501 | 0 | filter.setFieldDependNull( EntryFilter.FILTER_TRUE ); |
| 1502 | |
|
| 1503 | 0 | for ( Entry entryFirstLevel : EntryHome.getEntryList( filter ) ) |
| 1504 | |
{ |
| 1505 | 0 | if ( entryFirstLevel.getEntryType( ).getGroup( ) ) |
| 1506 | |
{ |
| 1507 | 0 | filter = new EntryFilter( ); |
| 1508 | 0 | filter.setIdResource( nIdForm ); |
| 1509 | 0 | filter.setIdEntryParent( entryFirstLevel.getIdEntry( ) ); |
| 1510 | 0 | filter.setIdIsComment( EntryFilter.FILTER_FALSE ); |
| 1511 | |
|
| 1512 | 0 | entryFirstLevel.setFields( FieldHome.getFieldListByIdEntry( entryFirstLevel.getIdEntry( ) ) ); |
| 1513 | |
|
| 1514 | |
|
| 1515 | 0 | int nIterationEntryMax = new IterationGroup( entryFirstLevel ).getNbMaxIteration( ); |
| 1516 | 0 | if ( nIterationEntryMax != FormConstants.DEFAULT_ITERATION_NUMBER ) |
| 1517 | |
{ |
| 1518 | 0 | for ( int nCurrentIterationNumber = NumberUtils.INTEGER_ONE; nCurrentIterationNumber <= nIterationEntryMax; nCurrentIterationNumber++ ) |
| 1519 | |
{ |
| 1520 | 0 | for ( Entry entryChild : EntryHome.getEntryList( filter ) ) |
| 1521 | |
{ |
| 1522 | 0 | listEntry.add( entryChild ); |
| 1523 | 0 | addConditionnalsEntry( entryChild, listEntry, plugin ); |
| 1524 | 0 | } |
| 1525 | |
|
| 1526 | |
} |
| 1527 | |
} |
| 1528 | |
else |
| 1529 | |
{ |
| 1530 | 0 | for ( Entry entryChild : EntryHome.getEntryList( filter ) ) |
| 1531 | |
{ |
| 1532 | 0 | listEntry.add( entryChild ); |
| 1533 | 0 | addConditionnalsEntry( entryChild, listEntry, plugin ); |
| 1534 | 0 | } |
| 1535 | |
} |
| 1536 | 0 | } |
| 1537 | |
else |
| 1538 | |
{ |
| 1539 | 0 | listEntry.add( entryFirstLevel ); |
| 1540 | 0 | addConditionnalsEntry( entryFirstLevel, listEntry, plugin ); |
| 1541 | |
} |
| 1542 | 0 | } |
| 1543 | |
|
| 1544 | 0 | return listEntry; |
| 1545 | |
} |
| 1546 | |
|
| 1547 | |
|
| 1548 | |
|
| 1549 | |
|
| 1550 | |
|
| 1551 | |
|
| 1552 | |
|
| 1553 | |
|
| 1554 | |
|
| 1555 | |
|
| 1556 | |
|
| 1557 | |
private static void addConditionnalsEntry( Entry entryParent, List<Entry> listEntry, Plugin plugin ) |
| 1558 | |
{ |
| 1559 | 0 | Entry parent = EntryHome.findByPrimaryKey( entryParent.getIdEntry( ) ); |
| 1560 | |
|
| 1561 | 0 | for ( Field field : parent.getFields( ) ) |
| 1562 | |
{ |
| 1563 | 0 | field = FieldHome.findByPrimaryKey( field.getIdField( ) ); |
| 1564 | |
|
| 1565 | 0 | if ( field.getConditionalQuestions( ) != null ) |
| 1566 | |
{ |
| 1567 | 0 | for ( Entry entryConditionnal : field.getConditionalQuestions( ) ) |
| 1568 | |
{ |
| 1569 | 0 | listEntry.add( entryConditionnal ); |
| 1570 | 0 | addConditionnalsEntry( entryConditionnal, listEntry, plugin ); |
| 1571 | 0 | } |
| 1572 | |
} |
| 1573 | 0 | } |
| 1574 | 0 | } |
| 1575 | |
|
| 1576 | |
|
| 1577 | |
|
| 1578 | |
|
| 1579 | |
|
| 1580 | |
|
| 1581 | |
|
| 1582 | |
|
| 1583 | |
|
| 1584 | |
|
| 1585 | |
public static List<Entry> getEntriesList( int nIdForm, Plugin plugin ) |
| 1586 | |
{ |
| 1587 | 0 | List<Entry> listEntry = new ArrayList<Entry>( ); |
| 1588 | 0 | EntryFilter filter = new EntryFilter( ); |
| 1589 | 0 | filter.setIdResource( nIdForm ); |
| 1590 | 0 | filter.setResourceType( Form.RESOURCE_TYPE ); |
| 1591 | 0 | filter.setEntryParentNull( EntryFilter.FILTER_TRUE ); |
| 1592 | 0 | filter.setFieldDependNull( EntryFilter.FILTER_TRUE ); |
| 1593 | |
|
| 1594 | 0 | for ( Entry entryFirstLevel : EntryHome.getEntryList( filter ) ) |
| 1595 | |
{ |
| 1596 | 0 | if ( entryFirstLevel.getEntryType( ).getGroup( ) ) |
| 1597 | |
{ |
| 1598 | 0 | filter = new EntryFilter( ); |
| 1599 | 0 | filter.setIdResource( nIdForm ); |
| 1600 | 0 | filter.setIdEntryParent( entryFirstLevel.getIdEntry( ) ); |
| 1601 | |
|
| 1602 | 0 | List<Entry> listEntryChild = new ArrayList<Entry>( ); |
| 1603 | |
|
| 1604 | 0 | for ( Entry entryChild : EntryHome.getEntryList( filter ) ) |
| 1605 | |
{ |
| 1606 | 0 | listEntryChild.add( entryChild ); |
| 1607 | 0 | addConditionnalsEntry( entryChild, listEntryChild, plugin ); |
| 1608 | 0 | } |
| 1609 | |
|
| 1610 | 0 | entryFirstLevel.setChildren( listEntryChild ); |
| 1611 | 0 | listEntry.add( entryFirstLevel ); |
| 1612 | 0 | } |
| 1613 | |
else |
| 1614 | |
{ |
| 1615 | 0 | listEntry.add( entryFirstLevel ); |
| 1616 | 0 | addConditionnalsEntry( entryFirstLevel, listEntry, plugin ); |
| 1617 | |
} |
| 1618 | 0 | } |
| 1619 | |
|
| 1620 | 0 | return listEntry; |
| 1621 | |
} |
| 1622 | |
|
| 1623 | |
|
| 1624 | |
|
| 1625 | |
|
| 1626 | |
|
| 1627 | |
|
| 1628 | |
|
| 1629 | |
|
| 1630 | |
|
| 1631 | |
|
| 1632 | |
|
| 1633 | |
|
| 1634 | |
|
| 1635 | |
|
| 1636 | |
public static String buildRequestWithFilter( String strSelect, List<String> listStrFilter, List<String> listStrGroupBy, String strOrder ) |
| 1637 | |
{ |
| 1638 | 0 | StringBuffer strBuffer = new StringBuffer( ); |
| 1639 | 0 | strBuffer.append( strSelect ); |
| 1640 | |
|
| 1641 | 0 | int nCount = 0; |
| 1642 | |
|
| 1643 | 0 | for ( String strFilter : listStrFilter ) |
| 1644 | |
{ |
| 1645 | 0 | if ( ++nCount == 1 ) |
| 1646 | |
{ |
| 1647 | 0 | strBuffer.append( FormConstants.CONSTANT_WHERE ); |
| 1648 | |
} |
| 1649 | |
|
| 1650 | 0 | strBuffer.append( strFilter ); |
| 1651 | |
|
| 1652 | 0 | if ( nCount != listStrFilter.size( ) ) |
| 1653 | |
{ |
| 1654 | 0 | strBuffer.append( FormConstants.CONSTANT_AND ); |
| 1655 | |
} |
| 1656 | 0 | } |
| 1657 | |
|
| 1658 | 0 | if ( listStrGroupBy != null ) |
| 1659 | |
{ |
| 1660 | 0 | for ( String strGroupBy : listStrGroupBy ) |
| 1661 | |
{ |
| 1662 | 0 | strBuffer.append( strGroupBy ); |
| 1663 | 0 | } |
| 1664 | |
} |
| 1665 | |
|
| 1666 | 0 | if ( strOrder != null ) |
| 1667 | |
{ |
| 1668 | 0 | strBuffer.append( strOrder ); |
| 1669 | |
} |
| 1670 | |
|
| 1671 | 0 | return strBuffer.toString( ); |
| 1672 | |
} |
| 1673 | |
|
| 1674 | |
|
| 1675 | |
|
| 1676 | |
|
| 1677 | |
|
| 1678 | |
|
| 1679 | |
|
| 1680 | |
|
| 1681 | |
public static EntryType getEntryTypeMyLuteceUser( Plugin plugin ) |
| 1682 | |
{ |
| 1683 | 0 | for ( EntryType entryType : EntryTypeHome.getList( FormPlugin.PLUGIN_NAME ) ) |
| 1684 | |
{ |
| 1685 | 0 | if ( StringUtils.equals( entryType.getBeanName( ), EntryTypeMyLuteceUser.BEAN_NAME ) ) |
| 1686 | |
{ |
| 1687 | 0 | return entryType; |
| 1688 | |
} |
| 1689 | 0 | } |
| 1690 | |
|
| 1691 | 0 | return null; |
| 1692 | |
} |
| 1693 | |
|
| 1694 | |
|
| 1695 | |
|
| 1696 | |
|
| 1697 | |
|
| 1698 | |
|
| 1699 | |
|
| 1700 | |
|
| 1701 | |
|
| 1702 | |
|
| 1703 | |
|
| 1704 | |
|
| 1705 | |
|
| 1706 | |
public static void activateMyLuteceAuthentification( Form form, Plugin plugin, Locale locale, HttpServletRequest request ) |
| 1707 | |
{ |
| 1708 | 0 | EntryType entryType = FormUtils.getEntryTypeMyLuteceUser( plugin ); |
| 1709 | 0 | Entry entry = null; |
| 1710 | |
|
| 1711 | 0 | entry = new Entry( ); |
| 1712 | 0 | entry.setEntryType( entryType ); |
| 1713 | |
|
| 1714 | 0 | EntryTypeServiceManager.getEntryTypeService( entry ).getRequestData( entry, request, locale ); |
| 1715 | 0 | entry.setIdResource( form.getIdForm( ) ); |
| 1716 | 0 | entry.setResourceType( Form.RESOURCE_TYPE ); |
| 1717 | 0 | entry.setIdEntry( EntryHome.create( entry ) ); |
| 1718 | |
|
| 1719 | 0 | if ( entry.getFields( ) != null ) |
| 1720 | |
{ |
| 1721 | 0 | for ( Field field : entry.getFields( ) ) |
| 1722 | |
{ |
| 1723 | 0 | field.setParentEntry( entry ); |
| 1724 | 0 | FieldHome.create( field ); |
| 1725 | 0 | } |
| 1726 | |
} |
| 1727 | 0 | } |
| 1728 | |
|
| 1729 | |
|
| 1730 | |
|
| 1731 | |
|
| 1732 | |
|
| 1733 | |
|
| 1734 | |
|
| 1735 | |
|
| 1736 | |
|
| 1737 | |
public static void deactivateMyLuteceAuthentification( Form form, Plugin plugin ) |
| 1738 | |
{ |
| 1739 | 0 | EntryFilter entryFilter = new EntryFilter( ); |
| 1740 | 0 | entryFilter.setIdResource( form.getIdForm( ) ); |
| 1741 | 0 | entryFilter.setResourceType( Form.RESOURCE_TYPE ); |
| 1742 | |
|
| 1743 | 0 | List<Entry> listEntries = EntryHome.getEntryList( entryFilter ); |
| 1744 | |
|
| 1745 | 0 | for ( Entry entry : listEntries ) |
| 1746 | |
{ |
| 1747 | 0 | IEntryTypeService entryTypeService = EntryTypeServiceManager.getEntryTypeService( entry ); |
| 1748 | |
|
| 1749 | 0 | if ( entryTypeService instanceof fr.paris.lutece.plugins.form.service.entrytype.EntryTypeMyLuteceUser ) |
| 1750 | |
{ |
| 1751 | 0 | EntryHome.remove( entry.getIdEntry( ) ); |
| 1752 | |
|
| 1753 | 0 | break; |
| 1754 | |
} |
| 1755 | 0 | } |
| 1756 | 0 | } |
| 1757 | |
|
| 1758 | |
|
| 1759 | |
|
| 1760 | |
|
| 1761 | |
|
| 1762 | |
|
| 1763 | |
|
| 1764 | |
|
| 1765 | |
|
| 1766 | |
public static void restoreResponses( HttpSession session, Map<Integer, List<Response>> mapResponses ) |
| 1767 | |
{ |
| 1768 | 0 | session.setAttribute( SESSION_FORM_LIST_SUBMITTED_RESPONSES, mapResponses ); |
| 1769 | 0 | } |
| 1770 | |
|
| 1771 | |
|
| 1772 | |
|
| 1773 | |
|
| 1774 | |
|
| 1775 | |
|
| 1776 | |
|
| 1777 | |
public static void removeResponses( HttpSession session ) |
| 1778 | |
{ |
| 1779 | 0 | session.removeAttribute( SESSION_FORM_LIST_SUBMITTED_RESPONSES ); |
| 1780 | 0 | } |
| 1781 | |
|
| 1782 | |
|
| 1783 | |
|
| 1784 | |
|
| 1785 | |
|
| 1786 | |
|
| 1787 | |
|
| 1788 | |
|
| 1789 | |
public static Map<Integer, List<Response>> getResponses( HttpSession session ) |
| 1790 | |
{ |
| 1791 | 0 | return (Map<Integer, List<Response>>) session.getAttribute( SESSION_FORM_LIST_SUBMITTED_RESPONSES ); |
| 1792 | |
} |
| 1793 | |
|
| 1794 | |
|
| 1795 | |
|
| 1796 | |
|
| 1797 | |
|
| 1798 | |
|
| 1799 | |
|
| 1800 | |
|
| 1801 | |
|
| 1802 | |
public static void restoreFormErrors( HttpSession session, List<GenericAttributeError> listFormErrors ) |
| 1803 | |
{ |
| 1804 | 0 | session.setAttribute( FormConstants.SESSION_FORM_ERRORS, listFormErrors ); |
| 1805 | 0 | } |
| 1806 | |
|
| 1807 | |
|
| 1808 | |
|
| 1809 | |
|
| 1810 | |
|
| 1811 | |
|
| 1812 | |
|
| 1813 | |
public static void removeFormErrors( HttpSession session ) |
| 1814 | |
{ |
| 1815 | 0 | session.removeAttribute( FormConstants.SESSION_FORM_ERRORS ); |
| 1816 | 0 | } |
| 1817 | |
|
| 1818 | |
|
| 1819 | |
|
| 1820 | |
|
| 1821 | |
|
| 1822 | |
|
| 1823 | |
|
| 1824 | |
|
| 1825 | |
public static List<GenericAttributeError> getFormErrors( HttpSession session ) |
| 1826 | |
{ |
| 1827 | 0 | return (List<GenericAttributeError>) session.getAttribute( FormConstants.SESSION_FORM_ERRORS ); |
| 1828 | |
} |
| 1829 | |
|
| 1830 | |
|
| 1831 | |
|
| 1832 | |
|
| 1833 | |
|
| 1834 | |
|
| 1835 | |
public static Plugin getPlugin( ) |
| 1836 | |
{ |
| 1837 | 0 | return PluginService.getPlugin( FormPlugin.PLUGIN_NAME ); |
| 1838 | |
} |
| 1839 | |
|
| 1840 | |
|
| 1841 | |
|
| 1842 | |
|
| 1843 | |
|
| 1844 | |
|
| 1845 | |
|
| 1846 | |
|
| 1847 | |
public static String trim( String strParameter ) |
| 1848 | |
{ |
| 1849 | 0 | if ( strParameter != null ) |
| 1850 | |
{ |
| 1851 | 0 | return strParameter.trim( ); |
| 1852 | |
} |
| 1853 | |
|
| 1854 | 0 | return strParameter; |
| 1855 | |
} |
| 1856 | |
|
| 1857 | |
|
| 1858 | |
|
| 1859 | |
|
| 1860 | |
|
| 1861 | |
|
| 1862 | |
|
| 1863 | |
|
| 1864 | |
public static String getAdminBaseUrl( HttpServletRequest request ) |
| 1865 | |
{ |
| 1866 | 0 | String strBaseUrl = StringUtils.EMPTY; |
| 1867 | |
|
| 1868 | 0 | if ( request != null ) |
| 1869 | |
{ |
| 1870 | 0 | strBaseUrl = AppPathService.getBaseUrl( request ); |
| 1871 | |
} |
| 1872 | |
else |
| 1873 | |
{ |
| 1874 | 0 | strBaseUrl = AppPropertiesService.getProperty( PROPERTY_LUTECE_ADMIN_PROD_URL ); |
| 1875 | |
|
| 1876 | 0 | if ( StringUtils.isBlank( strBaseUrl ) ) |
| 1877 | |
{ |
| 1878 | 0 | strBaseUrl = AppPropertiesService.getProperty( PROPERTY_LUTECE_BASE_URL ); |
| 1879 | |
|
| 1880 | 0 | if ( StringUtils.isBlank( strBaseUrl ) ) |
| 1881 | |
{ |
| 1882 | 0 | strBaseUrl = AppPropertiesService.getProperty( PROPERTY_LUTECE_PROD_URL ); |
| 1883 | |
} |
| 1884 | |
} |
| 1885 | |
} |
| 1886 | |
|
| 1887 | 0 | if ( StringUtils.isNotBlank( strBaseUrl ) ) |
| 1888 | |
{ |
| 1889 | 0 | if ( !strBaseUrl.endsWith( FormConstants.SLASH ) ) |
| 1890 | |
{ |
| 1891 | 0 | return strBaseUrl + FormConstants.SLASH; |
| 1892 | |
} |
| 1893 | |
} |
| 1894 | |
|
| 1895 | 0 | return strBaseUrl; |
| 1896 | |
} |
| 1897 | |
|
| 1898 | |
|
| 1899 | |
|
| 1900 | |
|
| 1901 | |
|
| 1902 | |
|
| 1903 | |
|
| 1904 | |
|
| 1905 | |
|
| 1906 | |
|
| 1907 | |
public static List<Field> getAuthorizedFieldsByRole( HttpServletRequest request, List<Field> listField ) |
| 1908 | |
{ |
| 1909 | 0 | List<Field> listFieldAuthorized = new ArrayList<Field>( ); |
| 1910 | |
|
| 1911 | 0 | for ( Field field : listField ) |
| 1912 | |
{ |
| 1913 | |
|
| 1914 | 0 | if ( !SecurityService.isAuthenticationEnable( ) || field.getRoleKey( ) == null || field.getRoleKey( ).equals( Form.ROLE_NONE ) |
| 1915 | 0 | || SecurityService.getInstance( ).isUserInRole( request, field.getRoleKey( ) ) ) |
| 1916 | |
{ |
| 1917 | 0 | listFieldAuthorized.add( field ); |
| 1918 | |
} |
| 1919 | 0 | } |
| 1920 | |
|
| 1921 | 0 | return listFieldAuthorized; |
| 1922 | |
} |
| 1923 | |
|
| 1924 | |
|
| 1925 | |
|
| 1926 | |
|
| 1927 | |
|
| 1928 | |
|
| 1929 | |
|
| 1930 | |
|
| 1931 | |
private static String getFrontOfficePictureSource( int nIdPictureFile ) |
| 1932 | |
{ |
| 1933 | 0 | File filePicture = FileHome.findByPrimaryKey( nIdPictureFile ); |
| 1934 | 0 | if ( filePicture != null ) |
| 1935 | |
{ |
| 1936 | 0 | PhysicalFile physicalFileLazyLoading = filePicture.getPhysicalFile( ); |
| 1937 | 0 | if ( physicalFileLazyLoading != null ) |
| 1938 | |
{ |
| 1939 | 0 | PhysicalFile physicalFile = PhysicalFileHome.findByPrimaryKey( physicalFileLazyLoading.getIdPhysicalFile( ) ); |
| 1940 | 0 | if ( physicalFile != null && physicalFile.getValue( ) != null ) |
| 1941 | |
{ |
| 1942 | 0 | byte [ ] bEncodedPhysicalFile = new Base64( ).encode( physicalFile.getValue( ) ); |
| 1943 | 0 | String strFrontOfficePicture = new String( bEncodedPhysicalFile ); |
| 1944 | 0 | String strMimeType = filePicture.getMimeType( ); |
| 1945 | |
|
| 1946 | 0 | if ( StringUtils.isNotBlank( strMimeType ) && StringUtils.isNotBlank( strFrontOfficePicture ) ) |
| 1947 | |
{ |
| 1948 | 0 | StringBuilder sbFrontOfficePictureSource = new StringBuilder( ); |
| 1949 | 0 | sbFrontOfficePictureSource.append( "data:" ); |
| 1950 | 0 | sbFrontOfficePictureSource.append( strMimeType ); |
| 1951 | 0 | sbFrontOfficePictureSource.append( ";base64," ); |
| 1952 | 0 | sbFrontOfficePictureSource.append( strFrontOfficePicture ); |
| 1953 | |
|
| 1954 | 0 | return sbFrontOfficePictureSource.toString( ); |
| 1955 | |
} |
| 1956 | |
} |
| 1957 | |
} |
| 1958 | |
} |
| 1959 | |
|
| 1960 | 0 | return null; |
| 1961 | |
} |
| 1962 | |
} |