use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.
the class StandardJobStandaloneBuildProviderTest 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);
final Method getAssemblyFileMethod = processorClazz.getDeclaredMethod("getAssemblyFile");
getAssemblyFileMethod.setAccessible(true);
final Object getAssemblyFile = getAssemblyFileMethod.invoke(processor);
Assert.assertTrue(getPomFile instanceof IFile);
IFile assemblyFile = (IFile) getAssemblyFile;
parameters.put(IBuildPomCreatorParameters.FILE_ASSEMBLY, assemblyFile);
// before set classpath, must do initJobClasspath
final Method initJobClasspathMethod = processorClazz.getDeclaredMethod("initJobClasspath");
initJobClasspathMethod.setAccessible(true);
initJobClasspathMethod.invoke(processor);
final Field windowsClasspathField = processorClazz.getDeclaredField("windowsClasspath");
windowsClasspathField.setAccessible(true);
parameters.put(IBuildPomCreatorParameters.CP_WIN, windowsClasspathField.get(processor));
final Field unixClasspathField = processorClazz.getDeclaredField("unixClasspath");
unixClasspathField.setAccessible(true);
parameters.put(IBuildPomCreatorParameters.CP_LINUX, unixClasspathField.get(processor));
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(CreateMavenJobPom.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());
assemblyFile.getParent().refreshLocal(IResource.DEPTH_ONE, null);
Assert.assertTrue("the assembly file " + assemblyFile.getName() + " is not created ", assemblyFile.exists());
}
use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.
the class ExpressionTest method testEvaluateDistrib_link.
@Test
public void testEvaluateDistrib_link() {
List<IElementParameter> params = new ArrayList<>();
ElementParameter param1 = createMockParameter("PARA1", true, null);
params.add(param1);
ElementParameter paramNode = mock(ElementParameter.class);
INode testElement = mock(INode.class);
when(paramNode.getName()).thenReturn("PARANODE");
TextElementParameter testParam = mock(TextElementParameter.class);
when(paramNode.getElement()).thenReturn(testElement);
when(paramNode.getElement().getElementName()).thenReturn("testComponent");
when(testElement.getElementParametersWithChildrens()).thenReturn((List) Arrays.asList(testParam));
when(testParam.getVariableName()).thenReturn("__CONNECTION__");
when(testParam.getValue()).thenReturn("relatedNode");
INode relatedNode = mock(INode.class);
when(relatedNode.getUniqueName()).thenReturn("relatedNode");
when(relatedNode.getElementParameters()).thenReturn((List) params);
IProcess process = mock(IProcess.class);
when(process.getGeneratingNodes()).thenReturn((List) Arrays.asList(relatedNode));
when(testElement.getProcess()).thenReturn(process);
params.add(paramNode);
ElementParameter distrib = createMockParameter("DISTRIBUTION", "CUSTOM");
params.add(distrib);
ElementParameter version = createMockParameter("HIVE_VERSION", "testVersion");
params.add(version);
ElementParameter invaliddistrib = createMockParameter("INVALDDISTRIB", "INVALID");
params.add(invaliddistrib);
assertTrue(Expression.evaluateDistrib("DISTRIB[#LINK@NODE.CONNECTION.DISTRIBUTION, #LINK@NODE.CONNECTION.HIVE_VERSION].doSupportUseDatanodeHostname[]", params, paramNode));
assertFalse(Expression.evaluateDistrib("!DISTRIB[#LINK@NODE.CONNECTION.DISTRIBUTION, #LINK@NODE.CONNECTION.HIVE_VERSION].doSupportUseDatanodeHostname[]", params, paramNode));
}
use of org.talend.core.model.process.IProcess in project tesb-studio-se by Talend.
the class CamelFeatureUtil method addFeatureAndBundles.
/**
* Add feature and bundle to Feature Model
*
* @param node
* @param featuresModel
*/
public static void addFeatureAndBundles(ProcessItem routeProcess, FeaturesModel featuresModel) {
IDesignerCoreService designerService = RepositoryPlugin.getDefault().getDesignerCoreService();
IProcess process = designerService.getProcessFromProcessItem(routeProcess, false);
Collection<FeatureModel> features = new HashSet<FeatureModel>();
for (String lib : process.getNeededLibraries(true)) {
Collection<FeatureModel> featureModel = computeFeature(getNameWithoutVersion(lib));
if (featureModel != null) {
features.addAll(featureModel);
}
}
addNodesSpecialFeatures(features, routeProcess.getProcess());
addConnectionsSpecialFeatures(features, routeProcess.getProcess());
for (FeatureModel model : features) {
featuresModel.addFeature(model);
}
}
use of org.talend.core.model.process.IProcess in project tdi-studio-se by Talend.
the class ComponentContextPropertyValueEvaluator method evaluate.
@Override
public Object evaluate(Property property, Object storedValue) {
if (storedValue == null) {
return storedValue;
}
if (storedValue instanceof Schema || storedValue instanceof List || storedValue instanceof Enum || storedValue instanceof Boolean) {
return storedValue;
}
IContext context = null;
if (node != null) {
IProcess process = node.getProcess();
if (process != null) {
IContextManager cm = process.getContextManager();
if (cm != null) {
context = cm.getDefaultContext();
}
}
}
String stringStoredValue = String.valueOf(storedValue);
if (context != null && ContextParameterUtils.isContainContextParam(stringStoredValue)) {
stringStoredValue = ContextParameterUtils.parseScriptContextCode(stringStoredValue, context);
}
return getTypedValue(property, stringStoredValue);
}
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