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-28048: Fixed SONAR Exceptions' handling for 'ProgressManager' elements #437

Open
wants to merge 1 commit 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
Expand Up @@ -40,7 +40,7 @@

import fr.paris.lutece.portal.business.progressmanager.ProgressFeed;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -275,7 +275,7 @@ public List<String> getReport( String strFeedToken, int iFromLine )
}
}

return null;
return Collections.emptyList( );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
package fr.paris.lutece.portal.web.progressmanager;

import fr.paris.lutece.portal.service.progressmanager.ProgressManagerService;
import fr.paris.lutece.portal.service.util.AppLogService;
import fr.paris.lutece.util.json.ErrorJsonResponse;
import fr.paris.lutece.util.json.JsonResponse;
import fr.paris.lutece.util.json.JsonUtil;
Expand Down Expand Up @@ -99,64 +100,69 @@ public void init( ServletConfig config ) throws ServletException
public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
{
response.setContentType( CONTENT_TYPE );
PrintWriter out = response.getWriter( );
PrintWriter out = null;

// token
String strToken = (String) request.getParameter( PARAMETER_TOKEN );

if ( strToken == null || strToken.isEmpty( ) )
try
{
out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) );
out.flush( );
out.close( );
return;
}
out = response.getWriter( );

ProgressManagerService progressManagerService = ProgressManagerService.getInstance( );
// token
String strToken = request.getParameter( PARAMETER_TOKEN );

if ( !progressManagerService.isRegistred( strToken ) )
{
out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) );
out.flush( );
out.close( );
return;
}
if ( strToken == null || strToken.isEmpty( ) )
{
out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) );
return;
}

if ( request.getParameter( PARAMETER_PROGRESS ) != null )
{
out.println( JsonUtil.buildJsonResponse( new JsonResponse( progressManagerService.getProgressStatus( strToken ) ) ) );
out.flush( );
out.close( );
return;
}
else
if ( request.getParameter( PARAMETER_REPORT ) != null )
ProgressManagerService progressManagerService = ProgressManagerService.getInstance( );

if ( !progressManagerService.isRegistred( strToken ) )
{
out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) );
return;
}

if ( request.getParameter( PARAMETER_PROGRESS ) != null )
{
int iFromLine = -1;
try
out.println( JsonUtil.buildJsonResponse( new JsonResponse( progressManagerService.getProgressStatus( strToken ) ) ) );
}
else
if ( request.getParameter( PARAMETER_REPORT ) != null )
{
iFromLine = Integer.parseInt( request.getParameter( PARAMETER_FROM_LINE ) );
int iFromLine = -1;
try
{
iFromLine = Integer.parseInt( request.getParameter( PARAMETER_FROM_LINE ) );
}
catch( NumberFormatException e )
{
out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_BAD_PARAMETER ) ) );
}

Map<String, Object> mapResponse = new HashMap<>( );
List<String> reportLines = progressManagerService.getReport( strToken, iFromLine );
mapResponse.put( ATTRIBUTE_NAME_LAST_LINE, iFromLine + reportLines.size( ) );
mapResponse.put( ATTRIBUTE_NAME_LINES, reportLines );
out.println( JsonUtil.buildJsonResponse( new JsonResponse( mapResponse ) ) );
}
catch( NumberFormatException e )
else
{
out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_BAD_PARAMETER ) ) );
out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) );
}

Map<String, Object> mapResponse = new HashMap<>( );
List<String> reportLines = progressManagerService.getReport( strToken, iFromLine );
mapResponse.put( ATTRIBUTE_NAME_LAST_LINE, iFromLine + reportLines.size( ) );
mapResponse.put( ATTRIBUTE_NAME_LINES, reportLines );
out.println( JsonUtil.buildJsonResponse( new JsonResponse( mapResponse ) ) );
}
catch( IOException e )
{
AppLogService.error( e.getStackTrace( ), e );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a specific context message

}
finally
{
// In every case, make sure the PrintWriter is properly sent/cleaned
if ( out != null )
{
out.flush( );
out.close( );
return;
}
else
{
out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) );
}

out.flush( );
out.close( );
}
}
}