69
69
import fr .paris .lutece .plugins .genericattributes .business .EntryHome ;
70
70
import fr .paris .lutece .plugins .genericattributes .business .Field ;
71
71
import fr .paris .lutece .plugins .genericattributes .business .FieldHome ;
72
- import fr .paris .lutece .plugins .genericattributes .business .Response ;
73
- import fr .paris .lutece .plugins .genericattributes .business .ResponseFilter ;
74
72
import fr .paris .lutece .plugins .genericattributes .service .entrytype .EntryTypeServiceManager ;
75
73
import fr .paris .lutece .plugins .genericattributes .service .entrytype .IEntryTypeService ;
76
74
import fr .paris .lutece .portal .service .admin .AccessDeniedException ;
@@ -126,7 +124,7 @@ public class FormQuestionJspBean extends AbstractFormQuestionJspBean
126
124
127
125
// Markers
128
126
private static final String MARK_FIELDS_LIST_BY_ID_ENTRIES = "fields_list_by_id_entries" ;
129
- private static final String MARK_ID_QUESTION_ENTRY_MAP = "idQuestionEntryMap " ;
127
+ private static final String MARK_QUESTION_ENTRY_MAP = "questionEntryMap " ;
130
128
131
129
// Constants
132
130
private static final String PUBLIC_IMAGE_RESOURCE = "public_image_resource" ;
@@ -168,7 +166,7 @@ public String getManageQuestions( HttpServletRequest request )
168
166
model .put ( FormsConstants .MARK_ENTRY_TYPE_REF_LIST , FormsEntryUtils .initListEntryType ( ) );
169
167
model .put ( FormsConstants .MARK_ID_PARENT , _nIdParentSelected );
170
168
model .put ( SecurityTokenService .MARK_TOKEN , SecurityTokenService .getInstance ( ).getToken ( request , ACTION_SAVE_QUESTION ) );
171
- model .put ( MARK_ID_QUESTION_ENTRY_MAP , getIdQuestionEntryMap ( listICompositeDisplay ) );
169
+ model .put ( MARK_QUESTION_ENTRY_MAP , getQuestionEntryMap ( listICompositeDisplay ) );
172
170
173
171
setPageTitleProperty ( StringUtils .EMPTY );
174
172
HtmlTemplate templateList = AppTemplateService .getTemplate ( TEMPLATE_MANAGE_QUESTIONS , locale , model );
@@ -568,7 +566,7 @@ public String getConfirmRemoveComposite( HttpServletRequest request )
568
566
_formDisplay = FormDisplayHome .findByPrimaryKey ( nIdDisplay );
569
567
}
570
568
571
- if ( isCompositeHasResponses ( nIdEntry ) )
569
+ if ( _formService . existCompositeResponses ( _formDisplay , nIdEntry ) )
572
570
{
573
571
boolean bIsQuestion = CompositeDisplayType .QUESTION .getLabel ( ).equalsIgnoreCase ( _formDisplay .getCompositeType ( ) );
574
572
String strMessage = bIsQuestion ? MESSAGE_CANT_REMOVE_ENTRY_RESOURCES_ATTACHED : MESSAGE_CANT_REMOVE_GROUP_RESOURCES_ATTACHED ;
@@ -587,51 +585,6 @@ public String getConfirmRemoveComposite( HttpServletRequest request )
587
585
588
586
return redirect ( request , strMessageUrl );
589
587
}
590
-
591
- private boolean isCompositeHasResponses ( int nIdEntry )
592
- {
593
- boolean isCompositeHasResponses = false ;
594
-
595
- if ( CompositeDisplayType .QUESTION .getLabel ( ).equalsIgnoreCase ( _formDisplay .getCompositeType ( ) ) && nIdEntry > 0 )
596
- {
597
- ResponseFilter responsefilter = new ResponseFilter ( );
598
- responsefilter .setIdEntry ( nIdEntry );
599
-
600
- isCompositeHasResponses = isExisteQuestionFilled ( responsefilter );
601
- }
602
- else if ( CompositeDisplayType .GROUP .getLabel ( ).equalsIgnoreCase ( _formDisplay .getCompositeType ( ) ) )
603
- {
604
- List <Question > questionsList = new ArrayList <>( );
605
- ICompositeDisplay composite = _formService .formDisplayToComposite ( _formDisplay , null , 0 );
606
- composite .addQuestions ( questionsList );
607
-
608
- if ( CollectionUtils .isNotEmpty ( questionsList ) )
609
- {
610
- List <Integer > idEntryList = questionsList .stream ( ).map ( Question ::getIdEntry ).collect ( Collectors .toList ( ) );
611
- ResponseFilter responsefilter = new ResponseFilter ( );
612
- responsefilter .setListIdEntry ( idEntryList );
613
-
614
- isCompositeHasResponses = isExisteQuestionFilled ( responsefilter );
615
- }
616
- }
617
-
618
- return isCompositeHasResponses ;
619
- }
620
-
621
- private boolean isExisteQuestionFilled ( ResponseFilter responsefilter )
622
- {
623
- boolean isExisteQuestionFilled = false ;
624
-
625
- List <Response > responseList = _formService .getResponseList ( responsefilter );
626
-
627
- if ( CollectionUtils .isNotEmpty (responseList )
628
- && responseList .stream ( ).anyMatch ( response -> StringUtils .isNotBlank ( response .getResponseValue ( ) ) ) )
629
- {
630
- isExisteQuestionFilled = true ;
631
- }
632
-
633
- return isExisteQuestionFilled ;
634
- }
635
588
636
589
private String getConfirmMessageRemoveQuestion ( Form form , FormDisplay formDisplay )
637
590
{
@@ -796,14 +749,14 @@ public String doMoveComposite( HttpServletRequest request )
796
749
}
797
750
798
751
/**
799
- * Modify the field attribute disabled
752
+ * change the deactivation of a question
800
753
*
801
754
* @param request
802
755
* The HTTP request
803
756
* @return The URL to go after performing the action
804
757
*/
805
- @ Action ( value = ACTION_MODIFY_FIELD_DISABLED )
806
- public String doModifyFieldDisabled ( HttpServletRequest request )
758
+ @ Action ( value = ACTION_DISABLE_QUESTION )
759
+ public String doToggleQuestionDisabled ( HttpServletRequest request )
807
760
{
808
761
int nIdStep = NumberUtils .toInt ( request .getParameter ( FormsConstants .PARAMETER_ID_STEP ), INTEGER_MINUS_ONE );
809
762
int nIdQuestion = NumberUtils .toInt ( request .getParameter ( FormsConstants .PARAMETER_ID_QUESTION ), INTEGER_MINUS_ONE );
@@ -815,10 +768,9 @@ public String doModifyFieldDisabled( HttpServletRequest request )
815
768
816
769
if ( entry != null )
817
770
{
818
- Field disabledField = entry .getFieldByCode ( IEntryTypeService .FIELD_DISABLED );
819
- boolean valueField = disabledField != null ? !Boolean .parseBoolean ( disabledField .getValue ( ) ) : false ;
771
+ boolean bFieldDisabled = entry .isDisabled ( );
820
772
821
- _formService .saveOrUpdateField ( entry , IEntryTypeService .FIELD_DISABLED , null , Boolean .toString ( valueField ) );
773
+ _formService .saveOrUpdateField ( entry , IEntryTypeService .FIELD_DISABLED , null , Boolean .toString ( ! bFieldDisabled ) );
822
774
823
775
getFormDatabaseService ( ).updateQuestion ( questionToUpdate );
824
776
}
@@ -834,7 +786,7 @@ public String doModifyFieldDisabled( HttpServletRequest request )
834
786
* list of compositeDisplay objects
835
787
* @return map
836
788
*/
837
- private Map <String , Entry > getIdQuestionEntryMap ( List <ICompositeDisplay > listICompositeDisplay )
789
+ private Map <String , Entry > getQuestionEntryMap ( List <ICompositeDisplay > listICompositeDisplay )
838
790
{
839
791
Map <String , Entry > questionEntryMap = new HashMap <>( );
840
792
0 commit comments