Search in sources :

Example 26 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class MultipleThreadDynamicComposite method updateRepositoryList.

public void updateRepositoryList() {
    ProgressDialog progressDialog = new ProgressDialog(this.getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitorWrap = new EventLoopProgressMonitor(monitor);
            IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
            List<IRepositoryViewObject> repositoryObjects = getAllRepositoryMetadata();
            // + elem.getElementParameters().size();
            int total = repositoryObjects.size();
            //$NON-NLS-1$
            monitorWrap.beginTask(Messages.getString("MultipleThreadDynamicComposite.gatherInformation"), total);
            IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, section);
            String repositoryValue = null;
            if (propertyParam != null) {
                repositoryValue = propertyParam.getRepositoryValue();
            }
            if (repositoryObjects != null && (repositoryObjects.size() != 0)) {
                tableIdAndDbTypeMap.clear();
                tableIdAndDbSchemaMap.clear();
                for (IRepositoryViewObject curObject : repositoryObjects) {
                    Item item = curObject.getProperty().getItem();
                    if (item instanceof ConnectionItem) {
                        ConnectionItem connectionItem = (ConnectionItem) item;
                        Connection connection = connectionItem.getConnection();
                        if (connection == null || connection.isReadOnly()) {
                            continue;
                        }
                        for (Object tableObj : ConnectionHelper.getTables(connection)) {
                            org.talend.core.model.metadata.builder.connection.MetadataTable table;
                            table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
                            if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
                                if (!factory.isDeleted(table)) {
                                    IMetadataTable newTable = ConvertionHelper.convert(table);
                                    // newTable);
                                    if (connection instanceof DatabaseConnection) {
                                        String dbType = ((DatabaseConnection) connection).getDatabaseType();
                                        String schema = ((DatabaseConnection) connection).getUiSchema();
                                        tableIdAndDbTypeMap.put(newTable.getId(), dbType);
                                        if (schema != null && !schema.equals("")) {
                                            //$NON-NLS-1$
                                            tableIdAndDbSchemaMap.put(newTable.getId(), schema);
                                        }
                                    }
                                }
                            }
                        }
                        monitorWrap.worked(1);
                    }
                    // hywang add for feature 6484
                    if (item instanceof FileItem) {
                        FileItem FileItem = (FileItem) item;
                        if (repositoryValue != null) {
                            if (repositoryValue.equals("RULE")) {
                                //$NON-NLS-1$
                                repositoryFileItemMap.put(FileItem.getProperty().getId(), FileItem);
                            }
                        }
                        monitorWrap.worked(1);
                    }
                    if (item instanceof LinkRulesItem) {
                        LinkRulesItem linkItem = (LinkRulesItem) item;
                        if (repositoryValue != null) {
                            if (repositoryValue.equals("RULE")) {
                                //$NON-NLS-1$
                                repositoryLinkRulesItemMap.put(linkItem.getProperty().getId(), linkItem);
                            }
                        }
                        monitorWrap.worked(1);
                    }
                }
            }
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
        return;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return;
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) FileItem(org.talend.core.model.properties.FileItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 27 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class MultipleThreadDynamicComposite method getAllRepositoryMetadata.

/**
     * 
     * cli Comment method "getAllRepositoryMetadata".
     * 
     * fixed for 8971
     */
private List<IRepositoryViewObject> getAllRepositoryMetadata() {
    IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    ProjectManager pManager = ProjectManager.getInstance();
    // retrieve reference project.
    pManager.getReferencedProjects();
    List<IRepositoryViewObject> repositoryObjects;
    try {
        repositoryObjects = retrieveMetadataFromProject(factory, pManager, pManager.getCurrentProject());
    } catch (PersistenceException e) {
        throw new RuntimeException(e);
    }
    return repositoryObjects;
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProjectManager(org.talend.repository.ProjectManager)

Example 28 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class SQLPatternComposite method getAllSqlPatterns.

private List<SQLPatternInfor> getAllSqlPatterns(List<Map> tableInput, boolean modifySQL) {
    IElementParameter elementParam = element.getElementParameter(EParameterName.SQLPATTERN_DB_NAME.getName());
    if (elementParam == null) {
        return Collections.EMPTY_LIST;
    }
    // String dbName = (String) elementParam.getValue();
    List<SQLPatternInfor> patternInfor = new ArrayList<SQLPatternInfor>();
    try {
        List<IRepositoryViewObject> list = null;
        if (isItemIndexChecked() && modifySQL) {
            List<Relation> relations = new ArrayList<Relation>();
            IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
            List<IRepositoryViewObject> updateList = new ArrayList<IRepositoryViewObject>();
            for (Map map : tableInput) {
                String id = (String) map.get(SQLPatternUtils.SQLPATTERNLIST);
                relations.addAll(RelationshipItemBuilder.getInstance().getItemsRelatedTo(id, ItemCacheManager.LATEST_VERSION, RelationshipItemBuilder.SQLPATTERN_RELATION));
            }
            for (Relation relation : relations) {
                try {
                    IRepositoryViewObject obj = factory.getLastVersion(relation.getId());
                    if (obj != null) {
                        updateList.add(obj);
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
            }
            list = updateList;
        } else {
            list = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAll(ERepositoryObjectType.SQLPATTERNS, false);
            // add reference sql pattern
            addReferencedSQLTemplate(list, ProjectManager.getInstance().getCurrentProject());
        }
        for (IRepositoryViewObject repositoryObject : list) {
            Item item = repositoryObject.getProperty().getItem();
            if (item instanceof SQLPatternItem) {
                SQLPatternItem sqlitem = (SQLPatternItem) repositoryObject.getProperty().getItem();
                // disable this test as there is now only Generic ELT components
                // if (item.getEltName().equals(dbName)) {
                patternInfor.add(new SQLPatternInfor(sqlitem.getProperty().getId() + SQLPatternUtils.ID_SEPARATOR + sqlitem.getProperty().getLabel(), sqlitem.getProperty().getLabel()));
            // }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return patternInfor;
}
Also used : ArrayList(java.util.ArrayList) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) PartInitException(org.eclipse.ui.PartInitException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) TableItem(org.eclipse.swt.widgets.TableItem) Relation(org.talend.core.model.relationship.Relation) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) Map(java.util.Map) HashMap(java.util.HashMap) BidiMap(org.apache.commons.collections.BidiMap) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 29 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class SQLPatternComposite method addReferencedSQLTemplate.

private void addReferencedSQLTemplate(List<IRepositoryViewObject> list, Project project) {
    try {
        Context ctx = CorePlugin.getContext();
        if (ctx == null) {
            return;
        }
        String parentBranch = ProjectManager.getInstance().getMainProjectBranch(project);
        List<ProjectReference> referencedProjects = project.getEmfProject().getReferencedProjects();
        for (ProjectReference referenced : referencedProjects) {
            if (referenced.getBranch() != null && !parentBranch.equals(referenced.getBranch())) {
                continue;
            }
            org.talend.core.model.properties.Project referencedEmfProject = referenced.getReferencedProject();
            EList refeInRef = referencedEmfProject.getReferencedProjects();
            Project newProject = new Project(referencedEmfProject);
            if (refeInRef != null && refeInRef.size() > 0) {
                addReferencedSQLTemplate(list, newProject);
            }
            List<IRepositoryViewObject> refList;
            refList = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().getAll(newProject, ERepositoryObjectType.SQLPATTERNS, false);
            for (IRepositoryViewObject repositoryObject : refList) {
                Item item = repositoryObject.getProperty().getItem();
                if (item instanceof SQLPatternItem) {
                    if (!((SQLPatternItem) item).isSystem()) {
                        list.add(repositoryObject);
                        sqlPatternAndProject.put((SQLPatternItem) item, project);
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Context(org.talend.core.context.Context) ProjectReference(org.talend.core.model.properties.ProjectReference) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) Project(org.talend.core.model.general.Project) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) TableItem(org.eclipse.swt.widgets.TableItem) EList(org.eclipse.emf.common.util.EList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 30 with IRepositoryViewObject

use of org.talend.core.model.repository.IRepositoryViewObject in project tdi-studio-se by Talend.

the class JSONConnectionContextHelper method convertContextLabel.

/**
     * 
     * change the mode of lebel to Context mode
     * 
     * @param label which you want to convert(it is the name of connection normal)
     * @return Context mode label
     */
public static String convertContextLabel(String label) {
    if (label != null) {
        //$NON-NLS-1$ //$NON-NLS-2$
        String newLabel = label.replaceAll("[\\.\\-\\ \\(\\)\\[\\]=]", "_");
        //$NON-NLS-1$
        Pattern pattern = Pattern.compile("^[0-9]+.*$");
        Matcher m = pattern.matcher(newLabel);
        if (m.matches()) {
            //$NON-NLS-1$
            newLabel = "_" + newLabel;
        }
        //
        try {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<IRepositoryViewObject> contextObjectList = factory.getAll(ERepositoryObjectType.CONTEXT, true);
            int i = 1;
            String tmpLabel = newLabel;
            while (!isValidContextName(contextObjectList, tmpLabel)) {
                tmpLabel = newLabel + i;
                i++;
            }
            return tmpLabel;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
        return newLabel;
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) Matcher(java.util.regex.Matcher) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)222 PersistenceException (org.talend.commons.exception.PersistenceException)115 Item (org.talend.core.model.properties.Item)86 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)67 ArrayList (java.util.ArrayList)63 ConnectionItem (org.talend.core.model.properties.ConnectionItem)54 ProcessItem (org.talend.core.model.properties.ProcessItem)54 RepositoryNode (org.talend.repository.model.RepositoryNode)50 IElementParameter (org.talend.core.model.process.IElementParameter)43 Property (org.talend.core.model.properties.Property)43 IRepositoryNode (org.talend.repository.model.IRepositoryNode)33 List (java.util.List)32 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)32 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)31 INode (org.talend.core.model.process.INode)30 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)25 Node (org.talend.designer.core.ui.editor.nodes.Node)25 Connection (org.talend.core.model.metadata.builder.connection.Connection)23 CoreException (org.eclipse.core.runtime.CoreException)17 RoutineItem (org.talend.core.model.properties.RoutineItem)17