// Grab the first x lines from the given file... // private List<String> getFirst(FixedInputMeta meta, int limit) throws IOException, KettleValueException { List<String> lines = new ArrayList<String>(); FixedInputMeta oneMeta = new FixedInputMeta(); getInfo(oneMeta); // Add a single field with the width of the line... // int lineWidth = Integer.parseInt(oneMeta.getLineWidth()); if (lineWidth <= 0) { throw new IOException("The width of a line can not be 0 or less."); } oneMeta.allocate(1); FixedFileInputField field = new FixedFileInputField(); field.setName("Field1"); field.setType(ValueMetaInterface.TYPE_STRING); field.setWidth(lineWidth); // CHECKSTYLE:Indentation:OFF oneMeta.getFieldDefinition()[0] = field; TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText()); TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog( shell, previewMeta, new String[] {wStepname.getText()}, new int[] {limit}); progressDialog.open(); Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if (!progressDialog.isCancelled()) { if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) { EnterTextDialog etd = new EnterTextDialog( shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true); etd.setReadOnly(); etd.open(); } } // The rows are in the transformation... // RowMetaInterface previewRowsMeta = progressDialog.getPreviewRowsMeta(wStepname.getText()); List<Object[]> previewRowsData = progressDialog.getPreviewRows(wStepname.getText()); for (int i = 0; i < previewRowsData.size(); i++) { String line = previewRowsMeta.getString(previewRowsData.get(i), 0); lines.add(line); } return lines; }
// Preview the data private void preview() { try { GetFilesRowsCountMeta oneMeta = new GetFilesRowsCountMeta(); getInfo(oneMeta); TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation( transMeta, oneMeta, wStepname.getText()); EnterNumberDialog numberDialog = new EnterNumberDialog( shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "GetFilesRowsCountDialog.NumberRows.DialogTitle"), BaseMessages.getString(PKG, "GetFilesRowsCountDialog.NumberRows.DialogMessage")); int previewSize = numberDialog.open(); if (previewSize > 0) { TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog( shell, previewMeta, new String[] {wStepname.getText()}, new int[] {previewSize}); progressDialog.open(); if (!progressDialog.isCancelled()) { Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) { EnterTextDialog etd = new EnterTextDialog( shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true); etd.setReadOnly(); etd.open(); } PreviewRowsDialog prd = new PreviewRowsDialog( shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText); prd.open(); } } } catch (KettleException e) { new ErrorDialog( shell, BaseMessages.getString(PKG, "GetFilesRowsCountDialog.ErrorPreviewingData.DialogTitle"), BaseMessages.getString(PKG, "GetFilesRowsCountDialog.ErrorPreviewingData.DialogMessage"), e); } }
// Preview the data private void preview() { GetTableNamesMeta oneMeta = new GetTableNamesMeta(); getInfo(oneMeta); if (oneMeta.getDatabase() == null) { MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR); mb.setMessage( BaseMessages.getString(PKG, "GetTableNamesDialog.InvalidConnection.DialogMessage")); mb.setText(BaseMessages.getString(PKG, "GetTableNamesDialog.InvalidConnection.DialogTitle")); mb.open(); return; } if (!checkUserInput(oneMeta)) return; TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText()); EnterNumberDialog numberDialog = new EnterNumberDialog( shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "GetTableNamesDialog.PreviewSize.DialogTitle"), BaseMessages.getString(PKG, "GetTableNamesDialog.PreviewSize.DialogMessage")); int previewSize = numberDialog.open(); if (previewSize > 0) { TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog( shell, previewMeta, new String[] {wStepname.getText()}, new int[] {previewSize}); progressDialog.open(); if (!progressDialog.isCancelled()) { Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) { EnterTextDialog etd = new EnterTextDialog( shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "GetTableNamesDialog.ErrorInPreview.DialogMessage"), loggingText, true); etd.setReadOnly(); etd.open(); } PreviewRowsDialog prd = new PreviewRowsDialog( shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText); prd.open(); } } }
private void preview() { PaloDimInputMeta oneMeta = new PaloDimInputMeta(); try { getInfo(oneMeta); } catch (KettleException e) { new ErrorDialog( shell, BaseMessages.getString(PKG, "PaloInputDialog.Illegal.Dialog.Settings.Title"), BaseMessages.getString(PKG, "PaloInputDialog.Illegal.Dialog.Settings.Message"), e); return; } TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation( transMeta, oneMeta, textStepName.getText()); EnterNumberDialog numberDialog = new EnterNumberDialog( shell, 500, BaseMessages.getString("System.Dialog.EnterPreviewSize.Title"), BaseMessages.getString("System.Dialog.EnterPreviewSize.Message")); int previewSize = numberDialog.open(); if (previewSize > 0) { TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog( shell, previewMeta, new String[] {textStepName.getText()}, new int[] {previewSize}); progressDialog.open(); Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if (!progressDialog.isCancelled()) { if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) { EnterTextDialog etd = new EnterTextDialog( shell, BaseMessages.getString("System.Dialog.PreviewError.Title"), BaseMessages.getString("System.Dialog.PreviewError.Message"), loggingText, true); etd.setReadOnly(); etd.open(); } } PreviewRowsDialog prd = new PreviewRowsDialog( shell, transMeta, SWT.NONE, textStepName.getText(), progressDialog.getPreviewRowsMeta(textStepName.getText()), progressDialog.getPreviewRows(textStepName.getText()), loggingText); prd.open(); } }
// Preview the data private void preview() { // execute a complete preview transformation in the background. // This is how we do it... // FixedInputMeta oneMeta = new FixedInputMeta(); getInfo(oneMeta); TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText()); EnterNumberDialog numberDialog = new EnterNumberDialog( shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "FixedInputDialog.PreviewSize.DialogTitle"), BaseMessages.getString(PKG, "FixedInputDialog.PreviewSize.DialogMessage")); int previewSize = numberDialog.open(); if (previewSize > 0) { TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog( shell, previewMeta, new String[] {wStepname.getText()}, new int[] {previewSize}); progressDialog.open(); Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if (!progressDialog.isCancelled()) { if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) { EnterTextDialog etd = new EnterTextDialog( shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true); etd.setReadOnly(); etd.open(); } } PreviewRowsDialog prd = new PreviewRowsDialog( shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText); prd.open(); } }
// Preview the data // unused // preserve for later private void preview() { // Create the XML input step SapInputMeta oneMeta = new SapInputMeta(); getInfo(oneMeta); TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText()); transMeta.getVariable("Internal.Transformation.Filename.Directory"); previewMeta.getVariable("Internal.Transformation.Filename.Directory"); EnterNumberDialog numberDialog = new EnterNumberDialog( shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "CsvInputDialog.PreviewSize.DialogTitle"), BaseMessages.getString(PKG, "CsvInputDialog.PreviewSize.DialogMessage")); int previewSize = numberDialog.open(); if (previewSize > 0) { TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog( shell, previewMeta, new String[] {wStepname.getText()}, new int[] {previewSize}); progressDialog.open(); Trans trans = progressDialog.getTrans(); String loggingText = progressDialog.getLoggingText(); if (!progressDialog.isCancelled()) { if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) { EnterTextDialog etd = new EnterTextDialog( shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true); etd.setReadOnly(); etd.open(); } } PreviewRowsDialog prd = new PreviewRowsDialog( shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText); prd.open(); } }
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) { return; } if (log.isDebug()) { logDebug(BaseMessages.getString(PKG, "TransStatusServlet.Log.TransStatusRequested")); } String transName = request.getParameter("name"); String id = request.getParameter("id"); boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml")); int startLineNr = Const.toInt(request.getParameter("from"), 0); response.setStatus(HttpServletResponse.SC_OK); if (useXML) { response.setContentType("text/xml"); response.setCharacterEncoding(Const.XML_ENCODING); } else { response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); } PrintWriter out = response.getWriter(); // ID is optional... // Trans trans; CarteObjectEntry entry; if (Const.isEmpty(id)) { // get the first transformation that matches... // entry = getTransformationMap().getFirstCarteObjectEntry(transName); if (entry == null) { trans = null; } else { id = entry.getId(); trans = getTransformationMap().getTransformation(entry); } } else { // Take the ID into account! // entry = new CarteObjectEntry(transName, id); trans = getTransformationMap().getTransformation(entry); } Encoder encoder = ESAPI.encoder(); if (trans != null) { String status = trans.getStatus(); int lastLineNr = KettleLogStore.getLastBufferLineNr(); String logText = KettleLogStore.getAppender() .getBuffer(trans.getLogChannel().getLogChannelId(), false, startLineNr, lastLineNr) .toString(); if (useXML) { response.setContentType("text/xml"); response.setCharacterEncoding(Const.XML_ENCODING); out.print(XMLHandler.getXMLHeader(Const.XML_ENCODING)); SlaveServerTransStatus transStatus = new SlaveServerTransStatus(transName, entry.getId(), status); transStatus.setFirstLoggingLineNr(startLineNr); transStatus.setLastLoggingLineNr(lastLineNr); for (int i = 0; i < trans.nrSteps(); i++) { StepInterface baseStep = trans.getRunThread(i); if ((baseStep.isRunning()) || baseStep.getStatus() != StepExecutionStatus.STATUS_EMPTY) { StepStatus stepStatus = new StepStatus(baseStep); transStatus.getStepStatusList().add(stepStatus); } } // The log can be quite large at times, we are going to put a base64 encoding around a // compressed stream // of bytes to handle this one. String loggingString = HttpUtil.encodeBase64ZippedString(logText); transStatus.setLoggingString(loggingString); // Also set the result object... // transStatus.setResult(trans.getResult()); // Is the transformation paused? // transStatus.setPaused(trans.isPaused()); // Send the result back as XML // try { out.println(transStatus.getXML()); } catch (KettleException e) { throw new ServletException("Unable to get the transformation status in XML format", e); } } else { response.setContentType("text/html;charset=UTF-8"); out.println("<HTML>"); out.println("<HEAD>"); out.println( "<TITLE>" + BaseMessages.getString(PKG, "TransStatusServlet.KettleTransStatus") + "</TITLE>"); out.println( "<META http-equiv=\"Refresh\" content=\"10;url=" + convertContextPath(CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">"); out.println("<META http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">"); out.println("</HEAD>"); out.println("<BODY>"); out.println( "<H1>" + encoder.encodeForHTML( BaseMessages.getString(PKG, "TransStatusServlet.TopTransStatus", transName)) + "</H1>"); try { out.println("<table border=\"1\">"); out.print( "<tr> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.TransName") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.CarteObjectId") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.TransStatus") + "</th> </tr>"); out.print("<tr>"); out.print("<td>" + encoder.encodeForHTML(transName) + "</td>"); out.print("<td>" + encoder.encodeForHTML(id) + "</td>"); out.print("<td>" + encoder.encodeForHTML(status) + "</td>"); out.print("</tr>"); out.print("</table>"); out.print("<p>"); // Get the transformation image // // out.print("<a href=\"" + convertContextPath(GetTransImageServlet.CONTEXT_PATH) + // "?name=" + // URLEncoder.encode(transName, "UTF-8") + "&id="+id+"\">" // + BaseMessages.getString(PKG, "TransStatusServlet.GetTransImage") + "</a>"); Point max = trans.getTransMeta().getMaximum(); max.x += 20; max.y += 20; out.print( "<iframe height=\"" + max.y + "\" width=\"" + max.x + "\" seamless src=\"" + convertContextPath(GetTransImageServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\"></iframe>"); out.print("<p>"); if ((trans.isFinished() && trans.isRunning()) || (!trans.isRunning() && !trans.isPreparing() && !trans.isInitializing())) { out.print( "<a href=\"" + convertContextPath(StartTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.StartTrans") + "</a>"); out.print("<p>"); out.print( "<a href=\"" + convertContextPath(PrepareExecutionTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.PrepareTrans") + "</a><br>"); } else if (trans.isRunning()) { out.print( "<a href=\"" + convertContextPath(PauseTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "PauseStatusServlet.PauseResumeTrans") + "</a><br>"); out.print( "<a href=\"" + convertContextPath(StopTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.StopTrans") + "</a>"); out.print("<p>"); } out.print( "<a href=\"" + convertContextPath(CleanupTransServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.CleanupTrans") + "</a>"); out.print("<p>"); out.println("<table border=\"1\">"); out.print( "<tr> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Stepname") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.CopyNr") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Read") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Written") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Input") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Output") + "</th> " + "<th>" + BaseMessages.getString(PKG, "TransStatusServlet.Updated") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Rejected") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Errors") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Active") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.Time") + "</th> " + "<th>" + BaseMessages.getString(PKG, "TransStatusServlet.Speed") + "</th> <th>" + BaseMessages.getString(PKG, "TransStatusServlet.prinout") + "</th> </tr>"); for (int i = 0; i < trans.nrSteps(); i++) { StepInterface step = trans.getRunThread(i); if ((step.isRunning()) || step.getStatus() != StepExecutionStatus.STATUS_EMPTY) { StepStatus stepStatus = new StepStatus(step); boolean snif = false; if (step.isRunning() && !step.isStopped() && !step.isPaused()) { snif = true; String sniffLink = " <a href=\"" + convertContextPath(SniffStepServlet.CONTEXT_PATH) + "?trans=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "&lines=50" + "©nr=" + step.getCopy() + "&type=" + SniffStepServlet.TYPE_OUTPUT + "&step=" + URLEncoder.encode(step.getStepname(), "UTF-8") + "\">" + encoder.encodeForHTML(stepStatus.getStepname()) + "</a>"; stepStatus.setStepname(sniffLink); } out.print(stepStatus.getHTMLTableRow(snif)); } } out.println("</table>"); out.println("<p>"); out.print( "<a href=\"" + convertContextPath(GetTransStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "&xml=y\">" + BaseMessages.getString(PKG, "TransStatusServlet.ShowAsXml") + "</a><br>"); out.print( "<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><br>"); out.print( "<p><a href=\"" + convertContextPath(GetTransStatusServlet.CONTEXT_PATH) + "?name=" + URLEncoder.encode(transName, "UTF-8") + "&id=" + URLEncoder.encode(id, "UTF-8") + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.Refresh") + "</a>"); // Put the logging below that. out.println("<p>"); out.println( "<textarea id=\"translog\" cols=\"120\" rows=\"20\" " + "wrap=\"off\" name=\"Transformation log\" readonly=\"readonly\">" + encoder.encodeForHTML(logText) + "</textarea>"); out.println("<script type=\"text/javascript\"> "); out.println(" translog.scrollTop=translog.scrollHeight; "); out.println("</script> "); out.println("<p>"); } catch (Exception ex) { out.println("<p>"); out.println("<pre>"); out.println(encoder.encodeForHTML(Const.getStackTracker(ex))); out.println("</pre>"); } out.println("<p>"); out.println("</BODY>"); out.println("</HTML>"); } } else { if (useXML) { out.println( new WebResult( WebResult.STRING_ERROR, BaseMessages.getString( PKG, "TransStatusServlet.Log.CoundNotFindSpecTrans", transName))); } else { out.println( "<H1>" + encoder.encodeForHTML( BaseMessages.getString( PKG, "TransStatusServlet.Log.CoundNotFindTrans", transName)) + "</H1>"); out.println( "<a href=\"" + convertContextPath(GetStatusServlet.CONTEXT_PATH) + "\">" + BaseMessages.getString(PKG, "TransStatusServlet.BackToStatusPage") + "</a><p>"); } } }