Search in sources :

Example 36 with ProxyRepositoryFactory

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

the class ExportProjectsAsAction method getRoutineFromProject.

/**
     * DOC bqian Comment method "getRouineFromProject".
     * 
     * @param project
     */
private RootContainer<String, IRepositoryViewObject> getRoutineFromProject(Project project) {
    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    RootContainer<String, IRepositoryViewObject> routines = null;
    try {
        routines = factory.getRoutineFromProject(project);
    } catch (PersistenceException e) {
        // TODO Auto-generated catch block
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
    return routines;
}
Also used : IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 37 with ProxyRepositoryFactory

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

the class TOSLoginComposite method readProject.

public Project[] readProject() {
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    Project[] projects = null;
    try {
        projects = repositoryFactory.readProject();
    } catch (PersistenceException e1) {
        e1.printStackTrace();
    } catch (BusinessException e1) {
        e1.printStackTrace();
    }
    return projects;
}
Also used : Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) BusinessException(org.talend.commons.exception.BusinessException) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 38 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tesb-studio-se by Talend.

the class ServiceExportWithMavenManager method analysisMavenModule.

@Override
protected void analysisMavenModule(Item item) {
    if (item != null && item instanceof ServiceItem) {
        try {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            List<String> mavenModules = getMavenModules();
            ServiceItem serviceItem = (ServiceItem) item;
            ServiceConnection connection = (ServiceConnection) serviceItem.getConnection();
            EList<ServicePort> listPort = connection.getServicePort();
            for (ServicePort port : listPort) {
                List<ServiceOperation> listOperation = port.getServiceOperation();
                for (ServiceOperation operation : listOperation) {
                    if (StringUtils.isNotEmpty(operation.getReferenceJobId())) {
                        IRepositoryViewObject repObj = factory.getLastVersion(operation.getReferenceJobId());
                        if (repObj != null) {
                            String jobName = repObj.getLabel();
                            if (jobName != null && !mavenModules.contains(jobName)) {
                                mavenModules.add(OPERATIONS_PATH + jobName);
                            }
                        }
                    }
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : ServicePort(org.talend.repository.services.model.services.ServicePort) ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ServiceOperation(org.talend.repository.services.model.services.ServiceOperation)

Example 39 with ProxyRepositoryFactory

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

the class UpdateManagerUtils method doExecuteUpdates.

private static boolean doExecuteUpdates(final List<UpdateResult> results, final boolean updateAllJobs) {
    if (results == null || results.isEmpty()) {
        return false;
    }
    try {
        IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                monitor.setCanceled(false);
                int size = (results.size() * 2 + 1) * UpdatesConstants.SCALE;
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("UpdateManagerUtils.Update"), size);
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                // first list by job we need to update
                Map<String, Set<String>> jobIdToVersion = new HashMap<String, Set<String>>();
                Map<String, Boolean> jobIdClosed = new HashMap<String, Boolean>();
                for (UpdateResult result : results) {
                    // if (!result.isChecked()) {
                    // continue;
                    // }
                    String id = result.getObjectId();
                    String version = result.getObjectVersion();
                    if (id == null) {
                        if (result.getJob() != null && result.getJob() instanceof IProcess) {
                            IProcess process = (IProcess) result.getJob();
                            if (process instanceof IProcess2 && ERepositoryStatus.LOCK_BY_OTHER.equals(factory.getStatus(((IProcess2) process).getProperty().getItem()))) {
                                // file.
                                continue;
                            }
                            id = process.getId();
                            version = process.getVersion();
                            result.setObjectId(id);
                            result.setObjectVersion(version);
                        } else {
                            continue;
                        }
                    }
                    Set<String> versionList;
                    if (!jobIdToVersion.containsKey(id)) {
                        versionList = new HashSet<String>();
                        jobIdToVersion.put(id, versionList);
                    } else {
                        versionList = jobIdToVersion.get(id);
                    }
                    versionList.add(version);
                    //$NON-NLS-1$
                    jobIdClosed.put(id + " - " + version, result.isFromItem());
                }
                // now will execute updates only for the job selected depends this list.
                for (String currentId : jobIdToVersion.keySet()) {
                    for (String version : jobIdToVersion.get(currentId)) {
                        IRepositoryViewObject currentObj = null;
                        //$NON-NLS-1$
                        boolean closedItem = jobIdClosed.get(currentId + " - " + version);
                        IProcess process = null;
                        Item item = null;
                        if (closedItem) {
                            // if item is closed, then just load it.
                            boolean checkOnlyLastVersion = Boolean.parseBoolean(DesignerPlugin.getDefault().getPreferenceStore().getString(//$NON-NLS-1$
                            "checkOnlyLastVersion"));
                            try {
                                if (checkOnlyLastVersion || version == null) {
                                    currentObj = factory.getLastVersion(currentId);
                                } else {
                                    List<IRepositoryViewObject> allVersion = factory.getAllVersion(currentId);
                                    for (IRepositoryViewObject obj : allVersion) {
                                        if (obj.getVersion().equals(version)) {
                                            currentObj = obj;
                                        }
                                    }
                                }
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                            if (currentObj == null) {
                                // item not found, don't do anything
                                continue;
                            }
                            item = currentObj.getProperty().getItem();
                            IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
                            if (item instanceof ProcessItem) {
                                process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
                            } else if (item instanceof JobletProcessItem) {
                                process = designerCoreService.getProcessFromJobletProcessItem((JobletProcessItem) item);
                            }
                        }
                        for (UpdateResult result : results) {
                            // }
                            if (!StringUtils.equals(currentId, result.getObjectId())) {
                                // not the current job we need to update
                                continue;
                            }
                            if (closedItem) {
                                if (result.getJob() == null) {
                                    result.setJob(process);
                                } else {
                                    process = (IProcess) result.getJob();
                                }
                                IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
                                if (process != null && jobletContextType != null && (jobletContextType.equals(result.getUpdateType()))) {
                                    if ((result.getParameter() instanceof List) && process.getContextManager() != null) {
                                        process.getContextManager().setListContext((List<IContext>) result.getParameter());
                                    }
                                }
                            }
                            // execute
                            executeUpdate(result, monitor, updateAllJobs);
                            if (closedItem) {
                                result.setJob(null);
                            }
                        }
                        boolean isTestContainer = false;
                        ITestContainerProviderService testContainerService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                            testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                            if (testContainerService != null) {
                                isTestContainer = testContainerService.isTestContainerItem(item);
                            }
                        }
                        if (closedItem && process instanceof IProcess2) {
                            IProcess2 process2 = (IProcess2) process;
                            ProcessType processType;
                            try {
                                processType = process2.saveXmlFile(false);
                                if (isTestContainer) {
                                    testContainerService.setTestContainerProcess(processType, item);
                                } else if (item instanceof JobletProcessItem) {
                                    ((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
                                } else {
                                    ((ProcessItem) item).setProcess(processType);
                                }
                                factory.save(item);
                            } catch (IOException e) {
                                ExceptionHandler.process(e);
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                        if (closedItem && !ERepositoryStatus.LOCK_BY_USER.equals(factory.getStatus(item))) {
                            // unload item from memory, but only if this one is not locked by current user.
                            try {
                                factory.unloadResources(item.getProperty());
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                    }
                }
                UpdateManagerProviderDetector.INSTANCE.postUpdate(results);
                // update joblet reference
                upadateJobletReferenceInfor();
                final List<UpdateResult> tempResults = new ArrayList<UpdateResult>(results);
                // refresh
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refreshRelatedViewers(tempResults);
                        // hyWang add method checkandRefreshProcess for bug7248
                        checkandRefreshProcess(tempResults);
                    }
                });
                monitor.worked(1 * UpdatesConstants.SCALE);
                monitor.done();
            }
        };
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        }
        return !results.isEmpty();
    } finally {
        results.clear();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IContext(org.talend.core.model.process.IContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JobletProcess(org.talend.designer.joblet.model.JobletProcess) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) ArrayList(java.util.ArrayList) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) UpdateResult(org.talend.core.model.update.UpdateResult) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 40 with ProxyRepositoryFactory

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

the class ProjectSettingMultipleThreadDynamicComposite method updateConnectionFromRepository.

private void updateConnectionFromRepository() {
    if (repositoryPropertyName == null || repositoryPropertyName.split(":").length != 2 || connectionUpdated) {
        return;
    }
    String[] split = repositoryPropertyName.split(":");
    String parentParamName = split[0];
    Element elementParams = elem;
    IElementParameter elementParameter = elementParams.getElementParameter(parentParamName);
    if (elementParameter != null && elementParameter.isShow(elem.getElementParameters()) && elementParameter.getChildParameters() != null) {
        if (elementParameter.getChildParameters().get("PROPERTY_TYPE") != null && !EmfComponent.BUILTIN.equals(elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue())) {
            DatabaseConnection connection = null;
            String id = (String) elementParameter.getChildParameters().get("REPOSITORY_PROPERTY_TYPE").getValue();
            // bug 0018192
            String propertyType = (String) elementParameter.getChildParameters().get("PROPERTY_TYPE").getValue();
            ProxyRepositoryFactory proxyRepositoryFactory = ProxyRepositoryFactory.getInstance();
            IRepositoryViewObject lastVersion = null;
            if (null != id && !"".equals(id)) {
                try {
                    lastVersion = proxyRepositoryFactory.getLastVersion(id);
                    if (null == lastVersion && propertyType.equals(EmfComponent.REPOSITORY)) {
                        List<ConnectionItem> connectionItems = proxyRepositoryFactory.getMetadataConnectionsItem();
                        if (connectionItems.isEmpty()) {
                            elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", "");
                            ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, null, parentParamName + ":" + "PROPERTY_TYPE", EmfComponent.REPOSITORY);
                            changeValuesFromRepository1.execute();
                        }
                        for (ConnectionItem cItem : connectionItems) {
                            if (cItem instanceof DatabaseConnectionItem) {
                                id = cItem.getProperty().getId();
                                lastVersion = proxyRepositoryFactory.getLastVersion(id);
                                elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", id);
                                break;
                            }
                        }
                    }
                } catch (PersistenceException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    List<ConnectionItem> connectionItems = proxyRepositoryFactory.getMetadataConnectionsItem();
                    for (ConnectionItem cItem : connectionItems) {
                        if (cItem instanceof DatabaseConnectionItem) {
                            lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(cItem.getProperty().getId());
                            id = cItem.getProperty().getId();
                            lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(id);
                            elem.setPropertyValue("REPOSITORY_PROPERTY_TYPE", id);
                            break;
                        }
                    }
                } catch (PersistenceException e) {
                    e.printStackTrace();
                }
            }
            if (lastVersion != null && lastVersion.getProperty() != null) {
                Item item = lastVersion.getProperty().getItem();
                if (item instanceof DatabaseConnectionItem) {
                    DatabaseConnectionItem dbItem = (DatabaseConnectionItem) item;
                    connection = (DatabaseConnection) dbItem.getConnection();
                }
            }
            if (connection != null) {
                boolean sameValues = true;
                for (IElementParameter param : elementParams.getElementParameters()) {
                    String repositoryValue = param.getRepositoryValue();
                    if (param.isShow(elementParams.getElementParameters()) && repositoryValue != null && !param.getName().equals("PROPERTY_TYPE")) {
                        Object repValue = RepositoryToComponentProperty.getValue(connection, repositoryValue, null);
                        if (repValue == null) {
                            continue;
                        }
                        if (repositoryValue.equals(UpdatesConstants.TYPE)) {
                            // datebase type
                            boolean found = false;
                            String[] list = param.getListRepositoryItems();
                            for (int i = 0; (i < list.length) && (!found); i++) {
                                if (repValue.equals(list[i])) {
                                    found = true;
                                }
                            }
                            if (!found) {
                                sameValues = false;
                                break;
                            }
                        } else {
                            // check the value
                            if (!param.getValue().equals(repValue)) {
                                sameValues = false;
                                break;
                            }
                        }
                    }
                }
                if (!sameValues) {
                    ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, connection, repositoryPropertyName, id);
                    changeValuesFromRepository.execute();
                    connectionUpdated = true;
                }
            }
        // bug 0018192
        // else {
        // change to build in
        // ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem,
        // null,
        // parentParamName + ":" + "PROPERTY_TYPE", EmfComponent.BUILTIN);
        // changeValuesFromRepository1.execute();
        // }
        }
    }
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Element(org.talend.core.model.process.Element) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Aggregations

ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)74 PersistenceException (org.talend.commons.exception.PersistenceException)32 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)25 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)22 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)18 EList (org.eclipse.emf.common.util.EList)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)11 Project (org.talend.core.model.general.Project)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 BusinessException (org.talend.commons.exception.BusinessException)8 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)8 ArrayList (java.util.ArrayList)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Path (org.eclipse.core.runtime.Path)6 EConnectionType (org.talend.core.model.process.EConnectionType)6 ConnectionItem (org.talend.core.model.properties.ConnectionItem)6 List (java.util.List)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)5