Search in sources :

Example 51 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class UpdateDbtypeOfCreateTableTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractJobMigrationTask#executeOnProcess(org.talend.core.model.properties.ProcessItem)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage().equals(ECodeLanguage.JAVA) && processType != null) {
        final Map<String, String> dbtypes = new HashMap<String, String>();
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("Access", "ACCESS");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("AS400", "AS400");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("DB2", "DB2");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("FireBird", "FIREBIRD");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("Hsql", "HSQLDB");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("Informix", "INFORMIX");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("Ingres", "INGRES");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("Interbase", "INTERBASE");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("JavaDb", "JAVADB");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("MSSQLServer", "MSSQL");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("Oracle", "DBORACLE");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("Postgre", "POSTGRE");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("SQLite", "SQLITE");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("Sybase", "SYBASE");
        //$NON-NLS-1$ //$NON-NLS-2$
        dbtypes.put("ODBC", "ODBC");
        //$NON-NLS-1$
        final String name = "tCreateTable";
        //$NON-NLS-1$
        final String property = "DBTYPE";
        IComponentFilter filert = new IComponentFilter() {

            public boolean accept(NodeType node) {
                boolean toReturn = (name == null ? true : acceptS(node));
                if (toReturn) {
                    String pValue = ComponentUtilities.getNodePropertyValue(node, property);
                    toReturn = !dbtypes.values().contains(pValue);
                }
                return toReturn;
            }

            public boolean acceptS(NodeType node) {
                return node.getComponentName().equals(name);
            }
        };
        IComponentConversion conversion = new IComponentConversion() {

            public void transform(NodeType node) {
                String pValue = ComponentUtilities.getNodePropertyValue(node, property);
                String value = dbtypes.get(pValue);
                if (value != null) {
                    ComponentUtilities.setNodeValue(node, property, value);
                } else {
                    //$NON-NLS-1$
                    ComponentUtilities.setNodeValue(node, property, "MYSQL");
                }
            }
        };
        List<IComponentConversion> cons = new ArrayList<IComponentConversion>();
        cons.add(conversion);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filert, cons);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (Exception e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    } else {
        // do nothing
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) HashMap(java.util.HashMap) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ArrayList(java.util.ArrayList) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 52 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class UnifyParameterOfDatastaxAndHectorForCassandra method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    final ProcessType processType = getProcessType(item);
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
    String[] compNames = { "tCassandraInput", "tCassandraOutput", "tCassandraRow", "tCassandraLookupInput" };
    IComponentConversion conversion = new IComponentConversion() {

        @Override
        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            //$NON-NLS-1$
            ElementParameterType cf = ComponentUtilities.getNodeProperty(node, "TABLE");
            if (cf != null) {
                if (ComponentUtilities.getNodeProperty(node, "COLUMN_FAMILY") == null) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$
                    ComponentUtilities.addNodeProperty(node, "COLUMN_FAMILY", "TEXT");
                }
                //$NON-NLS-1$ 
                ComponentUtilities.getNodeProperty(node, "COLUMN_FAMILY").setValue(cf.getValue());
            }
            //$NON-NLS-1$
            ElementParameterType actionForCF = ComponentUtilities.getNodeProperty(node, "TABLE_ACTION");
            if (actionForCF != null) {
                if (ComponentUtilities.getNodeProperty(node, "ACTION_ON_COLUMN_FAMILY") == null) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$ //$NON-NLS-2$
                    ComponentUtilities.addNodeProperty(node, "ACTION_ON_COLUMN_FAMILY", "TEXT");
                }
                //$NON-NLS-1$ 
                ComponentUtilities.getNodeProperty(node, "ACTION_ON_COLUMN_FAMILY").setValue(actionForCF.getValue());
            }
        }
    };
    for (String name : compNames) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(conversion));
        } catch (PersistenceException e) {
            // TODO Auto-generated catch block
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 53 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class UpdateCheckResult method getCategory.

@Override
@SuppressWarnings("unchecked")
public String getCategory() {
    String category = null;
    if (getUpdateType() instanceof EUpdateItemType) {
        switch((EUpdateItemType) getUpdateType()) {
            case NODE_PROPERTY:
            case NODE_SCHEMA:
            case NODE_QUERY:
            case NODE_VALIDATION_RULE:
            case JOBLET_SCHEMA:
                if (getUpdateObject() != null) {
                    if (getUpdateObject() instanceof Node) {
                        Node node = (Node) getUpdateObject();
                        if (node.getUniqueName().equals(node.getLabel())) {
                            category = node.getUniqueName();
                        } else {
                            category = node.getLabel() + UpdateManagerUtils.addBrackets(node.getUniqueName());
                        }
                    }
                    if (getUpdateObject() instanceof NodeType) {
                        NodeType node = (NodeType) getUpdateObject();
                        String uniqueName = null;
                        for (ElementParameterType param : (List<ElementParameterType>) node.getElementParameter()) {
                            if (EParameterName.UNIQUE_NAME.getName().equals(param.getName())) {
                                uniqueName = param.getValue();
                                break;
                            }
                        }
                        if (uniqueName != null) {
                            category = uniqueName;
                        }
                    }
                }
                break;
            case JOB_PROPERTY_EXTRA:
            case JOB_PROPERTY_STATS_LOGS:
            case JOB_PROPERTY_HEADERFOOTER:
            case JOB_PROPERTY_MAPREDUCE:
                boolean isJoblet = false;
                boolean isMR = false;
                if (getUpdateObject() != null) {
                    if (getUpdateObject() instanceof org.talend.designer.core.ui.editor.process.Process) {
                        if (AbstractProcessProvider.isExtensionProcessForJoblet((IProcess) getUpdateObject())) {
                            isJoblet = true;
                        } else if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
                            IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
                            org.talend.core.model.properties.Item item = ((org.talend.designer.core.ui.editor.process.Process) getUpdateObject()).getProperty().getItem();
                            isMR = mrProcessService.isMapReduceItem(item);
                        }
                    }
                }
                if (isMR) {
                    //
                    category = JobSettingsView.VIEW_NAME_BATCH;
                } else if (isJoblet) {
                    // joblet
                    category = JobSettingsView.VIEW_NAME_JOBLET;
                } else {
                    category = JobSettingsView.getViewNameLable();
                }
                break;
            case JOB_PROPERTY_STORM:
                boolean isStreaming = false;
                if (getUpdateObject() != null && getUpdateObject() instanceof org.talend.designer.core.ui.editor.process.Process) {
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IStormProcessService.class)) {
                        IStormProcessService streamingService = (IStormProcessService) GlobalServiceRegister.getDefault().getService(IStormProcessService.class);
                        org.talend.core.model.properties.Item item = ((org.talend.designer.core.ui.editor.process.Process) getUpdateObject()).getProperty().getItem();
                        isStreaming = streamingService.isStormItem(item);
                    }
                }
                if (isStreaming) {
                    //
                    category = JobSettingsView.VIEW_NAME_STREAMING;
                } else {
                    category = JobSettingsView.getViewNameLable();
                }
                break;
            case CONTEXT:
                // case JOBLET_CONTEXT:
                category = UpdatesConstants.CONTEXT;
                break;
            case CONTEXT_GROUP:
                category = UpdatesConstants.CONTEXT_GROUP;
                break;
            case JOBLET_RENAMED:
            case RELOAD:
            case JUNIT_RELOAD:
                if (getUpdateObject() != null && getUpdateObject() instanceof List) {
                    String display = UpdateManagerHelper.getCollectionsDisplay(getUpdateObject(), true);
                    if (display != null) {
                        category = display;
                    }
                } else if (getParameter() != null && getParameter() instanceof PropertyChangeEvent) {
                    PropertyChangeEvent event = (PropertyChangeEvent) getParameter();
                    // reload all compoennts.
                    if (event.getSource() != null && !(event.getSource() instanceof IProcess)) {
                        category = UpdatesConstants.COMPONENT;
                        break;
                    }
                } else {
                    category = UpdatesConstants.JOBLET;
                }
                break;
            default:
        }
    } else {
        category = UpdateManagerProviderDetector.INSTANCE.getDisplayCategory(this);
    }
    return category == null ? UpdatesConstants.EMPTY : category;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IMRProcessService(org.talend.core.service.IMRProcessService) Item(org.talend.core.model.properties.Item) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IStormProcessService(org.talend.core.service.IStormProcessService) IProcess(org.talend.core.model.process.IProcess) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) List(java.util.List) IProcess(org.talend.core.model.process.IProcess)

Example 54 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class UpdateContentProvider method getElements.

@Override
@SuppressWarnings("unchecked")
public Object[] getElements(Object inputElement) {
    List<Job> jobs = new ArrayList<Job>();
    if (inputElement instanceof Collection) {
        for (UpdateResult result : (List<UpdateResult>) inputElement) {
            String jobName = result.getJobInfor();
            if (jobName == null) {
                jobName = UpdatesConstants.EMPTY;
            }
            Job job = getJob(jobs, jobName);
            if (job == null) {
                job = new Job(jobName);
                Object job2 = result.getJob();
                if (job2 != null) {
                    if (job2 instanceof IProcess2) {
                        // ?? joblet
                        job.setJoblet(((IProcess2) job2).disableRunJobView());
                        job.setReadOnlyProcess(result.isReadOnlyProcess());
                        IProcess2 process = (IProcess2) job2;
                        org.talend.core.model.properties.Item processItem = process.getProperty().getItem();
                        job.setModelItem(processItem);
                        boolean isMRProcess = false;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IMRProcessService.class)) {
                            IMRProcessService mrProcessService = (IMRProcessService) GlobalServiceRegister.getDefault().getService(IMRProcessService.class);
                            isMRProcess = mrProcessService.isMapReduceItem(processItem);
                        }
                        boolean isStreamingProcess = false;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IStormProcessService.class)) {
                            IStormProcessService streamingService = (IStormProcessService) GlobalServiceRegister.getDefault().getService(IStormProcessService.class);
                            isStreamingProcess = streamingService.isStormItem(processItem);
                        }
                        if (isMRProcess) {
                            job.setMR(isMRProcess);
                        } else if (isStreamingProcess) {
                            job.setStreaming(isStreamingProcess);
                        } else if (processItem instanceof ProcessItem) {
                            job.setJoblet(false);
                            job.setMR(false);
                            job.setStreaming(false);
                            job.setSparkJoblet(false);
                            job.setSparkStreamingJoblet(false);
                        } else if (processItem instanceof JobletProcessItem) {
                            boolean isSpark = false;
                            boolean isSparkStreaming = false;
                            if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkJobletProviderService.class)) {
                                ISparkJobletProviderService sparkJobletService = (ISparkJobletProviderService) GlobalServiceRegister.getDefault().getService(ISparkJobletProviderService.class);
                                if (sparkJobletService != null && sparkJobletService.isSparkJobletItem(processItem)) {
                                    isSpark = true;
                                }
                            }
                            if (GlobalServiceRegister.getDefault().isServiceRegistered(ISparkStreamingJobletProviderService.class)) {
                                ISparkStreamingJobletProviderService sparkStreamingJobletService = (ISparkStreamingJobletProviderService) GlobalServiceRegister.getDefault().getService(ISparkStreamingJobletProviderService.class);
                                if (sparkStreamingJobletService != null && sparkStreamingJobletService.isSparkStreamingJobletItem(processItem)) {
                                    isSparkStreaming = true;
                                }
                            }
                            if (isSpark) {
                                job.setSparkJoblet(true);
                                job.setJoblet(false);
                            } else if (isSparkStreaming) {
                                job.setSparkStreamingJoblet(true);
                                job.setJoblet(false);
                            } else {
                                job.setJoblet(true);
                            }
                        }
                    }
                } else {
                    String itemId = result.getObjectId();
                    if (itemId != null) {
                        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                        try {
                            IRepositoryViewObject repoViewObject = factory.getLastVersion(itemId);
                            if (repoViewObject != null) {
                                Property property = repoViewObject.getProperty();
                                if (property != null) {
                                    job.setModelItem(property.getItem());
                                }
                            }
                        } catch (PersistenceException e) {
                            CommonExceptionHandler.process(e, Priority.WARN);
                        }
                    }
                    job.setJoblet(result.isJoblet());
                    job.setMR(result.isMR());
                    job.setStreaming(result.isStreaming());
                    job.setSparkJoblet(result.isSparkJoblet());
                    job.setSparkStreamingJoblet(result.isSparkStreamingJoblet());
                }
                jobs.add(job);
            }
            Category category = job.getCategory(result.getCategory());
            if (category == null) {
                category = new Category(job, result.getCategory());
                // for icon
                category.setType(result.getUpdateType());
                if (result.getUpdateObject() instanceof Node) {
                    // for node icon
                    category.setNode(result.getUpdateObject());
                }
                if (result.getUpdateObject() instanceof NodeType) {
                    // for node icon
                    category.setNode(result.getUpdateObject());
                }
                if (result.getUpdateObject() instanceof List) {
                    // for node icon
                    List list = (List) result.getUpdateObject();
                    if (list.size() > 0) {
                        Object object = list.get(0);
                        if (object instanceof Node) {
                            category.setNode(object);
                        }
                    }
                }
                job.addCategory(category);
            }
            Item item = new Item(category, result);
            category.addItem(item);
        }
    }
    return jobs.toArray();
}
Also used : IMRProcessService(org.talend.core.service.IMRProcessService) IStormProcessService(org.talend.core.service.IStormProcessService) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.talend.core.model.properties.Property) UpdateResult(org.talend.core.model.update.UpdateResult) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ISparkJobletProviderService(org.talend.core.ui.ISparkJobletProviderService) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ISparkStreamingJobletProviderService(org.talend.core.ui.ISparkStreamingJobletProviderService) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) Collection(java.util.Collection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 55 with NodeType

use of org.talend.designer.core.model.utils.emf.talendfile.NodeType in project tdi-studio-se by Talend.

the class TXMLMapChangeAllInOneValueMigrationTask method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.talend.core.model.migration.TXMLMapChangeAllInOneValueMigrationTask
	 * (org .talend.core.model.properties.Item)
	 */
@Override
public ExecutionResult execute(Item item) {
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
    ProcessType processType = getProcessType(item);
    boolean modified = false;
    if (processType != null) {
        for (Object obj : processType.getNode()) {
            NodeType nodeType = (NodeType) obj;
            if (nodeType.getComponentName().startsWith("tXMLMap")) {
                XmlMapData xmlMapdata = (XmlMapData) nodeType.getNodeData();
                EList<OutputXmlTree> outputTables = xmlMapdata.getOutputTrees();
                EList<InputXmlTree> inputTables = xmlMapdata.getInputTrees();
                boolean hasDocumentInTheMainInputTable = false;
                for (InputXmlTree inputTable : inputTables) {
                    if (!(inputTable.isLookup())) {
                        for (TreeNode inputEntry : inputTable.getNodes()) {
                            if ("id_Document".equals(inputEntry.getType())) {
                                hasDocumentInTheMainInputTable = true;
                            }
                        }
                    }
                }
                if (hasDocumentInTheMainInputTable) {
                    for (OutputXmlTree outputTable : outputTables) {
                        for (TreeNode outputEntry : outputTable.getNodes()) {
                            if ("id_Document".equals(outputEntry.getType())) {
                                if (!outputTable.isAllInOne()) {
                                    outputTable.setAllInOne(true);
                                    modified = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    try {
        if (modified) {
            factory.save(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        } else {
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : InputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.InputXmlTree) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) TreeNode(org.talend.designer.xmlmap.model.emf.xmlmap.TreeNode) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) OutputXmlTree(org.talend.designer.xmlmap.model.emf.xmlmap.OutputXmlTree) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) XmlMapData(org.talend.designer.xmlmap.model.emf.xmlmap.XmlMapData)

Aggregations

NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)198 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)157 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)127 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)112 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)111 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)110 PersistenceException (org.talend.commons.exception.PersistenceException)93 ProcessItem (org.talend.core.model.properties.ProcessItem)25 ArrayList (java.util.ArrayList)24 EList (org.eclipse.emf.common.util.EList)23 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)21 List (java.util.List)20 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)18 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)13 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)13 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)13 IComponent (org.talend.core.model.components.IComponent)10 ColumnType (org.talend.designer.core.model.utils.emf.talendfile.ColumnType)9 Property (org.talend.core.model.properties.Property)8