use of org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider in project pentaho-platform by pentaho.
the class LocalActionInvoker method getStreamProvider.
/**
* Gets the stream provider from the {@code INVOKER_STREAMPROVIDER} key within the {@code params} {@link Map} or
* builds it from the input file and output dir {@link Map} values. Returns {@code null} if information needed to
* build the stream provider is not present in the {@code map}, which is perfectly ok for some
* {@link org.pentaho.platform.api.action.IAction} types.
*
* @param params the {@link Map} or parameters needed to invoke the {@link org.pentaho.platform.api.action.IAction}
* @return a {@link IBackgroundExecutionStreamProvider} represented in the {@code params} {@link Map}
*/
@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);
// put in the map for future lookup
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), // $NON-NLS-1$
params));
}
}
}
return streamProvider;
}
Aggregations