diff --git a/src/java/fr/paris/lutece/plugins/forms/web/admin/AbstractMultiviewFormJspBean.java b/src/java/fr/paris/lutece/plugins/forms/web/admin/AbstractMultiviewFormJspBean.java new file mode 100644 index 000000000..aa22cf63f --- /dev/null +++ b/src/java/fr/paris/lutece/plugins/forms/web/admin/AbstractMultiviewFormJspBean.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2002-2024, City of Paris + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright notice + * and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice + * and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * License 1.0 + */ +package fr.paris.lutece.plugins.forms.web.admin; + +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; + +import fr.paris.lutece.plugins.forms.util.FormsConstants; +import fr.paris.lutece.portal.service.workflow.WorkflowService; +import fr.paris.lutece.util.string.StringUtil; + +/** + * Abstract Jsp Bean for multiviewForm + */ +public abstract class AbstractMultiviewFormJspBean extends AbstractJspBean +{ + // Generated serial UID + private static final long serialVersionUID = 3673744119874180461L; + + // Parameters + protected static final String PARAMETER_BACK_FROM_ACTION = "back_form_action"; + protected static final String PARAMETER_ID_ACTION = "id_action"; + protected static final String PARAMETER_ACTION_HISTORY_RESOURCE_ID = "action_history_resource_id"; + + // Marks + protected static final String MARK_PROCESS_ACTION_CONFIRMATION = "process_action_confirmation"; + + /** + * add the action confirmation to the model + * + * @param request + * the HttpServletRequest + * @param model + * The given model + */ + protected void addActionConfirmationToModel( HttpServletRequest request, Map model ) + { + int nIdAction = NumberUtils.toInt( request.getParameter( PARAMETER_ID_ACTION ), NumberUtils.INTEGER_MINUS_ONE ); + String actionHistoryResourceId = request.getParameter( PARAMETER_ACTION_HISTORY_RESOURCE_ID ); + + if ( NumberUtils.INTEGER_MINUS_ONE != nIdAction && StringUtils.isNotBlank( actionHistoryResourceId ) ) + { + List actionHistoryResourceIdList = StringUtil.convertStringToIntList( actionHistoryResourceId, FormsConstants.SEPARATOR_UNDERSCORE ); + + model.put( MARK_PROCESS_ACTION_CONFIRMATION, WorkflowService.getInstance( ).getDisplayProcessActionConfirmation( nIdAction, getLocale( ), actionHistoryResourceIdList ) ); + } + } +} diff --git a/src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormResponseDetailsJspBean.java b/src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormResponseDetailsJspBean.java index 4f03337be..c28981ece 100644 --- a/src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormResponseDetailsJspBean.java +++ b/src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormResponseDetailsJspBean.java @@ -76,11 +76,11 @@ import fr.paris.lutece.plugins.forms.web.entrytype.DisplayType; import fr.paris.lutece.plugins.forms.web.form.response.view.FormResponseViewModelProcessorFactory; import fr.paris.lutece.plugins.forms.web.form.response.view.IFormResponseViewModelProcessor; +import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory; import fr.paris.lutece.plugins.workflowcore.business.state.State; -import fr.paris.lutece.portal.business.user.AdminUser; +import fr.paris.lutece.plugins.workflowcore.util.ActionResult; import fr.paris.lutece.portal.business.user.AdminUserHome; import fr.paris.lutece.portal.service.admin.AccessDeniedException; -import fr.paris.lutece.portal.service.admin.AdminUserService; import fr.paris.lutece.portal.service.rbac.RBACService; import fr.paris.lutece.portal.service.security.SecurityTokenService; import fr.paris.lutece.portal.service.spring.SpringContextService; @@ -99,7 +99,7 @@ * Jsp Bean associated to the page which display the details of a form response */ @Controller( controllerJsp = "ManageDirectoryFormResponseDetails.jsp", controllerPath = "jsp/admin/plugins/forms/", right = "FORMS_MULTIVIEW" ) -public class MultiviewFormResponseDetailsJspBean extends AbstractJspBean +public class MultiviewFormResponseDetailsJspBean extends AbstractMultiviewFormJspBean { // Rights public static final String RIGHT_FORMS_MULTIVIEW = "FORMS_MULTIVIEW"; @@ -126,8 +126,6 @@ public class MultiviewFormResponseDetailsJspBean extends AbstractJspBean // Parameters private static final String PARAMETER_ID_FORM_RESPONSE = "id_form_response"; - private static final String PARAMETER_BACK_FROM_ACTION = "back_form_action"; - private static final String PARAMETER_ID_ACTION = "id_action"; // Marks private static final String MARK_LIST_FILTER_VALUES = "list_filter_values"; @@ -154,6 +152,7 @@ public class MultiviewFormResponseDetailsJspBean extends AbstractJspBean private Map _mapFilterValues = new LinkedHashMap<>( ); private final transient IFormsMultiviewAuthorizationService _formsMultiviewAuthorizationService = SpringContextService .getBean( FormsMultiviewAuthorizationService.BEAN_NAME ); + private List _actionHistoryResourceIdList; /** * Return the page with the details of a form response @@ -205,6 +204,11 @@ public String getResponseDetails( HttpServletRequest request ) throws AccessDeni { _mapFilterValues = fillFilterMapValues( request ); } + else + { + addActionConfirmationToModel( request, model ); + } + populateModelWithFilterValues( _mapFilterValues, model ); return getPage( MESSAGE_MULTIVIEW_FORM_RESPONSE_TITLE, TEMPLATE_VIEW_FORM_RESPONSE, model ); @@ -473,8 +477,13 @@ public String doProcessWorkflowAction( HttpServletRequest request ) throws Acces { boolean bIsAutomaticAction = Boolean.FALSE; - workflowService.doProcessAction( nIdFormResponse, FormResponse.RESOURCE_TYPE, nIdAction, formResponse.getFormId( ), request, locale, + List actionHistoryResourceList = workflowService.doProcessAction( nIdFormResponse, FormResponse.RESOURCE_TYPE, nIdAction, formResponse.getFormId( ), request, locale, bIsAutomaticAction, getUser( ) ); + + if ( CollectionUtils.isNotEmpty( actionHistoryResourceList ) && actionHistoryResourceList.stream( ).noneMatch( ah -> ActionResult.FAILURE.getId( ) == ah.getStatus( ) ) ) + { + _actionHistoryResourceIdList = actionHistoryResourceList.stream( ).map( ah -> ah.getId( ) ).collect( Collectors.toList( ) ); + } } else { @@ -517,12 +526,17 @@ public String doSaveTaskForm( HttpServletRequest request ) throws AccessDeniedEx { try { - String strError = workflowService.doSaveTasksForm( nIdFormResponse, FormResponse.RESOURCE_TYPE, nIdAction, nIdForm, request, getLocale( ), - getUser( ) ); + List actionHistoryResourceList = new ArrayList<>( ); + String strError = workflowService.doSaveTasksForm( nIdFormResponse, FormResponse.RESOURCE_TYPE, nIdAction, nIdForm, request, getLocale( ), + getUser( ), actionHistoryResourceList ); if ( strError != null ) { return redirect( request, strError ); } + else if ( CollectionUtils.isNotEmpty( actionHistoryResourceList ) && actionHistoryResourceList.stream( ).noneMatch( ah -> ActionResult.FAILURE.getId( ) == ah.getStatus( ) ) ) + { + _actionHistoryResourceIdList = actionHistoryResourceList.stream( ).map( ah -> ah.getId( ) ).collect( Collectors.toList( ) ); + } } catch( AppException e ) { @@ -607,7 +621,7 @@ private String manageRedirection( HttpServletRequest request ) */ private String redirectToResponseList( HttpServletRequest request ) { - return redirect( request, buildRedirecUrlWithFilterValues( ) ); + return redirect( request, buildRedirectUrl( request ) ); } /** @@ -636,10 +650,16 @@ private String defaultRedirection( HttpServletRequest request ) if ( nIdFormResponse != NumberUtils.INTEGER_MINUS_ONE ) { - Map mapParameters = new LinkedHashMap<>( ); mapParameters.put( PARAMETER_ID_FORM_RESPONSE, String.valueOf( nIdFormResponse ) ); mapParameters.put( PARAMETER_BACK_FROM_ACTION, Boolean.TRUE.toString( ) ); + mapParameters.put( PARAMETER_ID_ACTION, request.getParameter( PARAMETER_ID_ACTION ) ); + + if ( CollectionUtils.isNotEmpty( _actionHistoryResourceIdList ) ) + { + mapParameters.put( PARAMETER_ACTION_HISTORY_RESOURCE_ID, _actionHistoryResourceIdList.stream( ).map( String::valueOf ).collect( Collectors.joining( FormsConstants.SEPARATOR_UNDERSCORE ) ) ); + _actionHistoryResourceIdList.clear(); + } return redirect( request, VIEW_FORM_RESPONSE_DETAILS, mapParameters ); } @@ -647,18 +667,20 @@ private String defaultRedirection( HttpServletRequest request ) { AppLogService.error( "The given id form response is not valid !" ); - return redirect( request, buildRedirecUrlWithFilterValues( ) ); + return redirect( request, buildRedirectUrl( request ) ); } } /** - * Build the url with the values of the filter selected on the list view + * Build the redirection url * - * @return the url with the values of the filter selected on the list view + * @param request + * The HttpServletRequest to retrieve data from + * @return the url */ - private String buildRedirecUrlWithFilterValues( ) + private String buildRedirectUrl( HttpServletRequest request ) { - UrlItem urlRedirectWithFilterValues = new UrlItem( MultiviewFormsJspBean.getMultiviewBaseViewUrl( ) ); + UrlItem urlRedirect = new UrlItem( MultiviewFormsJspBean.getMultiviewBaseViewUrl( ) ); if ( !MapUtils.isEmpty( _mapFilterValues ) ) { @@ -675,11 +697,20 @@ private String buildRedirecUrlWithFilterValues( ) AppLogService.debug( "Failed to encode url parameter value !" ); } - urlRedirectWithFilterValues.addParameter( strFilterName, strFilterValue ); + urlRedirect.addParameter( strFilterName, strFilterValue ); } } + + String strWorkflowActionRedirection = request.getParameter( FormsConstants.PARAMETER_WORKFLOW_ACTION_REDIRECTION ); + if ( StringUtils.isNotBlank( strWorkflowActionRedirection ) && CollectionUtils.isNotEmpty( _actionHistoryResourceIdList ) ) + { + urlRedirect.addParameter( PARAMETER_BACK_FROM_ACTION, Boolean.TRUE.toString( ) ); + urlRedirect.addParameter( PARAMETER_ID_ACTION, request.getParameter( PARAMETER_ID_ACTION ) ); + urlRedirect.addParameter( PARAMETER_ACTION_HISTORY_RESOURCE_ID, _actionHistoryResourceIdList.stream( ).map( String::valueOf ).collect( Collectors.joining( FormsConstants.SEPARATOR_UNDERSCORE ) ) ); + _actionHistoryResourceIdList.clear(); + } - return urlRedirectWithFilterValues.getUrl( ); + return urlRedirect.getUrl( ); } } diff --git a/src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormsJspBean.java b/src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormsJspBean.java index 5d9df6ea5..a65a7be01 100644 --- a/src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormsJspBean.java +++ b/src/java/fr/paris/lutece/plugins/forms/web/admin/MultiviewFormsJspBean.java @@ -103,7 +103,7 @@ * Controller which manage the multiview of responses of all Forms */ @Controller( controllerJsp = "MultiviewForms.jsp", controllerPath = "jsp/admin/plugins/forms/", right = "FORMS_MULTIVIEW" ) -public class MultiviewFormsJspBean extends AbstractJspBean +public class MultiviewFormsJspBean extends AbstractMultiviewFormJspBean { // Generated serial UID private static final long serialVersionUID = 2122079505317782087L; @@ -245,6 +245,11 @@ public String getMultiviewFormsView( HttpServletRequest request ) model.put( MARK_FORM_PANEL_LIST, _listAuthorizedFormPanelDisplay ); model.put( MARK_CURRENT_SELECTED_PANEL, _strSelectedPanelTechnicalCode ); model.put( MARK_LIST_FORMAT_EXPORT, ExportServiceManager.getInstance( ).getRefListFormatExport( ) ); + + if ( request.getParameter( PARAMETER_BACK_FROM_ACTION ) != null ) + { + addActionConfirmationToModel( request, model ); + } return getPage( PROPERTY_FORMS_MULTIVIEW_PAGE_TITLE, TEMPLATE_FORMS_MULTIVIEW, model ); } diff --git a/webapp/WEB-INF/templates/admin/plugins/forms/multiview/forms_multiview.html b/webapp/WEB-INF/templates/admin/plugins/forms/multiview/forms_multiview.html index 45b29ff76..aac9ca80b 100644 --- a/webapp/WEB-INF/templates/admin/plugins/forms/multiview/forms_multiview.html +++ b/webapp/WEB-INF/templates/admin/plugins/forms/multiview/forms_multiview.html @@ -28,6 +28,7 @@

#i18n{forms.multiviewForms.noFormResponses} + ${process_action_confirmation!''} diff --git a/webapp/WEB-INF/templates/admin/plugins/forms/multiview/view_form_response.html b/webapp/WEB-INF/templates/admin/plugins/forms/multiview/view_form_response.html index e79ea15b6..e935e1099 100644 --- a/webapp/WEB-INF/templates/admin/plugins/forms/multiview/view_form_response.html +++ b/webapp/WEB-INF/templates/admin/plugins/forms/multiview/view_form_response.html @@ -127,6 +127,7 @@

#i18n{forms.multiviewForms.view_record_history.information}

+ ${process_action_confirmation!''}