LocalActionInvoker extends DefaultActionInvoker { @Override protected IBackgroundExecutionStreamProvider getStreamProvider( final Map<String, Serializable> params ) { if ( params == null ) { logger.warn( Messages.getInstance().getMapNullCantReturnSp() ); return null; } IBackgroundExecutionStreamProvider streamProvider = null; final Object objsp = params.get( ActionUtil.INVOKER_STREAMPROVIDER ); if ( objsp != null && IBackgroundExecutionStreamProvider.class.isAssignableFrom( objsp.getClass() ) ) { streamProvider = (IBackgroundExecutionStreamProvider) objsp; if ( streamProvider instanceof RepositoryFileStreamProvider ) { params.put( ActionUtil.INVOKER_STREAMPROVIDER_INPUT_FILE, ( (RepositoryFileStreamProvider) streamProvider ) .getInputFilePath() ); params.put( ActionUtil.INVOKER_STREAMPROVIDER_OUTPUT_FILE_PATTERN, ( (RepositoryFileStreamProvider) streamProvider ).getOutputFilePath() ); params.put( ActionUtil.INVOKER_STREAMPROVIDER_UNIQUE_FILE_NAME, ( (RepositoryFileStreamProvider) streamProvider ).autoCreateUniqueFilename() ); } } else { final String inputFile = params.get( ActionUtil.INVOKER_STREAMPROVIDER_INPUT_FILE ) == null ? null : params.get( ActionUtil.INVOKER_STREAMPROVIDER_INPUT_FILE ).toString(); final String outputFilePattern = params.get( ActionUtil.INVOKER_STREAMPROVIDER_OUTPUT_FILE_PATTERN ) == null ? null : params.get( ActionUtil.INVOKER_STREAMPROVIDER_OUTPUT_FILE_PATTERN ).toString(); boolean hasInputFile = !StringUtils.isEmpty( inputFile ); boolean hasOutputPattern = !StringUtils.isEmpty( outputFilePattern ); if ( hasInputFile && hasOutputPattern ) { boolean autoCreateUniqueFilename = params.get( ActionUtil.INVOKER_STREAMPROVIDER_UNIQUE_FILE_NAME ) == null || params.get( ActionUtil.INVOKER_STREAMPROVIDER_UNIQUE_FILE_NAME ).toString().equalsIgnoreCase( "true" ); streamProvider = new RepositoryFileStreamProvider( inputFile, outputFilePattern, autoCreateUniqueFilename ); params.put( ActionUtil.INVOKER_STREAMPROVIDER, streamProvider ); } else { if ( logger.isWarnEnabled() ) { logger.warn( Messages.getInstance().getMissingParamsCantReturnSp( String.format( "%s, %s", ActionUtil.INVOKER_STREAMPROVIDER_INPUT_FILE, ActionUtil.INVOKER_STREAMPROVIDER_OUTPUT_FILE_PATTERN ), params ) ); } } } return streamProvider; }  @Override IActionInvokeStatus invokeAction( final IAction actionBean,
                                           final String actionUser,
                                           final Map<String, Serializable> params );  }
@Test public void getStreamProviderNullTest() { Map<String, Serializable> paramMap = new HashMap<>(); paramMap.put( ActionUtil.INVOKER_STREAMPROVIDER, null ); IBackgroundExecutionStreamProvider iBackgroundExecutionStreamProvider = defaultActionInvoker.getStreamProvider( paramMap ); Assert.assertNull( iBackgroundExecutionStreamProvider ); }
@Test public void getStreamProviderNullWithInputFileTest() throws IOException { Map<String, Serializable> paramMap = new HashMap<>(); File inputFile = new File( "example.txt" ); BufferedWriter output = new BufferedWriter( new FileWriter( inputFile ) ); output.write( "TEST TEXT" ); paramMap.put( ActionUtil.INVOKER_STREAMPROVIDER, null ); paramMap.put( ActionUtil.INVOKER_STREAMPROVIDER_INPUT_FILE, inputFile ); IBackgroundExecutionStreamProvider iBackgroundExecutionStreamProvider = defaultActionInvoker.getStreamProvider( paramMap ); Assert.assertNull( iBackgroundExecutionStreamProvider ); }
@Test public void getStreamProviderWithInputAndOutputFileTest() throws IOException { Map<String, Serializable> paramMap = new HashMap<>(); RepositoryFileStreamProvider repositoryFileStreamProvider = new RepositoryFileStreamProvider(); File inputFile = new File( "example.txt" ); BufferedWriter output = new BufferedWriter( new FileWriter( inputFile ) ); output.write( "TEST TEXT" ); paramMap.put( ActionUtil.INVOKER_STREAMPROVIDER, repositoryFileStreamProvider ); paramMap.put( ActionUtil.INVOKER_STREAMPROVIDER_INPUT_FILE, inputFile ); paramMap.put( ActionUtil.INVOKER_STREAMPROVIDER_OUTPUT_FILE_PATTERN, inputFile ); paramMap.put( ActionUtil.INVOKER_STREAMPROVIDER_UNIQUE_FILE_NAME, true ); IBackgroundExecutionStreamProvider iBackgroundExecutionStreamProvider = defaultActionInvoker.getStreamProvider( paramMap ); Assert.assertEquals( iBackgroundExecutionStreamProvider, repositoryFileStreamProvider ); }
@Test public void getStreamProviderTest() { Map<String, Serializable> paramMap = new HashMap<>(); RepositoryFileStreamProvider repositoryFileStreamProvider = new RepositoryFileStreamProvider(); paramMap.put( ActionUtil.INVOKER_STREAMPROVIDER, repositoryFileStreamProvider ); IBackgroundExecutionStreamProvider iBackgroundExecutionStreamProvider = defaultActionInvoker.getStreamProvider( paramMap ); Assert.assertEquals( repositoryFileStreamProvider, iBackgroundExecutionStreamProvider ); }