Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUT-28182 : add a confirmation as a notification when a manual workfl… #368

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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<Integer> actionHistoryResourceIdList = StringUtil.convertStringToIntList( actionHistoryResourceId, FormsConstants.SEPARATOR_UNDERSCORE );

model.put( MARK_PROCESS_ACTION_CONFIRMATION, WorkflowService.getInstance( ).getDisplayProcessActionConfirmation( nIdAction, getLocale( ), actionHistoryResourceIdList ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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";
Expand All @@ -154,6 +152,7 @@ public class MultiviewFormResponseDetailsJspBean extends AbstractJspBean
private Map<String, String> _mapFilterValues = new LinkedHashMap<>( );
private final transient IFormsMultiviewAuthorizationService _formsMultiviewAuthorizationService = SpringContextService
.getBean( FormsMultiviewAuthorizationService.BEAN_NAME );
private List<Integer> _actionHistoryResourceIdList;

/**
* Return the page with the details of a form response
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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<ResourceHistory> 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
{
Expand Down Expand Up @@ -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<ResourceHistory> 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 )
{
Expand Down Expand Up @@ -607,7 +621,7 @@ private String manageRedirection( HttpServletRequest request )
*/
private String redirectToResponseList( HttpServletRequest request )
{
return redirect( request, buildRedirecUrlWithFilterValues( ) );
return redirect( request, buildRedirectUrl( request ) );
}

/**
Expand Down Expand Up @@ -636,29 +650,37 @@ private String defaultRedirection( HttpServletRequest request )

if ( nIdFormResponse != NumberUtils.INTEGER_MINUS_ONE )
{

Map<String, String> 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 );
}
else
{
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 ) )
{
Expand All @@ -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( );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h2 class="text-muted text-center">#i18n{forms.multiviewForms.noFormResponses}</
</@card>
</@div>
</#if>
${process_action_confirmation!''}
</@boxBody>
</@box>
</@columns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ <h2>#i18n{forms.multiviewForms.view_record_history.information}</h2>
</@boxBody>
</@box>
</@columns>
${process_action_confirmation!''}
</@row>
</@boxBody>
</@box>
Expand Down