Search in sources :

Example 26 with KettleFileException

use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.

the class RepositoryExportProgressDialog method checkIsFileIsAcceptable.

/**
 * Check if file is empty, writable, and return message dialogue box if file not empty, null otherwise.
 *
 * @param shell
 * @param log
 * @param filename
 * @return
 */
public static MessageBox checkIsFileIsAcceptable(Shell shell, LogChannelInterface log, String filename) {
    MessageBox box = null;
    // check if file is exists
    try {
        // check if file is not empty
        FileObject output = KettleVFS.getFileObject(filename);
        if (output.exists()) {
            if (!output.isWriteable()) {
                box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.OK | SWT.CANCEL);
                box.setText(BaseMessages.getString(PKG, "RepositoryExportProgressDialog.ExportFileDialog.AreadyExists"));
                box.setMessage(BaseMessages.getString(PKG, "RepositoryExportProgressDialog.ExportFileDialog.NoWritePermissions"));
                return box;
            }
            box = new MessageBox(shell, SWT.ICON_QUESTION | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.OK | SWT.CANCEL);
            box.setText(BaseMessages.getString(PKG, "RepositoryExportProgressDialog.ExportFileDialog.AreadyExists"));
            box.setMessage(BaseMessages.getString(PKG, "RepositoryExportProgressDialog.ExportFileDialog.Overwrite"));
        }
    // in case of exception - anyway we will not be able to write into this file.
    } catch (KettleFileException e) {
        log.logError("Can't access file: " + filename);
    } catch (FileSystemException e) {
        log.logError("Can't check if file exists/file permissions: " + filename);
    }
    return box;
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 27 with KettleFileException

use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.

the class PurRepository method loadTransformation.

@Override
public TransMeta loadTransformation(final String transName, final RepositoryDirectoryInterface parentDir, final ProgressMonitorListener monitor, final boolean setInternalVariables, final String versionId) throws KettleException {
    String absPath = null;
    try {
        // by the user
        if (StringUtils.isBlank(transName)) {
            throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0007_TRANSFORMATION_NAME_MISSING"));
        }
        try {
            absPath = getPath(transName, parentDir, RepositoryObjectType.TRANSFORMATION);
        } catch (Exception e) {
        // ignore and handle null value below
        }
        // variable that is not available at runtime
        if (StringUtils.isBlank(absPath)) {
            // Couldn't resolve path, throw an exception
            throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0008_TRANSFORMATION_PATH_INVALID", transName));
        }
        RepositoryFile file = pur.getFile(absPath);
        if (versionId != null) {
            // need to go back to server to get versioned info
            file = pur.getFileAtVersion(file.getId(), versionId);
        }
        // valid file
        if (file == null) {
            throw new KettleException(BaseMessages.getString(PKG, "PurRepository.ERROR_0008_TRANSFORMATION_PATH_INVALID", absPath));
        }
        NodeRepositoryFileData data = null;
        ObjectRevision revision = null;
        // Additional obfuscation through obscurity
        data = pur.getDataAtVersionForRead(file.getId(), versionId, NodeRepositoryFileData.class);
        revision = getObjectRevision(new StringObjectId(file.getId().toString()), versionId);
        TransMeta transMeta = buildTransMeta(file, parentDir, data, revision);
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationMetaLoaded.id, transMeta);
        return transMeta;
    } catch (final KettleException ke) {
        // if we have a KettleException, simply re-throw it
        throw ke;
    } catch (Exception e) {
        throw new KettleException("Unable to load transformation from path [" + absPath + "]", e);
    }
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) KettleException(org.pentaho.di.core.exception.KettleException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) TransMeta(org.pentaho.di.trans.TransMeta) EETransMeta(org.pentaho.di.repository.pur.model.EETransMeta) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Example 28 with KettleFileException

use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.

the class PurRepository method loadJob.

@Override
public JobMeta loadJob(String jobname, RepositoryDirectoryInterface parentDir, ProgressMonitorListener monitor, String versionId) throws KettleException {
    String absPath = null;
    try {
        absPath = getPath(jobname, parentDir, RepositoryObjectType.JOB);
        if (absPath == null) {
            // Couldn't resolve path, throw an exception
            throw new KettleFileException(BaseMessages.getString(PKG, "PurRepository.ERROR_0003_JOB_NOT_FOUND", jobname));
        }
        RepositoryFile file = pur.getFile(absPath);
        if (versionId != null) {
            // need to go back to server to get versioned info
            file = pur.getFileAtVersion(file.getId(), versionId);
        }
        NodeRepositoryFileData data = null;
        ObjectRevision revision = null;
        data = pur.getDataAtVersionForRead(file.getId(), versionId, NodeRepositoryFileData.class);
        revision = getObjectRevision(new StringObjectId(file.getId().toString()), versionId);
        JobMeta jobMeta = buildJobMeta(file, parentDir, data, revision);
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.JobMetaLoaded.id, jobMeta);
        return jobMeta;
    } catch (Exception e) {
        throw new KettleException("Unable to load job from path [" + absPath + "]", e);
    }
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) KettleException(org.pentaho.di.core.exception.KettleException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) EEJobMeta(org.pentaho.di.repository.pur.model.EEJobMeta) JobMeta(org.pentaho.di.job.JobMeta) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) StringObjectId(org.pentaho.di.repository.StringObjectId) MetaStoreNamespaceExistsException(org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) UnifiedRepositoryCreateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException) UnifiedRepositoryUpdateFileException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) KettleException(org.pentaho.di.core.exception.KettleException) IdNotFoundException(org.pentaho.di.core.exception.IdNotFoundException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Example 29 with KettleFileException

use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.

the class LogWriter method createFileAppender.

/**
 * Create a file appender
 * @param filename The (VFS) filename (URL) to write to.
 * @param exact is this an exact filename of a filename to be stored in "java.io.tmp"
 * @param append
 * @return A new file appender
 * @throws KettleFileException In case there is a problem opening the file.
 */
public static final Log4jFileAppender createFileAppender(String filename, boolean exact, boolean append) throws KettleFileException {
    try {
        FileObject file;
        if (!exact) {
            file = KettleVFS.createTempFile(filename, ".log", System.getProperty("java.io.tmpdir"));
        } else {
            file = KettleVFS.getFileObject(filename);
        }
        Log4jFileAppender appender = new Log4jFileAppender(file, append);
        appender.setLayout(new Log4jKettleLayout(true));
        appender.setName(LogWriter.createFileAppenderName(filename, exact));
        return appender;
    } catch (IOException e) {
        throw new KettleFileException("Unable to add Kettle file appender to Log4J", e);
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException)

Example 30 with KettleFileException

use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.

the class TestUtils method createRamFile.

public static String createRamFile(String path, VariableSpace space) {
    if (space == null) {
        space = new Variables();
        space.initializeVariablesFrom(null);
    }
    try {
        FileObject file = KettleVFS.getFileObject("ram://" + path, space);
        file.createFile();
        return file.getName().getURI();
    } catch (FileSystemException | KettleFileException e) {
        throw new RuntimeException(e);
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

KettleFileException (org.pentaho.di.core.exception.KettleFileException)61 IOException (java.io.IOException)32 FileObject (org.apache.commons.vfs2.FileObject)30 KettleException (org.pentaho.di.core.exception.KettleException)25 FileSystemException (org.apache.commons.vfs2.FileSystemException)10 DataInputStream (java.io.DataInputStream)8 File (java.io.File)7 ResultFile (org.pentaho.di.core.ResultFile)7 SocketTimeoutException (java.net.SocketTimeoutException)6 FileInputStream (java.io.FileInputStream)5 InputStream (java.io.InputStream)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 BufferedInputStream (java.io.BufferedInputStream)4 InputStreamReader (java.io.InputStreamReader)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleEOFException (org.pentaho.di.core.exception.KettleEOFException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 DataOutputStream (java.io.DataOutputStream)3 FileNotFoundException (java.io.FileNotFoundException)3