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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations