Search in sources :

Example 41 with IRepositoryViewObject

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

the class DowngradeParameterHelper method getOldLabelFromId.

/**
     * DOC nrousseau Comment method "getOldLabelFromId".
     * 
     * @param id
     * @param type
     * @return
     */
private static String getOldLabelFromId(String id, ERepositoryObjectType type) {
    final IProxyRepositoryFactory proxyRepositoryFactory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
    try {
        ERepositoryObjectType repositoryConnectionsNeeded;
        if (type == ERepositoryObjectType.METADATA_CON_QUERY) {
            repositoryConnectionsNeeded = ERepositoryObjectType.METADATA_CONNECTIONS;
        } else {
            repositoryConnectionsNeeded = ERepositoryObjectType.METADATA;
        }
        List<IRepositoryViewObject> objects = proxyRepositoryFactory.getAll(repositoryConnectionsNeeded);
        ConnectionItem connectionItem = null;
        for (IRepositoryViewObject object : objects) {
            connectionItem = (ConnectionItem) object.getProperty().getItem();
            if (type == ERepositoryObjectType.METADATA_CON_QUERY) {
                QueriesConnection queries = connectionItem.getConnection().getQueries();
                if (queries == null) {
                    continue;
                }
                for (Query query : (List<Query>) queries.getQuery()) {
                    if (query.getId().equals(id)) {
                        return connectionItem.getProperty().getId() + SEPARATOR + query.getLabel();
                    }
                }
            } else if (type == ERepositoryObjectType.METADATA_CON_TABLE) {
                for (MetadataTable table : (Set<MetadataTable>) ConnectionHelper.getTables(connectionItem.getConnection())) {
                    if (table.getId().equals(id)) {
                        return connectionItem.getProperty().getId() + SEPARATOR + table.getLabel();
                    }
                }
            }
        }
    } catch (PersistenceException e) {
        return null;
    }
    return null;
}
Also used : QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) Query(org.talend.core.model.metadata.builder.connection.Query) ConnectionItem(org.talend.core.model.properties.ConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) PersistenceException(org.talend.commons.exception.PersistenceException) List(java.util.List) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 42 with IRepositoryViewObject

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

the class JavaProcessorUtilities method getNeededModulesForProcess.

public static Set<ModuleNeeded> getNeededModulesForProcess(IProcess process) {
    Set<ModuleNeeded> neededLibraries = new TreeSet<ModuleNeeded>(new Comparator<ModuleNeeded>() {

        @Override
        public int compare(ModuleNeeded m1, ModuleNeeded m2) {
            return m1.toString().compareTo(m2.toString());
        }
    });
    Set<ModuleNeeded> neededModules = LastGenerationInfo.getInstance().getModulesNeededWithSubjobPerJob(process.getId(), process.getVersion());
    neededLibraries.addAll(neededModules);
    if (process == null || !(process instanceof IProcess2)) {
        if (neededLibraries.isEmpty() && process != null) {
            neededLibraries = process.getNeededModules(true);
            if (neededLibraries == null) {
                neededLibraries = new HashSet<ModuleNeeded>();
            // for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeeded()) {
            // neededLibraries.add(moduleNeeded.getModuleName());
            // }
            }
        } else {
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getRunningModules()) {
                neededLibraries.add(moduleNeeded);
            }
        }
        return neededLibraries;
    }
    Property property = ((IProcess2) process).getProperty();
    if (neededLibraries.isEmpty()) {
        neededLibraries = process.getNeededModules(true);
        if (neededLibraries == null) {
            neededLibraries = new HashSet<ModuleNeeded>();
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeeded()) {
                neededLibraries.add(moduleNeeded);
            }
        }
    } else {
        if (property != null && property.getItem() instanceof ProcessItem) {
            neededLibraries.addAll(ModulesNeededProvider.getModulesNeededForProcess((ProcessItem) property.getItem(), process));
        } else {
            for (ModuleNeeded moduleNeeded : ModulesNeededProvider.getRunningModules()) {
                neededLibraries.add(moduleNeeded);
            }
        }
    }
    if (property != null && GlobalServiceRegister.getDefault().isServiceRegistered(ICamelDesignerCoreService.class)) {
        ICamelDesignerCoreService camelService = (ICamelDesignerCoreService) GlobalServiceRegister.getDefault().getService(ICamelDesignerCoreService.class);
        if (camelService.isInstanceofCamel(property.getItem())) {
            // http://jira.talendforge.org/browse/TESB-5887 LiXiaopeng 2012-6-19
            // Synchronize Route resources
            camelService.synchronizeRouteResource((ProcessItem) property.getItem());
            try {
                for (IRepositoryViewObject object : CoreRuntimePlugin.getInstance().getProxyRepositoryFactory().getAll(camelService.getBeansType())) {
                    Item item = object.getProperty().getItem();
                    if (item instanceof RoutineItem) {
                        RoutineItem routine = (RoutineItem) item;
                        for (Object o : routine.getImports()) {
                            IMPORTType type = (IMPORTType) o;
                            ModuleNeeded neededModule = new ModuleNeeded("camel bean dependencies", type.getMODULE(), "camel bean dependencies", true);
                            neededLibraries.add(neededModule);
                        }
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    return neededLibraries;
}
Also used : ICamelDesignerCoreService(org.talend.designer.core.ICamelDesignerCoreService) RoutineItem(org.talend.core.model.properties.RoutineItem) Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) TreeSet(java.util.TreeSet) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IMPORTType(org.talend.designer.core.model.utils.emf.component.IMPORTType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) Property(org.talend.core.model.properties.Property)

Example 43 with IRepositoryViewObject

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

the class VersionManagementPage method versionLatest.

private void versionLatest() {
    List<ItemVersionObject> tableList = new ArrayList<ItemVersionObject>();
    tableList.addAll(checkedObjects);
    for (ItemVersionObject object : checkedObjects) {
        if (object.getRepositoryNode() != null) {
            List<Relation> relations = builder.getItemsJobRelatedTo(object.getRepositoryNode().getId(), object.getOldVersion(), RelationshipItemBuilder.JOB_RELATION);
            for (Relation relation : relations) {
                try {
                    IRepositoryViewObject obj = FACTORY.getLastVersion(relation.getId());
                    if (obj != null) {
                        for (ItemVersionObject obj2 : versionObjects) {
                            if (obj2.getItem() == obj.getProperty().getItem()) {
                                ItemVersionObject relat = obj2;
                                if (!tableList.contains(relat)) {
                                    tableList.add(relat);
                                    checkAllVerSionLatest(tableList, relat);
                                }
                                break;
                            }
                        }
                    }
                } catch (PersistenceException et) {
                    ExceptionHandler.process(et);
                }
            }
        }
    }
    removeItemElements(checkedObjects);
    checkedObjects.clear();
    checkedObjects.addAll(tableList);
    refreshTableItems();
    refreshCheckedTreeView();
}
Also used : Relation(org.talend.core.model.relationship.Relation) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ItemVersionObject(org.talend.repository.model.ItemVersionObject)

Example 44 with IRepositoryViewObject

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

the class VersionManagementPage method updateItemsVersion.

@Override
protected void updateItemsVersion() {
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new RepositoryWorkUnit<Object>(project, "Update items version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items version", checkedObjects.size());
                    Map<String, String> versions = new HashMap<String, String>();
                    for (int i = 0; i < checkedObjects.size(); i++) {
                        ItemVersionObject object = checkedObjects.get(i);
                        versions.put(object.getItem().getProperty().getId(), object.getOldVersion());
                    }
                    for (ItemVersionObject object : checkedObjects) {
                        IRepositoryViewObject repositoryObject = object.getRepositoryNode().getObject();
                        if (repositoryObject != null && repositoryObject.getProperty() != null) {
                            if (!object.getNewVersion().equals(repositoryObject.getVersion())) {
                                final Item item = object.getItem();
                                Property itemProperty = item.getProperty();
                                itemProperty.setVersion(object.getNewVersion());
                                monitor.subTask(itemProperty.getLabel());
                                try {
                                    // for bug 12853 ,version management doesn't work for joblet because eResource
                                    // is null
                                    IRepositoryViewObject obj = null;
                                    if (itemProperty.eResource() == null) {
                                        ItemState state = item.getState();
                                        if (state != null && state.getPath() != null) {
                                            obj = FACTORY.getLastVersion(project, itemProperty.getId(), state.getPath(), object.getRepositoryNode().getObjectType());
                                        } else {
                                            obj = FACTORY.getLastVersion(project, itemProperty.getId());
                                        }
                                    }
                                    if (obj != null) {
                                        // obj.setVersion(object.getNewVersion());
                                        FACTORY.save(project, obj.getProperty());
                                        builder.addOrUpdateItem(obj.getProperty().getItem(), true);
                                    } else {
                                        String id = itemProperty.getId();
                                        FACTORY.save(project, itemProperty);
                                        if (versionLatest.getSelection()) {
                                            builder.updateItemVersion(item, object.getOldVersion(), id, versions, true);
                                        }
                                        builder.addOrUpdateItem(item, true);
                                    }
                                } catch (PersistenceException e) {
                                    ExceptionHandler.process(e);
                                }
                            }
                        }
                        monitor.worked(1);
                    }
                    try {
                        FACTORY.saveProject(project);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            rwu.setAvoidUnloadResources(true);
            rwu.executeRun();
            monitor.done();
        }
    };
    IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update the project files need to be done in the workspace runnable to avoid all notification
                // of changes before the end of the modifications.
                workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    // final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(null);
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashMap(java.util.HashMap) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ItemState(org.talend.core.model.properties.ItemState) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) Property(org.talend.core.model.properties.Property)

Example 45 with IRepositoryViewObject

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

the class VersionManagementPage method selectAllDependencies.

private void selectAllDependencies() {
    List<ItemVersionObject> tableList = new ArrayList<ItemVersionObject>();
    tableList.addAll(checkedObjects);
    IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
    for (ItemVersionObject object : checkedObjects) {
        if (object.getRepositoryNode() != null) {
            List<Relation> relations = builder.getItemsRelatedTo(object.getRepositoryNode().getId(), object.getOldVersion(), RelationshipItemBuilder.JOB_RELATION);
            for (Relation relation : relations) {
                IRepositoryViewObject obj = null;
                try {
                    if (RelationshipItemBuilder.ROUTINE_RELATION.equals(relation.getType())) {
                        obj = RoutinesUtil.getRoutineFromName(relation.getId());
                    } else {
                        obj = factory.getLastVersion(relation.getId());
                    }
                    if (obj != null) {
                        for (ItemVersionObject obj2 : versionObjects) {
                            if (obj2.getItem() == obj.getProperty().getItem()) {
                                ItemVersionObject relat = obj2;
                                if (!tableList.contains(relat)) {
                                    tableList.add(relat);
                                    checkAllVerSionLatest(tableList, relat);
                                }
                                break;
                            }
                        }
                    }
                } catch (PersistenceException et) {
                    ExceptionHandler.process(et);
                }
            }
        }
    }
    removeItemElements(checkedObjects);
    checkedObjects.clear();
    checkedObjects.addAll(tableList);
    refreshTableItems();
    refreshCheckedTreeView();
}
Also used : Relation(org.talend.core.model.relationship.Relation) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ItemVersionObject(org.talend.repository.model.ItemVersionObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

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