Search in sources :

Example 1 with InvalidFileTypeException

use of org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileTypeException in project pentaho-kettle by pentaho.

the class RepositoryFileProvider method writeFile.

@Override
public RepositoryFile writeFile(InputStream inputStream, RepositoryFile destDir, String path, boolean overwrite) throws FileException {
    RepositoryObjectType type = getType(path);
    String name = Util.getName(path).replace(" ", "_");
    RepositoryElementInterface repositoryElementInterface = null;
    if (type != null) {
        if (type.equals(RepositoryObjectType.TRANSFORMATION)) {
            try {
                repositoryElementInterface = new TransMeta(inputStream, null, false, null, null);
            } catch (KettleException e) {
                return null;
            }
        } else if (type.equals(RepositoryObjectType.JOB)) {
            try {
                repositoryElementInterface = new JobMeta(inputStream, null, null);
            } catch (KettleException e) {
                return null;
            }
        } else {
            throw new InvalidFileTypeException();
        }
    }
    try {
        RepositoryDirectoryInterface directoryInterface = getRepository().findDirectory(destDir.getPath());
        if (repositoryElementInterface != null) {
            repositoryElementInterface.setRepositoryDirectory(directoryInterface);
            getRepository().save(repositoryElementInterface, null, null);
            return null;
        }
        return null;
    } catch (KettleException e) {
        return null;
    }
}
Also used : RepositoryElementInterface(org.pentaho.di.repository.RepositoryElementInterface) KettleException(org.pentaho.di.core.exception.KettleException) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) InvalidFileTypeException(org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileTypeException) TransMeta(org.pentaho.di.trans.TransMeta) RepositoryObjectType(org.pentaho.di.repository.RepositoryObjectType)

Aggregations

KettleException (org.pentaho.di.core.exception.KettleException)1 JobMeta (org.pentaho.di.job.JobMeta)1 InvalidFileTypeException (org.pentaho.di.plugins.fileopensave.api.providers.exception.InvalidFileTypeException)1 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)1 RepositoryElementInterface (org.pentaho.di.repository.RepositoryElementInterface)1 RepositoryObjectType (org.pentaho.di.repository.RepositoryObjectType)1 TransMeta (org.pentaho.di.trans.TransMeta)1