use of org.apache.commons.vfs2.UserAuthenticationData.Type in project spoofax by metaborg.
the class ResourceAgent method isDirectory.
@Override
public boolean isDirectory(String fn) {
try {
final FileObject resource = resourceService.resolve(workingDir, fn);
final FileType type = resource.getType();
return type == FileType.FOLDER || type == FileType.FILE_OR_FOLDER;
} catch (FileSystemException e) {
throw new RuntimeException("Could not check if file " + fn + " is a directory", e);
}
}
use of org.apache.commons.vfs2.UserAuthenticationData.Type in project pentaho-kettle by pentaho.
the class Trans method prepareExecution.
/**
* Prepares the transformation for execution. This includes setting the arguments and parameters as well as preparing
* and tracking the steps and hops in the transformation.
*
* @param arguments the arguments to use for this transformation
* @throws KettleException in case the transformation could not be prepared (initialized)
*/
public void prepareExecution(String[] arguments) throws KettleException {
setPreparing(true);
startDate = null;
setRunning(false);
log.snap(Metrics.METRIC_TRANSFORMATION_EXECUTION_START);
log.snap(Metrics.METRIC_TRANSFORMATION_INIT_START);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.TransformationPrepareExecution.id, this);
checkCompatibility();
//
if (arguments != null) {
setArguments(arguments);
}
if (parentTrans != null) {
IMetaFileCache.setCacheInstance(transMeta, IMetaFileCache.initialize(parentTrans, log));
} else {
// If there is no parent, one of these still needs to be called to instantiate a new cache
IMetaFileCache.setCacheInstance(transMeta, IMetaFileCache.initialize(parentJob, log));
}
activateParameters();
transMeta.activateParameters();
ConnectionUtil.init(transMeta);
if (transMeta.getName() == null) {
if (transMeta.getFilename() != null) {
log.logBasic(BaseMessages.getString(PKG, "Trans.Log.DispacthingStartedForFilename", transMeta.getFilename()));
}
} else {
log.logBasic(BaseMessages.getString(PKG, "Trans.Log.DispacthingStartedForTransformation", transMeta.getName()));
}
if (getArguments() != null) {
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.NumberOfArgumentsDetected", String.valueOf(getArguments().length)));
}
}
if (isSafeModeEnabled()) {
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.SafeModeIsEnabled", transMeta.getName()));
}
}
if (getReplayDate() != null) {
SimpleDateFormat df = new SimpleDateFormat(REPLAY_DATE_FORMAT);
log.logBasic(BaseMessages.getString(PKG, "Trans.Log.ThisIsAReplayTransformation") + df.format(getReplayDate()));
} else {
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.ThisIsNotAReplayTransformation"));
}
}
//
if (servletPrintWriter == null) {
String encoding = System.getProperty("KETTLE_DEFAULT_SERVLET_ENCODING", null);
if (encoding == null) {
servletPrintWriter = new PrintWriter(new OutputStreamWriter(System.out));
} else {
try {
servletPrintWriter = new PrintWriter(new OutputStreamWriter(System.out, encoding));
} catch (UnsupportedEncodingException ex) {
servletPrintWriter = new PrintWriter(new OutputStreamWriter(System.out));
}
}
}
// Keep track of all the row sets and allocated steps
//
steps = new ArrayList<>();
rowsets = new ArrayList<>();
List<StepMeta> hopsteps = transMeta.getTransHopSteps(false);
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.FoundDefferentSteps", String.valueOf(hopsteps.size())));
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.AllocatingRowsets"));
}
//
for (int i = 0; i < hopsteps.size(); i++) {
StepMeta thisStep = hopsteps.get(i);
if (thisStep.isMapping()) {
// handled and allocated by the mapping step itself.
continue;
}
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.AllocateingRowsetsForStep", String.valueOf(i), thisStep.getName()));
}
List<StepMeta> nextSteps = transMeta.findNextSteps(thisStep);
int nrTargets = nextSteps.size();
for (int n = 0; n < nrTargets; n++) {
// What's the next step?
StepMeta nextStep = nextSteps.get(n);
if (nextStep.isMapping()) {
// handled and allocated by the mapping step itself.
continue;
}
// How many times do we start the source step?
int thisCopies = thisStep.getCopies();
if (thisCopies < 0) {
//
throw new KettleException(BaseMessages.getString(PKG, "Trans.Log.StepCopiesNotCorrectlyDefined", thisStep.getName()));
}
// How many times do we start the target step?
int nextCopies = nextStep.getCopies();
// Are we re-partitioning?
boolean repartitioning;
if (thisStep.isPartitioned()) {
repartitioning = !thisStep.getStepPartitioningMeta().equals(nextStep.getStepPartitioningMeta());
} else {
repartitioning = nextStep.isPartitioned();
}
int nrCopies;
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.copiesInfo", String.valueOf(thisCopies), String.valueOf(nextCopies)));
}
int dispatchType;
if (thisCopies == 1 && nextCopies == 1) {
dispatchType = TYPE_DISP_1_1;
nrCopies = 1;
} else if (thisCopies == 1 && nextCopies > 1) {
dispatchType = TYPE_DISP_1_N;
nrCopies = nextCopies;
} else if (thisCopies > 1 && nextCopies == 1) {
dispatchType = TYPE_DISP_N_1;
nrCopies = thisCopies;
} else if (thisCopies == nextCopies && !repartitioning) {
dispatchType = TYPE_DISP_N_N;
nrCopies = nextCopies;
} else {
// > 1!
dispatchType = TYPE_DISP_N_M;
nrCopies = nextCopies;
}
//
if (dispatchType != TYPE_DISP_N_M) {
for (int c = 0; c < nrCopies; c++) {
RowSet rowSet;
switch(transMeta.getTransformationType()) {
case Normal:
// This is a temporary patch until the batching rowset has proven
// to be working in all situations.
// Currently there are stalling problems when dealing with small
// amounts of rows.
//
Boolean batchingRowSet = ValueMetaString.convertStringToBoolean(System.getProperty(Const.KETTLE_BATCHING_ROWSET));
if (batchingRowSet != null && batchingRowSet.booleanValue()) {
rowSet = new BlockingBatchingRowSet(transMeta.getSizeRowset());
} else {
rowSet = new BlockingRowSet(transMeta.getSizeRowset());
}
break;
case SerialSingleThreaded:
rowSet = new SingleRowRowSet();
break;
case SingleThreaded:
rowSet = new QueueRowSet();
break;
default:
throw new KettleException("Unhandled transformation type: " + transMeta.getTransformationType());
}
switch(dispatchType) {
case TYPE_DISP_1_1:
rowSet.setThreadNameFromToCopy(thisStep.getName(), 0, nextStep.getName(), 0);
break;
case TYPE_DISP_1_N:
rowSet.setThreadNameFromToCopy(thisStep.getName(), 0, nextStep.getName(), c);
break;
case TYPE_DISP_N_1:
rowSet.setThreadNameFromToCopy(thisStep.getName(), c, nextStep.getName(), 0);
break;
case TYPE_DISP_N_N:
rowSet.setThreadNameFromToCopy(thisStep.getName(), c, nextStep.getName(), c);
break;
default:
break;
}
rowsets.add(rowSet);
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.TransformationAllocatedNewRowset", rowSet.toString()));
}
}
} else {
// distribution...
for (int s = 0; s < thisCopies; s++) {
for (int t = 0; t < nextCopies; t++) {
BlockingRowSet rowSet = new BlockingRowSet(transMeta.getSizeRowset());
rowSet.setThreadNameFromToCopy(thisStep.getName(), s, nextStep.getName(), t);
rowsets.add(rowSet);
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.TransformationAllocatedNewRowset", rowSet.toString()));
}
}
}
}
}
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.AllocatedRowsets", String.valueOf(rowsets.size()), String.valueOf(i), thisStep.getName()) + " ");
}
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.AllocatingStepsAndStepData"));
}
//
for (int i = 0; i < hopsteps.size(); i++) {
StepMeta stepMeta = hopsteps.get(i);
String stepid = stepMeta.getStepID();
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.TransformationIsToAllocateStep", stepMeta.getName(), stepid));
}
// How many copies are launched of this step?
int nrCopies = stepMeta.getCopies();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "Trans.Log.StepHasNumberRowCopies", String.valueOf(nrCopies)));
}
// At least run once...
for (int c = 0; c < nrCopies; c++) {
// Make sure we haven't started it yet!
if (!hasStepStarted(stepMeta.getName(), c)) {
StepMetaDataCombi combi = new StepMetaDataCombi();
combi.stepname = stepMeta.getName();
combi.copy = c;
// The meta-data
combi.stepMeta = stepMeta;
combi.meta = stepMeta.getStepMetaInterface();
// Allocate the step data
StepDataInterface data = combi.meta.getStepData();
combi.data = data;
// Allocate the step
StepInterface step = combi.meta.getStep(stepMeta, data, c, transMeta, this);
// Copy the variables of the transformation to the step...
// don't share. Each copy of the step has its own variables.
//
step.initializeVariablesFrom(this);
step.setUsingThreadPriorityManagment(transMeta.isUsingThreadPriorityManagment());
// Pass the connected repository & metaStore to the steps runtime
//
step.setRepository(repository);
step.setMetaStore(metaStore);
// things as well...
if (stepMeta.isPartitioned()) {
List<String> partitionIDs = stepMeta.getStepPartitioningMeta().getPartitionSchema().getPartitionIDs();
if (partitionIDs != null && !partitionIDs.isEmpty()) {
// Pass the partition ID
step.setPartitionID(partitionIDs.get(c));
// to the step
}
}
// Save the step too
combi.step = step;
// /
if (combi.step instanceof LoggingObjectInterface) {
LogChannelInterface logChannel = combi.step.getLogChannel();
logChannel.setLogLevel(logLevel);
logChannel.setGatheringMetrics(log.isGatheringMetrics());
}
// Add to the bunch...
steps.add(combi);
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.TransformationHasAllocatedANewStep", stepMeta.getName(), String.valueOf(c)));
}
}
}
}
//
for (int s = 0; s < steps.size(); s++) {
StepMetaDataCombi combi = steps.get(s);
if (combi.stepMeta.isDoingErrorHandling()) {
combi.step.identifyErrorOutput();
}
}
// Now (optionally) write start log record!
// Make sure we synchronize appropriately to avoid duplicate batch IDs.
//
Object syncObject = this;
if (parentJob != null) {
// parallel execution in a job
syncObject = parentJob;
}
if (parentTrans != null) {
// multiple sub-transformations
syncObject = parentTrans;
}
synchronized (syncObject) {
calculateBatchIdAndDateRange();
beginProcessing();
}
//
for (int i = 0; i < steps.size(); i++) {
StepMetaDataCombi sid = steps.get(i);
StepMeta stepMeta = sid.stepMeta;
StepInterface baseStep = sid.step;
baseStep.setPartitioned(stepMeta.isPartitioned());
// Now let's take a look at the source and target relation
//
// If this source step is not partitioned, and the target step is: it
// means we need to re-partition the incoming data.
// If both steps are partitioned on the same method and schema, we don't
// need to re-partition
// If both steps are partitioned on a different method or schema, we need
// to re-partition as well.
// If both steps are not partitioned, we don't need to re-partition
//
boolean isThisPartitioned = stepMeta.isPartitioned();
PartitionSchema thisPartitionSchema = null;
if (isThisPartitioned) {
thisPartitionSchema = stepMeta.getStepPartitioningMeta().getPartitionSchema();
}
boolean isNextPartitioned = false;
StepPartitioningMeta nextStepPartitioningMeta = null;
PartitionSchema nextPartitionSchema = null;
List<StepMeta> nextSteps = transMeta.findNextSteps(stepMeta);
int nrNext = nextSteps.size();
for (int p = 0; p < nrNext; p++) {
StepMeta nextStep = nextSteps.get(p);
if (nextStep.isPartitioned()) {
isNextPartitioned = true;
nextStepPartitioningMeta = nextStep.getStepPartitioningMeta();
nextPartitionSchema = nextStepPartitioningMeta.getPartitionSchema();
}
}
baseStep.setRepartitioning(StepPartitioningMeta.PARTITIONING_METHOD_NONE);
//
if ((!isThisPartitioned && isNextPartitioned) || (isThisPartitioned && isNextPartitioned && !thisPartitionSchema.equals(nextPartitionSchema))) {
baseStep.setRepartitioning(nextStepPartitioningMeta.getMethodType());
}
// For partitioning to a set of remove steps (repartitioning from a master
// to a set or remote output steps)
//
StepPartitioningMeta targetStepPartitioningMeta = baseStep.getStepMeta().getTargetStepPartitioningMeta();
if (targetStepPartitioningMeta != null) {
baseStep.setRepartitioning(targetStepPartitioningMeta.getMethodType());
}
}
setPreparing(false);
setInitializing(true);
//
if (isMonitored() && steps.size() < 150) {
doTopologySortOfSteps();
}
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.InitialisingSteps", String.valueOf(steps.size())));
}
StepInitThread[] initThreads = new StepInitThread[steps.size()];
Thread[] threads = new Thread[steps.size()];
//
for (int i = 0; i < steps.size(); i++) {
final StepMetaDataCombi sid = steps.get(i);
// Do the init code in the background!
// Init all steps at once, but ALL steps need to finish before we can
// continue properly!
//
initThreads[i] = new StepInitThread(sid, log);
// Put it in a separate thread!
//
threads[i] = new Thread(initThreads[i]);
threads[i].setName("init of " + sid.stepname + "." + sid.copy + " (" + threads[i].getName() + ")");
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.StepBeforeInitialize.id, initThreads[i]);
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
try {
threads[i].join();
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.StepAfterInitialize.id, initThreads[i]);
} catch (Exception ex) {
log.logError("Error with init thread: " + ex.getMessage(), ex.getMessage());
log.logError(Const.getStackTracker(ex));
}
}
setInitializing(false);
boolean ok = true;
//
for (int i = 0; i < initThreads.length; i++) {
StepMetaDataCombi combi = initThreads[i].getCombi();
if (!initThreads[i].isOk()) {
log.logError(BaseMessages.getString(PKG, "Trans.Log.StepFailedToInit", combi.stepname + "." + combi.copy));
combi.data.setStatus(StepExecutionStatus.STATUS_STOPPED);
ok = false;
} else {
combi.data.setStatus(StepExecutionStatus.STATUS_IDLE);
if (log.isDetailed()) {
log.logDetailed(BaseMessages.getString(PKG, "Trans.Log.StepInitialized", combi.stepname + "." + combi.copy));
}
}
}
if (!ok) {
// One or more steps failed on initialization.
// Transformation is now stopped.
setStopped(true);
//
for (int i = 0; i < initThreads.length; i++) {
StepMetaDataCombi combi = initThreads[i].getCombi();
// Dispose will overwrite the status, but we set it back right after
// this.
combi.step.dispose(combi.meta, combi.data);
if (initThreads[i].isOk()) {
combi.data.setStatus(StepExecutionStatus.STATUS_HALTED);
} else {
combi.data.setStatus(StepExecutionStatus.STATUS_STOPPED);
}
}
// Just for safety, fire the trans finished listeners...
try {
fireTransFinishedListeners();
} catch (KettleException e) {
// listeners produces errors
log.logError(BaseMessages.getString(PKG, "Trans.FinishListeners.Exception"));
// we will not pass this exception up to prepareExecution() entry point.
} finally {
// Flag the transformation as finished even if exception was thrown
setFinished(true);
}
//
if (preview) {
String logText = KettleLogStore.getAppender().getBuffer(getLogChannelId(), true).toString();
throw new KettleException(BaseMessages.getString(PKG, "Trans.Log.FailToInitializeAtLeastOneStep") + Const.CR + logText);
} else {
throw new KettleException(BaseMessages.getString(PKG, "Trans.Log.FailToInitializeAtLeastOneStep") + Const.CR);
}
}
log.snap(Metrics.METRIC_TRANSFORMATION_INIT_STOP);
KettleEnvironment.setExecutionInformation(this, repository);
setReadyToStart(true);
}
use of org.apache.commons.vfs2.UserAuthenticationData.Type in project pentaho-kettle by pentaho.
the class JobEntryMail method execute.
public Result execute(Result result, int nr) {
File masterZipfile = null;
// Send an e-mail...
// create some properties and get the default Session
Properties props = new Properties();
if (Utils.isEmpty(server)) {
logError(BaseMessages.getString(PKG, "JobMail.Error.HostNotSpecified"));
result.setNrErrors(1L);
result.setResult(false);
return result;
}
String protocol = "smtp";
if (usingSecureAuthentication) {
if (secureConnectionType.equals("TLS")) {
// Allow TLS authentication
props.put("mail.smtp.starttls.enable", "true");
} else {
protocol = "smtps";
// required to get rid of a SSL exception :
// nested exception is:
// javax.net.ssl.SSLException: Unsupported record version Unknown
props.put("mail.smtps.quitwait", "false");
}
}
props.put("mail." + protocol + ".host", environmentSubstitute(server));
if (!Utils.isEmpty(port)) {
props.put("mail." + protocol + ".port", environmentSubstitute(port));
}
if (log.isDebug()) {
props.put("mail.debug", "true");
}
if (usingAuthentication) {
props.put("mail." + protocol + ".auth", "true");
/*
* authenticator = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new
* PasswordAuthentication( StringUtil.environmentSubstitute(Const.NVL(authenticationUser, "")),
* StringUtil.environmentSubstitute(Const.NVL(authenticationPassword, "")) ); } };
*/
}
Session session = Session.getInstance(props);
session.setDebug(log.isDebug());
try {
// create a message
Message msg = new MimeMessage(session);
// set message priority
if (usePriority) {
String priority_int = "1";
if (priority.equals("low")) {
priority_int = "3";
}
if (priority.equals("normal")) {
priority_int = "2";
}
// (String)int between 1= high and 3 = low.
msg.setHeader("X-Priority", priority_int);
msg.setHeader("Importance", importance);
// seems to be needed for MS Outlook.
// where it returns a string of high /normal /low.
msg.setHeader("Sensitivity", sensitivity);
// Possible values are normal, personal, private, company-confidential
}
// Set Mail sender (From)
String sender_address = environmentSubstitute(replyAddress);
if (!Utils.isEmpty(sender_address)) {
String sender_name = environmentSubstitute(replyName);
if (!Utils.isEmpty(sender_name)) {
sender_address = sender_name + '<' + sender_address + '>';
}
msg.setFrom(new InternetAddress(sender_address));
} else {
throw new MessagingException(BaseMessages.getString(PKG, "JobMail.Error.ReplyEmailNotFilled"));
}
// set Reply to addresses
String reply_to_address = environmentSubstitute(replyToAddresses);
if (!Utils.isEmpty(reply_to_address)) {
// Split the mail-address: space separated
String[] reply_Address_List = environmentSubstitute(reply_to_address).split(" ");
InternetAddress[] address = new InternetAddress[reply_Address_List.length];
for (int i = 0; i < reply_Address_List.length; i++) {
address[i] = new InternetAddress(reply_Address_List[i]);
}
msg.setReplyTo(address);
}
// Split the mail-address: space separated
String[] destinations = environmentSubstitute(destination).split(" ");
InternetAddress[] address = new InternetAddress[destinations.length];
for (int i = 0; i < destinations.length; i++) {
address[i] = new InternetAddress(destinations[i]);
}
msg.setRecipients(Message.RecipientType.TO, address);
String realCC = environmentSubstitute(getDestinationCc());
if (!Utils.isEmpty(realCC)) {
// Split the mail-address Cc: space separated
String[] destinationsCc = realCC.split(" ");
InternetAddress[] addressCc = new InternetAddress[destinationsCc.length];
for (int i = 0; i < destinationsCc.length; i++) {
addressCc[i] = new InternetAddress(destinationsCc[i]);
}
msg.setRecipients(Message.RecipientType.CC, addressCc);
}
String realBCc = environmentSubstitute(getDestinationBCc());
if (!Utils.isEmpty(realBCc)) {
// Split the mail-address BCc: space separated
String[] destinationsBCc = realBCc.split(" ");
InternetAddress[] addressBCc = new InternetAddress[destinationsBCc.length];
for (int i = 0; i < destinationsBCc.length; i++) {
addressBCc[i] = new InternetAddress(destinationsBCc[i]);
}
msg.setRecipients(Message.RecipientType.BCC, addressBCc);
}
String realSubject = environmentSubstitute(subject);
if (!Utils.isEmpty(realSubject)) {
msg.setSubject(realSubject);
}
msg.setSentDate(new Date());
StringBuilder messageText = new StringBuilder();
String endRow = isUseHTML() ? "<br>" : Const.CR;
String realComment = environmentSubstitute(comment);
if (!Utils.isEmpty(realComment)) {
messageText.append(realComment).append(Const.CR).append(Const.CR);
}
if (!onlySendComment) {
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Job")).append(endRow);
messageText.append("-----").append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.JobName") + " : ").append(parentJob.getJobMeta().getName()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.JobDirectory") + " : ").append(parentJob.getJobMeta().getRepositoryDirectory()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.JobEntry") + " : ").append(getName()).append(endRow);
messageText.append(Const.CR);
}
if (includeDate) {
messageText.append(endRow).append(BaseMessages.getString(PKG, "JobMail.Log.Comment.MsgDate") + ": ").append(XMLHandler.date2string(new Date())).append(endRow).append(endRow);
}
if (!onlySendComment && result != null) {
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.PreviousResult") + ":").append(endRow);
messageText.append("-----------------").append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.JobEntryNr") + " : ").append(result.getEntryNr()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Errors") + " : ").append(result.getNrErrors()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesRead") + " : ").append(result.getNrLinesRead()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesWritten") + " : ").append(result.getNrLinesWritten()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesInput") + " : ").append(result.getNrLinesInput()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesOutput") + " : ").append(result.getNrLinesOutput()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesUpdated") + " : ").append(result.getNrLinesUpdated()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.LinesRejected") + " : ").append(result.getNrLinesRejected()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Status") + " : ").append(result.getExitStatus()).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Result") + " : ").append(result.getResult()).append(endRow);
messageText.append(endRow);
}
if (!onlySendComment && (!Utils.isEmpty(environmentSubstitute(contactPerson)) || !Utils.isEmpty(environmentSubstitute(contactPhone)))) {
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.ContactInfo") + " :").append(endRow);
messageText.append("---------------------").append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.PersonToContact") + " : ").append(environmentSubstitute(contactPerson)).append(endRow);
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.Tel") + " : ").append(environmentSubstitute(contactPhone)).append(endRow);
messageText.append(endRow);
}
// Include the path to this job entry...
if (!onlySendComment) {
JobTracker jobTracker = parentJob.getJobTracker();
if (jobTracker != null) {
messageText.append(BaseMessages.getString(PKG, "JobMail.Log.Comment.PathToJobentry") + ":").append(endRow);
messageText.append("------------------------").append(endRow);
addBacktracking(jobTracker, messageText);
if (isUseHTML()) {
messageText.replace(0, messageText.length(), messageText.toString().replace(Const.CR, endRow));
}
}
}
MimeMultipart parts = new MimeMultipart();
// put the text in the
MimeBodyPart part1 = new MimeBodyPart();
// Attached files counter
int nrattachedFiles = 0;
if (useHTML) {
if (!Utils.isEmpty(getEncoding())) {
part1.setContent(messageText.toString(), "text/html; " + "charset=" + getEncoding());
} else {
part1.setContent(messageText.toString(), "text/html; " + "charset=ISO-8859-1");
}
} else {
part1.setText(messageText.toString());
}
parts.addBodyPart(part1);
if (includingFiles && result != null) {
List<ResultFile> resultFiles = result.getResultFilesList();
if (resultFiles != null && !resultFiles.isEmpty()) {
if (!zipFiles) {
//
for (ResultFile resultFile : resultFiles) {
FileObject file = resultFile.getFile();
if (file != null && file.exists()) {
boolean found = false;
for (int i = 0; i < fileType.length; i++) {
if (fileType[i] == resultFile.getType()) {
found = true;
}
}
if (found) {
// create a data source
MimeBodyPart files = new MimeBodyPart();
URLDataSource fds = new URLDataSource(file.getURL());
// get a data Handler to manipulate this file type;
files.setDataHandler(new DataHandler(fds));
// include the file in the data source
files.setFileName(file.getName().getBaseName());
// insist on base64 to preserve line endings
files.addHeader("Content-Transfer-Encoding", "base64");
// add the part with the file in the BodyPart();
parts.addBodyPart(files);
nrattachedFiles++;
logBasic("Added file '" + fds.getName() + "' to the mail message.");
}
}
}
} else {
// create a single ZIP archive of all files
masterZipfile = new File(System.getProperty("java.io.tmpdir") + Const.FILE_SEPARATOR + environmentSubstitute(zipFilename));
ZipOutputStream zipOutputStream = null;
try {
zipOutputStream = new ZipOutputStream(new FileOutputStream(masterZipfile));
for (ResultFile resultFile : resultFiles) {
boolean found = false;
for (int i = 0; i < fileType.length; i++) {
if (fileType[i] == resultFile.getType()) {
found = true;
}
}
if (found) {
FileObject file = resultFile.getFile();
ZipEntry zipEntry = new ZipEntry(file.getName().getBaseName());
zipOutputStream.putNextEntry(zipEntry);
// Now put the content of this file into this archive...
BufferedInputStream inputStream = new BufferedInputStream(KettleVFS.getInputStream(file));
try {
int c;
while ((c = inputStream.read()) >= 0) {
zipOutputStream.write(c);
}
} finally {
inputStream.close();
}
zipOutputStream.closeEntry();
nrattachedFiles++;
logBasic("Added file '" + file.getName().getURI() + "' to the mail message in a zip archive.");
}
}
} catch (Exception e) {
logError("Error zipping attachement files into file [" + masterZipfile.getPath() + "] : " + e.toString());
logError(Const.getStackTracker(e));
result.setNrErrors(1);
} finally {
if (zipOutputStream != null) {
try {
zipOutputStream.finish();
zipOutputStream.close();
} catch (IOException e) {
logError("Unable to close attachement zip file archive : " + e.toString());
logError(Const.getStackTracker(e));
result.setNrErrors(1);
}
}
}
// Now attach the master zip file to the message.
if (result.getNrErrors() == 0) {
// create a data source
MimeBodyPart files = new MimeBodyPart();
FileDataSource fds = new FileDataSource(masterZipfile);
// get a data Handler to manipulate this file type;
files.setDataHandler(new DataHandler(fds));
// include the file in the data source
files.setFileName(fds.getName());
// add the part with the file in the BodyPart();
parts.addBodyPart(files);
}
}
}
}
int nrEmbeddedImages = 0;
if (embeddedimages != null && embeddedimages.length > 0) {
FileObject imageFile = null;
for (int i = 0; i < embeddedimages.length; i++) {
String realImageFile = environmentSubstitute(embeddedimages[i]);
String realcontenID = environmentSubstitute(contentids[i]);
if (messageText.indexOf("cid:" + realcontenID) < 0) {
if (log.isDebug()) {
log.logDebug("Image [" + realImageFile + "] is not used in message body!");
}
} else {
try {
boolean found = false;
imageFile = KettleVFS.getFileObject(realImageFile, this);
if (imageFile.exists() && imageFile.getType() == FileType.FILE) {
found = true;
} else {
log.logError("We can not find [" + realImageFile + "] or it is not a file");
}
if (found) {
// Create part for the image
MimeBodyPart messageBodyPart = new MimeBodyPart();
// Load the image
URLDataSource fds = new URLDataSource(imageFile.getURL());
messageBodyPart.setDataHandler(new DataHandler(fds));
// Setting the header
messageBodyPart.setHeader("Content-ID", "<" + realcontenID + ">");
// Add part to multi-part
parts.addBodyPart(messageBodyPart);
nrEmbeddedImages++;
log.logBasic("Image '" + fds.getName() + "' was embedded in message.");
}
} catch (Exception e) {
log.logError("Error embedding image [" + realImageFile + "] in message : " + e.toString());
log.logError(Const.getStackTracker(e));
result.setNrErrors(1);
} finally {
if (imageFile != null) {
try {
imageFile.close();
} catch (Exception e) {
/* Ignore */
}
}
}
}
}
}
if (nrEmbeddedImages > 0 && nrattachedFiles == 0) {
// If we need to embedd images...
// We need to create a "multipart/related" message.
// otherwise image will appear as attached file
parts.setSubType("related");
}
// put all parts together
msg.setContent(parts);
Transport transport = null;
try {
transport = session.getTransport(protocol);
String authPass = getPassword(authenticationPassword);
if (usingAuthentication) {
if (!Utils.isEmpty(port)) {
transport.connect(environmentSubstitute(Const.NVL(server, "")), Integer.parseInt(environmentSubstitute(Const.NVL(port, ""))), environmentSubstitute(Const.NVL(authenticationUser, "")), authPass);
} else {
transport.connect(environmentSubstitute(Const.NVL(server, "")), environmentSubstitute(Const.NVL(authenticationUser, "")), authPass);
}
} else {
transport.connect();
}
transport.sendMessage(msg, msg.getAllRecipients());
} finally {
if (transport != null) {
transport.close();
}
}
} catch (IOException e) {
logError("Problem while sending message: " + e.toString());
result.setNrErrors(1);
} catch (MessagingException mex) {
logError("Problem while sending message: " + mex.toString());
result.setNrErrors(1);
Exception ex = mex;
do {
if (ex instanceof SendFailedException) {
SendFailedException sfex = (SendFailedException) ex;
Address[] invalid = sfex.getInvalidAddresses();
if (invalid != null) {
logError(" ** Invalid Addresses");
for (int i = 0; i < invalid.length; i++) {
logError(" " + invalid[i]);
result.setNrErrors(1);
}
}
Address[] validUnsent = sfex.getValidUnsentAddresses();
if (validUnsent != null) {
logError(" ** ValidUnsent Addresses");
for (int i = 0; i < validUnsent.length; i++) {
logError(" " + validUnsent[i]);
result.setNrErrors(1);
}
}
Address[] validSent = sfex.getValidSentAddresses();
if (validSent != null) {
// System.out.println(" ** ValidSent Addresses");
for (int i = 0; i < validSent.length; i++) {
logError(" " + validSent[i]);
result.setNrErrors(1);
}
}
}
if (ex instanceof MessagingException) {
ex = ((MessagingException) ex).getNextException();
} else {
ex = null;
}
} while (ex != null);
} finally {
if (masterZipfile != null && masterZipfile.exists()) {
masterZipfile.delete();
}
}
if (result.getNrErrors() > 0) {
result.setResult(false);
} else {
result.setResult(true);
}
return result;
}
use of org.apache.commons.vfs2.UserAuthenticationData.Type in project pentaho-kettle by pentaho.
the class FixedInput method processRow.
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
meta = (FixedInputMeta) smi;
data = (FixedInputData) sdi;
if (first) {
first = false;
data.outputRowMeta = new RowMeta();
meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
// The conversion logic for when the lazy conversion is turned of is simple:
// Pretend it's a lazy conversion object anyway and get the native type during conversion.
//
data.convertRowMeta = data.outputRowMeta.clone();
for (ValueMetaInterface valueMeta : data.convertRowMeta.getValueMetaList()) {
valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
}
if (meta.isHeaderPresent()) {
// skip this row.
readOneRow(false);
}
}
Object[] outputRowData = readOneRow(true);
if (outputRowData == null) {
// no more input to be expected...
setOutputDone();
return false;
}
// copy row to possible alternate rowset(s).
putRow(data.outputRowMeta, outputRowData);
if (checkFeedback(getLinesInput())) {
logBasic(BaseMessages.getString(PKG, "FixedInput.Log.LineNumber", Long.toString(getLinesInput())));
}
return true;
}
use of org.apache.commons.vfs2.UserAuthenticationData.Type in project pentaho-kettle by pentaho.
the class FixedInput method readOneRow.
/**
* Read a single row of data from the file...
*
* @param doConversions
* if you want to do conversions, set to false for the header row.
* @return a row of data...
* @throws KettleException
*/
private Object[] readOneRow(boolean doConversions) throws KettleException {
try {
//
if (meta.isRunningInParallel()) {
if (getLinesInput() >= data.rowsToRead) {
// We're done. The rest is for the other steps in the cluster
return null;
}
}
Object[] outputRowData = RowDataUtil.allocateRowData(data.convertRowMeta.size());
int outputIndex = 0;
if (data.stopReading) {
return null;
}
FixedFileInputField[] fieldDefinitions = meta.getFieldDefinition();
for (int i = 0; i < fieldDefinitions.length; i++) {
int fieldWidth = fieldDefinitions[i].getWidth();
data.endBuffer = data.startBuffer + fieldWidth;
if (data.endBuffer > data.bufferSize) {
// Oops, we need to read more data...
// Better resize this before we read other things in it...
//
data.resizeByteBuffer();
// Also read another chunk of data, now that we have the space for it...
// Ignore EOF, there might be other stuff in the buffer.
//
data.readBufferFromFile();
}
//
if (data.endBuffer > data.bufferSize) {
// a row because we're done.
if ((0 == i) && data.bufferSize <= 0) {
return null;
}
// This is the last record of data in the file.
data.stopReading = true;
// Just take what's left for the current field.
fieldWidth = data.bufferSize;
}
byte[] field = new byte[fieldWidth];
System.arraycopy(data.byteBuffer, data.startBuffer, field, 0, fieldWidth);
if (doConversions) {
if (meta.isLazyConversionActive()) {
outputRowData[outputIndex++] = field;
} else {
// We're not lazy so we convert the data right here and now.
// The convert object uses binary storage as such we just have to ask the native type from it.
// That will do the actual conversion.
//
ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(outputIndex);
outputRowData[outputIndex++] = sourceValueMeta.convertBinaryStringToNativeType(field);
}
} else {
// nothing for the header, no conversions here.
outputRowData[outputIndex++] = null;
}
// OK, onto the next field...
//
data.startBuffer = data.endBuffer;
}
//
if (meta.isLineFeedPresent()) {
data.endBuffer += 2;
if (data.endBuffer >= data.bufferSize) {
// Oops, we need to read more data...
// Better resize this before we read other things in it...
//
data.resizeByteBuffer();
// Also read another chunk of data, now that we have the space for it...
data.readBufferFromFile();
}
//
if (data.byteBuffer[data.startBuffer] == '\n' || data.byteBuffer[data.startBuffer] == '\r') {
data.startBuffer++;
if (data.byteBuffer[data.startBuffer] == '\n' || data.byteBuffer[data.startBuffer] == '\r') {
data.startBuffer++;
}
}
data.endBuffer = data.startBuffer;
}
incrementLinesInput();
return outputRowData;
} catch (Exception e) {
throw new KettleFileException("Exception reading line using NIO: " + e.toString(), e);
}
}
Aggregations