Search in sources :

Example 56 with IProcess

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());
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) IProcessor(org.talend.designer.runprocess.IProcessor) Method(java.lang.reflect.Method) Item(org.talend.core.model.properties.Item) Field(java.lang.reflect.Field) RepositoryObjectTypeBuildProvider(org.talend.core.runtime.repository.build.RepositoryObjectTypeBuildProvider) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) Test(org.junit.Test)

Example 57 with IProcess

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));
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) TextElementParameter(org.talend.core.model.runprocess.shadow.TextElementParameter) INode(org.talend.core.model.process.INode) TextElementParameter(org.talend.core.model.runprocess.shadow.TextElementParameter) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) IProcess(org.talend.core.model.process.IProcess) Test(org.junit.Test)

Example 58 with IProcess

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);
    }
}
Also used : IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) FeatureModel(org.talend.designer.publish.core.models.FeatureModel) HashSet(java.util.HashSet)

Example 59 with IProcess

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);
}
Also used : IContext(org.talend.core.model.process.IContext) Schema(org.apache.avro.Schema) List(java.util.List) IProcess(org.talend.core.model.process.IProcess) IContextManager(org.talend.core.model.process.IContextManager)

Example 60 with IProcess

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;
}
Also used : INode(org.talend.core.model.process.INode) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Shell(org.eclipse.swt.widgets.Shell) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProcess(org.talend.core.model.process.IProcess) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

IProcess (org.talend.core.model.process.IProcess)102 INode (org.talend.core.model.process.INode)33 ArrayList (java.util.ArrayList)28 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)24 IProcess2 (org.talend.core.model.process.IProcess2)22 ProcessItem (org.talend.core.model.properties.ProcessItem)21 Node (org.talend.designer.core.ui.editor.nodes.Node)20 List (java.util.List)17 Item (org.talend.core.model.properties.Item)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 IOException (java.io.IOException)15 PersistenceException (org.talend.commons.exception.PersistenceException)14 IElementParameter (org.talend.core.model.process.IElementParameter)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)13 IEditorPart (org.eclipse.ui.IEditorPart)11 ProcessorException (org.talend.designer.runprocess.ProcessorException)10 File (java.io.File)9 Element (org.talend.core.model.process.Element)9 IConnection (org.talend.core.model.process.IConnection)9 IContext (org.talend.core.model.process.IContext)9