use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.
the class TestComponentsAction method generateCode.
public void generateCode(File[] tempFile, String componentPath) {
for (File file : tempFile) {
if (file.length() > 0) {
URI uri = URI.createFileURI(file.toString());
TalendFilePackage.eINSTANCE.getNsURI();
Resource resource = new ResourceSetImpl().getResource(uri, true);
ProcessType processType = (ProcessType) EcoreUtil.getObjectByType(resource.getContents(), TalendFilePackage.eINSTANCE.getProcessType());
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
ProcessItem item = PropertiesFactory.eINSTANCE.createProcessItem();
item.setProcess(processType);
item.setProperty(PropertiesFactory.eINSTANCE.createProperty());
item.getProperty().setLabel(TestParameter.TEST_DIR);
item.getProperty().setAuthor(PropertiesFactory.eINSTANCE.createUser());
item.getProperty().setId(file.getName());
item.getProperty().setStatusCode(file.getName());
item.getProperty().setVersion(TestParameter.VERSION);
IProcess process = service.getProcessFromProcessItem(item);
setDefaultProperties(process, componentPath);
IProcessor processor = ProcessorUtilities.getProcessor(process, item.getProperty(), process.getContextManager().getDefaultContext());
try {
// generate
//$NON-NLS-1$
log.info(TestParameter.GENERATE_START + " : " + file.getName());
// processor.generateCode(process.getContextManager().getDefaultContext(), false, false, true);
processor.generateCode(false, false, true);
//$NON-NLS-1$
log.info(TestParameter.GENERATE_END + " : " + file.getName());
// run
//$NON-NLS-1$
log.info(TestParameter.RUN_START + " : " + file.getName());
java.lang.Process runningProcess = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
StringBuffer errBuff = new StringBuffer();
if (isRunOK(runningProcess, errBuff)) {
//$NON-NLS-1$
log.info(TestParameter.RUN_SUCCESS + " : " + file.getName());
} else {
// 2 possibilities : OK not found / error stream
//$NON-NLS-1$
log.error(TestParameter.RUN_FAIL + " : " + file.getName(), new Exception(errBuff.toString()));
}
} catch (ProcessorException e) {
log.error(e.getMessage(), e);
}
}
}
}
use of org.talend.core.model.process.IProcess in project tesb-studio-se by Talend.
the class CheckESBProviderNodes method checkNode.
@Override
public void checkNode(Node node) {
String name = node.getComponent().getName();
if (!ESBPROVIDER_COMPONENT.equals(name)) {
return;
}
IProcess process = node.getProcess();
if (process.getNodesOfType(ESBPROVIDER_COMPONENT).size() > 1) {
Problems.add(ProblemStatus.ERROR, (Element) node, "Only one " + ESBPROVIDER_COMPONENT + " component is allowed in a Job!");
} else if (process.getNodesOfType(RESTREQUEST_COMPONENT).size() > 0) {
Problems.add(ProblemStatus.ERROR, (Element) node, ESBPROVIDER_COMPONENT + " and " + RESTREQUEST_COMPONENT + " can't present in a same Job!");
}
}
use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.
the class XmlMapInputZoneToolBar method changProperty.
/*
* (non-Javadoc)
*
* @see org.talend.designer.newabstractmap.figures.treetools.zone.InputZoneTooBar#changProperty()
*/
@Override
public void changProperty() {
boolean dieOnError = mapperManger.isDieOnError();
PropertySetDialog propertySet = new PropertySetDialog(null, dieOnError);
if (propertySet.open() == Window.OK) {
if (graphicViewer != null && propertySet.isValueChanged()) {
final boolean newValue = !dieOnError;
CommandStack commandStack = graphicViewer.getEditDomain().getCommandStack();
commandStack.execute(new Command() {
@Override
public void execute() {
mapperManger.setDieOnError(newValue);
if (newValue) {
if (!externalData.getOutputTrees().isEmpty()) {
OutputXmlTree outputTree = externalData.getOutputTrees().get(0);
if (outputTree.isErrorReject()) {
// mapperComponent.getMetadataList().add(metadataTable);
externalData.getOutputTrees().remove(0);
mapperComponent.getProcess().removeUniqueConnectionName(outputTree.getName());
removeMetadataTableByName(outputTree.getName());
if (!externalData.getOutputTrees().isEmpty()) {
int indexOf = externalPart.getModelChildren().indexOf(externalData.getOutputTrees().get(0));
if (indexOf != -1) {
graphicViewer.select((EditPart) externalPart.getChildren().get(indexOf));
}
}
}
}
} else {
boolean hasRejectTable = false;
if (!externalData.getOutputTrees().isEmpty()) {
OutputXmlTree outputTree = externalData.getOutputTrees().get(0);
if (outputTree.isErrorReject()) {
hasRejectTable = true;
}
}
if (!hasRejectTable) {
String baseName = MapperManager.ERROR_REJECT;
IProcess process = mapperComponent.getProcess();
String tableName = baseName;
if (!process.checkValidConnectionName(baseName) && process instanceof IProcess2) {
final String uniqueName = ((IProcess2) process).generateUniqueConnectionName("row", baseName);
tableName = uniqueName;
((IProcess2) process).addUniqueConnectionName(uniqueName);
} else if (process instanceof IProcess2) {
tableName = baseName;
((IProcess2) process).addUniqueConnectionName(baseName);
}
OutputXmlTree outputXmlTree = XmlmapFactory.eINSTANCE.createOutputXmlTree();
outputXmlTree.setErrorReject(true);
outputXmlTree.setName(tableName);
externalData.getOutputTrees().add(0, outputXmlTree);
MetadataTable metadataTable = new MetadataTable();
metadataTable.setLabel(tableName);
metadataTable.setTableName(tableName);
MetadataColumn errorMessageCol = new MetadataColumn();
errorMessageCol.setLabel(MapperManager.ERROR_REJECT_MESSAGE);
errorMessageCol.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
errorMessageCol.setNullable(true);
errorMessageCol.setOriginalDbColumnName(MapperManager.ERROR_REJECT_MESSAGE);
errorMessageCol.setReadOnly(true);
errorMessageCol.setCustom(true);
metadataTable.getListColumns().add(errorMessageCol);
MetadataColumn errorStackTrace = new MetadataColumn();
errorStackTrace.setLabel(MapperManager.ERROR_REJECT_STACK_TRACE);
errorStackTrace.setTalendType(DesignerPlugin.getDefault().getPreferenceStore().getString(MetadataTypeLengthConstants.FIELD_DEFAULT_TYPE));
errorStackTrace.setNullable(true);
errorStackTrace.setOriginalDbColumnName(MapperManager.ERROR_REJECT_STACK_TRACE);
errorStackTrace.setReadOnly(true);
errorStackTrace.setCustom(true);
metadataTable.getListColumns().add(errorStackTrace);
mapperComponent.getMetadataList().add(metadataTable);
OutputTreeNode errorMessageNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
errorMessageNode.setName(MapperManager.ERROR_REJECT_MESSAGE);
errorMessageNode.setType(errorMessageCol.getTalendType());
errorMessageNode.setNullable(true);
outputXmlTree.getNodes().add(errorMessageNode);
OutputTreeNode errorStackTraceNode = XmlmapFactory.eINSTANCE.createOutputTreeNode();
errorStackTraceNode.setName(MapperManager.ERROR_REJECT_STACK_TRACE);
errorStackTraceNode.setType(errorStackTrace.getTalendType());
errorStackTraceNode.setNullable(true);
outputXmlTree.getNodes().add(errorStackTraceNode);
int indexOf = externalPart.getModelChildren().indexOf(outputXmlTree);
if (indexOf != -1) {
graphicViewer.select((EditPart) externalPart.getChildren().get(indexOf));
}
}
}
}
});
}
}
}
use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.
the class StandardJobOSGiBundleBuildProviderTest method test_createPomCreator.
@Test
public void test_createPomCreator() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
Item jobItem = createJobItem();
final IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
Assert.assertNotNull(designerCoreService);
final IProcess processFromItem = designerCoreService.getProcessFromItem(jobItem);
IProcessor processor = ProcessorUtilities.getProcessor(processFromItem, jobItem.getProperty());
final Class<? extends IProcessor> processorClazz = processor.getClass();
Assert.assertEquals("org.talend.designer.runprocess.maven.MavenJavaProcessor", processorClazz.getName());
processor.setContext(processor.getProcess().getContextManager().getDefaultContext());
parameters.put(IBuildPomCreatorParameters.PROCESSOR, processor);
final Method getPomFileMethod = processorClazz.getDeclaredMethod("getPomFile");
getPomFileMethod.setAccessible(true);
final Object getPomFile = getPomFileMethod.invoke(processor);
Assert.assertTrue(getPomFile instanceof IFile);
IFile pomFile = (IFile) getPomFile;
parameters.put(IBuildPomCreatorParameters.FILE_POM, pomFile);
parameters.put(IBuildParametes.ITEM, processor.getProperty().getItem());
final Map<String, Object> arguments = processor.getArguments();
parameters.put(IBuildPomCreatorParameters.ARGUMENTS_MAP, arguments);
parameters.put(IBuildPomCreatorParameters.OVERWRITE_POM, true);
// create pom and assembly
RepositoryObjectTypeBuildProvider provider = createTestBuildProvider();
final IMavenPomCreator pomCreator = provider.createPomCreator(parameters);
Assert.assertNotNull("Create the pom creator failure", pomCreator);
Assert.assertEquals(CreateMavenStandardJobOSGiPom.class, pomCreator.getClass());
pomCreator.create(null);
pomFile.getParent().refreshLocal(IResource.DEPTH_ONE, null);
Assert.assertTrue("the pom file " + pomFile.getName() + " is not created ", pomFile.exists());
}
use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.
the class QueryTypeController method getGuessQueryCommand.
/**
* DOC nrousseau Comment method "getGuessQueryCommand".
*
* @return
*/
private QueryGuessCommand getGuessQueryCommand() {
// Map<String, IMetadataTable> repositoryTableMap = null;
IMetadataTable newRepositoryMetadata = null;
String realTableName = null;
String realTableId = null;
String schemaName = "";
// Only for getting the real table name.
if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (repositorySchemaTypeParameter != null) {
final Object value = repositorySchemaTypeParameter.getValue();
if (elem instanceof Node) {
/* value can be devided means the value like "connectionid - label" */
String[] keySplitValues = value.toString().split(" - ");
if (keySplitValues.length > 1) {
String connectionId = value.toString().split(" - ")[0];
String tableLabel = value.toString().split(" - ")[1];
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
Connection connection = ((ConnectionItem) item).getConnection();
for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
// bug 20365
if (table.getLabel().equals(tableLabel)) {
IMetadataTable repositoryMetadata = ConvertionHelper.convert(table);
realTableName = repositoryMetadata.getTableName();
realTableId = repositoryMetadata.getId();
// }
break;
}
}
}
}
// if (repositoryTableMap.containsKey(value)) {
// IMetadataTable repositoryMetadata = repositoryTableMap.get(value);
// realTableName = repositoryMetadata.getTableName();
// realTableId = repositoryMetadata.getId();
// }
}
}
// }
// }
}
// Ends
Connection repositoryConnection = null;
boolean useExisting = false;
IElementParameter elementParameter = elem.getElementParameter(EParameterName.USE_EXISTING_CONNECTION.name());
if (elem instanceof Node) {
IProcess process = ((Node) elem).getProcess();
if (elementParameter != null && Boolean.valueOf(String.valueOf(elementParameter.getValue()))) {
String connName = (String) elem.getPropertyValue("CONNECTION");
for (INode node : process.getGraphicalNodes()) {
if (node.getElementName().equals(connName)) {
useExisting = true;
final Object propertyValue = node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (propertyValue != null) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertyValue.toString());
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
} else {
initConnectionParameters();
repositoryConnection = TracesConnectionUtils.createConnection(connParameters);
}
}
break;
}
}
}
}
if (!useExisting && elem.getPropertyValue(EParameterName.PROPERTY_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
final Object propertyValue = elem.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
if (propertyValue != null) {
IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
Item item = null;
try {
IRepositoryViewObject repobj = factory.getLastVersion(propertyValue.toString());
if (repobj != null) {
Property property = repobj.getProperty();
if (property != null) {
item = property.getItem();
}
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
if (item != null && item instanceof ConnectionItem) {
repositoryConnection = ((ConnectionItem) item).getConnection();
}
}
} else {
initConnectionParameters();
repositoryConnection = TracesConnectionUtils.createConnection(connParameters);
}
QueryGuessCommand cmd = null;
INode node = null;
if (elem instanceof INode) {
node = (INode) elem;
} else {
// else instanceof Connection
node = ((IConnection) elem).getSource();
}
List<IMetadataTable> metadataList = node.getMetadataList();
newRepositoryMetadata = metadataList.get(0);
// for tInformixRow
if (newRepositoryMetadata.getListColumns().size() == 0 && metadataList.size() > 1) {
newRepositoryMetadata = metadataList.get(1);
}
if (newRepositoryMetadata == null) {
String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
if (schemaSelected != null) {
// repositoryMetadata = repositoryTableMap.get(schemaSelected);
} else if (newRepositoryMetadata == null) {
MessageDialog.openWarning(new Shell(), Messages.getString("QueryTypeController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("QueryTypeController.nothingToGuess"));
return cmd;
}
}
cmd = new QueryGuessCommand(node, newRepositoryMetadata, repositoryConnection);
cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
//$NON-NLS-1$
String type = getValueFromRepositoryName("TYPE");
if ("Oracle".equalsIgnoreCase(type)) {
type = EDatabaseTypeName.ORACLEFORSID.getDisplayName();
}
cmd.setParameters(realTableId, realTableName, type);
return cmd;
}
Aggregations