Search in sources :

Example 6 with RepositoryFileStreamProvider

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;
}
Also used : IBackgroundExecutionStreamProvider(org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider) RepositoryFileStreamProvider(org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider)

Aggregations

RepositoryFileStreamProvider (org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider)6 Serializable (java.io.Serializable)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)3 IBackgroundExecutionStreamProvider (org.pentaho.platform.api.scheduler2.IBackgroundExecutionStreamProvider)3 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)2 Job (org.pentaho.platform.api.scheduler2.Job)2 JobScheduleParam (org.pentaho.platform.web.http.api.resources.JobScheduleParam)2 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 Date (java.util.Date)1 IAction (org.pentaho.platform.api.action.IAction)1 ServiceException (org.pentaho.platform.api.engine.ServiceException)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)1 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)1 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)1 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)1