use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class GuessSchemaController method runShadowProcess.
private void runShadowProcess(final Property property, final Node inputNode, final IContext selectContext, final IElementParameter switchParam) {
DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
String dbmsId = connt.getDbmsId();
if (dbmsId == null) {
Shell shell = Display.getCurrent().getActiveShell();
MessageDialog.openError(shell, "No info about DB found !", "Please choose the correct mapping file.\n Note: This is normal when using JDBC component");
MappingFileSelectDialog dialog = new MappingFileSelectDialog(shell);
dialog.open();
dbmsId = dialog.getSelectId();
}
GuessSchemaProcess gsp = new GuessSchemaProcess(property, inputNode, selectContext, memoSQL, info, part.getProcess());
try {
List<Integer> indexsForSameNamedColumn = new ArrayList<Integer>();
CsvArray array = gsp.run();
List<String[]> schemaContent = array.getRows();
List<String> columnLabels = new ArrayList<String>();
if (columns != null) {
columns.clear();
}
if (!schemaContent.isEmpty()) {
int numbOfColumn = schemaContent.get(0).length;
for (int i = 1; i <= numbOfColumn; i++) {
indexsForSameNamedColumn.clear();
Boolean b = false;
IMetadataColumn oneColum = new MetadataColumn();
// get the column name from the temp file genenrated by GuessSchemaProcess.java
String labelName = (schemaContent.get(0))[i - 1];
if (info != null && info.isHive()) {
if (labelName != null && labelName.indexOf(TalendTextUtils.JAVA_END_STRING) != -1) {
labelName = labelName.substring(labelName.lastIndexOf(TalendTextUtils.JAVA_END_STRING) + 1, labelName.length());
}
}
String name = labelName;
String sub = "";
String sub2 = "";
if (labelName != null && labelName.length() > 0 && labelName.startsWith("_")) {
//$NON-NLS-1$
sub = labelName.substring(1);
if (sub != null && sub.length() > 0) {
sub2 = sub.substring(1);
}
}
if (KeywordsValidator.isKeyword(labelName) || KeywordsValidator.isKeyword(sub) || KeywordsValidator.isKeyword(sub2)) {
labelName = "_" + labelName;
b = true;
}
// String label = labelName;
// findSameNamedColumnAndReplaceTheIndex(indexsForSameNamedColumn, i, oneColum, labelName);
oneColum.setLabel(MetadataToolHelper.validateColumnName(labelName, i, columnLabels));
// if (b && label != null && label.length() > 0 && label.startsWith("_")) { //$NON-NLS-1$
// String substring = label.substring(1);
// if (label.startsWith("_")
// && (KeywordsValidator.isKeyword(substring) || KeywordsValidator.isKeyword(sub) ||
// KeywordsValidator
// .isKeyword(sub2))) {
// label = substring;
// }
// }
oneColum.setOriginalDbColumnName(name);
if (schemaContent.size() > 5) {
oneColum.setPrecision(Integer.parseInt(schemaContent.get(2)[i - 1]));
oneColum.setLength(Integer.parseInt(schemaContent.get(3)[i - 1]));
}
try {
String talendType = null;
// to see if the language is java or perl
if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
if (schemaContent.size() >= 5) {
talendType = MetadataTalendType.getMappingTypeRetriever(dbmsId).getDefaultSelectedTalendType(schemaContent.get(4)[i - 1]);
} else {
talendType = JavaTypesManager.STRING.getId();
}
} else {
if (schemaContent.size() >= 5) {
talendType = PerlDataTypeHelper.getNewTalendTypeOfValue(schemaContent.get(4)[i - 1]);
} else {
talendType = PerlTypesManager.STRING;
}
}
oneColum.setTalendType(talendType);
if (dbmsId != null) {
if (!TypesManager.checkDBType(dbmsId, oneColum.getTalendType(), oneColum.getType())) {
oneColum.setType(TypesManager.getDBTypeFromTalendType(dbmsId, oneColum.getTalendType()));
}
}
// oneColum.setTalendType(JavaTypesManager.STRING.getId());
} catch (Exception e) {
/*
* the table have no data at all ,to do nothing
*/
ExceptionHandler.process(e);
}
// get if a column is nullable from the temp file genenrated by GuessSchemaProcess.java
oneColum.setNullable((schemaContent.get(1))[i - 1].equals(Boolean.TRUE.toString()) ? true : false);
columns.add(oneColum);
columnLabels.add(oneColum.getLabel());
}
if (columns.size() > 0) {
IElementParameter dqRule = elem.getElementParameter("DQRULES_LIST");
if (dqRule != null) {
ITDQRuleService ruleService = null;
try {
ruleService = (ITDQRuleService) GlobalServiceRegister.getDefault().getService(ITDQRuleService.class);
} catch (RuntimeException e) {
// nothing to do
}
IElementParameter queryParam = elem.getElementParameter("QUERY");
if (ruleService != null && queryParam != null) {
ruleService.updateOriginalColumnNames(columns, queryParam);
}
}
}
IMetadataTable tempMetatable = new MetadataTable();
/* for bug 20973 */
if (tempMetatable.getTableName() == null) {
tempMetatable.setTableName(inputNode.getUniqueName());
}
IMetadataTable outputMetaCopy, originaleOutputTable;
String propertyName = "";
if (!btn.isDisposed()) {
propertyName = (String) btn.getData(PARAMETER_NAME);
}
IElementParameter param = inputNode.getElementParameter(propertyName);
for (IElementParameter eParam : elem.getElementParameters()) {
if (eParam.getContext() != null) {
param = eParam;
}
}
originaleOutputTable = inputNode.getMetadataFromConnector(param.getContext());
if (originaleOutputTable != null) {
outputMetaCopy = originaleOutputTable.clone();
}
tempMetatable.setListColumns(columns);
tempMetatable.setDbms(dbmsId);
MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), tempMetatable, inputNode, getCommandStack());
if (metaDialog != null) {
//$NON-NLS-1$
metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", inputNode.getLabel()));
}
// ok pressed
if (metaDialog.open() == MetadataDialog.OK) {
outputMetaCopy = metaDialog.getOutputMetaData();
boolean modified = false;
if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
modified = true;
}
if (modified) {
if (switchParam != null) {
switchParam.setValue(Boolean.FALSE);
}
changeMetadataCommand = new ChangeMetadataCommand(inputNode, param, originaleOutputTable, outputMetaCopy);
changeMetadataCommand.execute();
}
}
}
} catch (ProcessorException e) {
ExtractMetaDataUtils.getInstance().closeConnection();
final String strExcepton = e.getMessage();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openWarning(composite.getShell(), Messages.getString("GuessSchemaController.connectionError"), //$NON-NLS-1$
strExcepton);
}
});
ExceptionHandler.process(e);
}
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class Processor method updateContextCode.
protected void updateContextCode(ICodeGenerator codeGen) throws ProcessorException {
if (codeGen == null) {
return;
}
try {
//$NON-NLS-1$
String processContext = "false";
try {
processContext = codeGen.generateContextCode(context);
} catch (SystemException e) {
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.generationFailed"), e);
}
IFile contextFile = this.getCodeProject().getFile(contextPath);
InputStream contextStream = new ByteArrayInputStream(processContext.getBytes());
if (!contextFile.exists()) {
// see bug 0003592, detele file with different case in windows
deleteFileIfExisted(contextFile);
contextFile.create(contextStream, true, null);
} else {
contextFile.setContents(contextStream, true, false, null);
}
} catch (CoreException e1) {
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.tempFailed"), e1);
}
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class ExportProcessorHelper method export.
/**
*
* DOC ggu Comment method "export".
*
* export for execute or deploy the job on job server.
*/
public void export(IProgressMonitor monitor, ProcessItem item, ERepositoryObjectType type, String context, String archiveFile, String log4jLevel, boolean applyContextToChildren, int statisticsPort, int tracePort, Properties properties) throws ProcessorException {
if (item == null) {
throw new ProcessorException("Can't find the job");
}
if (monitor == null) {
monitor = new NullProgressMonitor();
}
// old way
// export(destDir, archiveFileName, context, log4jLevel, applyContextToChildren, statisticsPort, tracePort,
// statisticsPort > IProcessor.NO_STATISTICS, name, version, null, false, false, false);
// mostly, should same as BuildJobExecuteCommand
Map<ExportChoice, Object> exportChoiceMap = JobScriptsManagerFactory.getDefaultExportChoiceMap();
exportChoiceMap.put(ExportChoice.doNotCompileCode, false);
exportChoiceMap.put(ExportChoice.needDependencies, true);
exportChoiceMap.put(ExportChoice.addStatistics, (statisticsPort > IProcessor.NO_STATISTICS));
exportChoiceMap.put(ExportChoice.addTracs, (tracePort > IProcessor.NO_TRACES));
exportChoiceMap.put(ExportChoice.needAntScript, false);
exportChoiceMap.put(ExportChoice.needMavenScript, false);
exportChoiceMap.put(ExportChoice.applyToChildren, applyContextToChildren);
exportChoiceMap.put(ExportChoice.needContext, true);
exportChoiceMap.put(ExportChoice.binaries, true);
exportChoiceMap.put(ExportChoice.needSourceCode, false);
exportChoiceMap.put(ExportChoice.executeTests, false);
exportChoiceMap.put(ExportChoice.includeTestSource, false);
exportChoiceMap.put(ExportChoice.includeLibs, true);
exportChoiceMap.put(ExportChoice.needLog4jLevel, log4jLevel != null);
exportChoiceMap.put(ExportChoice.log4jLevel, log4jLevel);
// set like the method export(...) for buildJob
exportChoiceMap.put(ExportChoice.jobType, type);
if (context == null) {
context = item.getProcess().getDefaultContext();
}
exportChoiceMap.put(ExportChoice.contextName, context);
// add some other addition arguments in "properties"
Properties prop = new Properties();
if (properties != null) {
// add init properties.
Enumeration<Object> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement().toString();
String value = properties.getProperty(key);
prop.put(key, value);
}
}
// prop.put(TalendProcessArgumentConstant.ARG_PORT_STATS, statisticsPort);
// prop.put(TalendProcessArgumentConstant.ARG_PORT_TRACS, tracePort);
exportChoiceMap.put(ExportChoice.properties, prop);
if (monitor.isCanceled()) {
throw new ProcessorException(new InterruptedException());
}
try {
BuildJobManager.getInstance().buildJob(archiveFile, item, item.getProperty().getVersion(), context, exportChoiceMap, JobExportType.POJO, monitor);
} catch (InvocationTargetException e) {
if (e.getTargetException() != null) {
throw new ProcessorException(e.getTargetException());
} else {
throw new ProcessorException(e);
}
} catch (Exception e) {
throw new ProcessorException(e);
}
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class JavaProcessor method generateEsbFiles.
/*
* (non-Javadoc) generate ESB files on classpath for jobs with ESB components
*/
@Override
public void generateEsbFiles() throws ProcessorException {
// process.getGeneratingNodes();
List<? extends INode> graphicalNodes = process.getGraphicalNodes();
try {
IPath jobPackagePath = getSrcCodePath().removeLastSegments(1);
IFolder jobPackageFolder = this.getCodeProject().getFolder(jobPackagePath);
//$NON-NLS-1$
IFolder wsdlsPackageFolder = jobPackageFolder.getFolder("wsdl");
if (wsdlsPackageFolder.exists()) {
wsdlsPackageFolder.delete(true, null);
}
for (INode node : graphicalNodes) {
if (node.getComponent().getComponentType() == EComponentType.JOBLET) {
List<? extends INode> graphicalNodesOfJoblet = node.getProcess().getGeneratingNodes();
for (INode nodeOfJoblet : graphicalNodesOfJoblet) {
if ("tESBConsumer".equals(nodeOfJoblet.getComponent().getName()) && nodeOfJoblet.isActivate()) {
//$NON-NLS-1$
generateWSDL(wsdlsPackageFolder, nodeOfJoblet);
}
}
} else {
if ("tESBConsumer".equals(node.getComponent().getName()) && node.isActivate()) {
//$NON-NLS-1$
generateWSDL(wsdlsPackageFolder, node);
}
}
}
} catch (CoreException e) {
if (e.getStatus() != null && e.getStatus().getException() != null) {
ExceptionHandler.process(e.getStatus().getException());
}
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.tempFailed"), e);
} catch (IOException e) {
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.tempFailed"), e);
}
boolean samEnabled = false;
boolean slEnabled = false;
boolean oidcEnabled = false;
for (INode node : graphicalNodes) {
if (node.isActivate()) {
final String nodeName = node.getComponent().getName();
Object slValue = null, samValue = null;
if (//$NON-NLS-1$
"tESBConsumer".equals(nodeName) || //$NON-NLS-1$
"tRESTClient".equals(nodeName) || //$NON-NLS-1$
"tRESTRequest".equals(nodeName) || "cREST".equals(nodeName)) {
//$NON-NLS-1$
if (!slEnabled) {
//$NON-NLS-1$
slValue = node.getPropertyValue("SERVICE_LOCATOR");
}
if (!samEnabled) {
//$NON-NLS-1$
samValue = node.getPropertyValue("SERVICE_ACTIVITY_MONITOR");
}
oidcEnabled = true;
} else if ("cSOAP".equals(nodeName)) {
//$NON-NLS-1$
if (!slEnabled) {
//$NON-NLS-1$
slValue = node.getPropertyValue("ENABLE_SL");
}
if (!samEnabled) {
//$NON-NLS-1$
samValue = node.getPropertyValue("ENABLE_SAM");
}
}
if (null != slValue) {
slEnabled = (Boolean) slValue;
}
if (null != samValue) {
samEnabled = (Boolean) samValue;
}
if (samEnabled && slEnabled && oidcEnabled) {
break;
}
}
}
if (samEnabled || slEnabled || oidcEnabled) {
File esbConfigsSourceFolder = EsbConfigUtils.getEclipseEsbFolder();
if (!esbConfigsSourceFolder.exists()) {
RunProcessPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, RunProcessPlugin.getDefault().getBundle().getSymbolicName(), //$NON-NLS-1$
"ESB configuration folder does not exists - " + esbConfigsSourceFolder.toURI()));
return;
}
ITalendProcessJavaProject tProcessJvaProject = this.getTalendJavaProject();
if (tProcessJvaProject == null) {
return;
}
IFolder esbConfigsTargetFolder = tProcessJvaProject.getResourcesFolder();
// add SAM config file to classpath
if (samEnabled) {
//$NON-NLS-1$
copyEsbConfigFile(esbConfigsSourceFolder, esbConfigsTargetFolder, "agent.properties");
}
// add SL config file to classpath
if (slEnabled) {
//$NON-NLS-1$
copyEsbConfigFile(esbConfigsSourceFolder, esbConfigsTargetFolder, "locator.properties");
}
// add OIDC config file to classpath
if (oidcEnabled) {
//$NON-NLS-1$
copyEsbConfigFile(esbConfigsSourceFolder, esbConfigsTargetFolder, "oidc.properties");
}
}
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class JavaProcessor method getDefaultInterpreter.
public static String getDefaultInterpreter() throws ProcessorException {
IPreferenceStore prefStore = CorePlugin.getDefault().getPreferenceStore();
String javaInterpreter = prefStore.getString(ITalendCorePrefConstants.JAVA_INTERPRETER);
if (javaInterpreter == null || javaInterpreter.length() == 0) {
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.configureJava"));
}
Path path = new Path(javaInterpreter);
javaInterpreter = path.toPortableString();
return javaInterpreter;
}
Aggregations