Search in sources :

Example 61 with IProxyRepositoryFactory

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

the class ControllerRepositoryValueHander method fastRepositoryUpdateSchema.

private void fastRepositoryUpdateSchema(IElementParameter param) {
    if (param != null && param.getValue() != null) {
        String queryIdAndName = (String) param.getValue();
        //$NON-NLS-1$
        String[] names = queryIdAndName.split(" - ");
        if (names.length < 2) {
            return;
        }
        String linkedRepository = names[0];
        String tableName = null;
        if (names.length == 2) {
            tableName = names[1];
        } else if (names.length > 2) {
            tableName = queryIdAndName.substring(linkedRepository.length() + 3);
        }
        if (lastItemUsed != null) {
            if (!linkedRepository.equals(lastItemUsed.getProperty().getId())) {
                lastItemUsed = null;
            }
        }
        if (lastItemUsed == null) {
            IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
            Item item;
            try {
                IRepositoryViewObject object = factory.getLastVersion(linkedRepository);
                if (object == null) {
                    return;
                }
                item = object.getProperty().getItem();
                Assert.isTrue(item instanceof ConnectionItem);
                lastItemUsed = (ConnectionItem) item;
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
        // EList<MetadataTable> tableList = lastItemUsed.getConnection().getTables();
        // for (MetadataTable table )
        String displayName = //$NON-NLS-1$
        RepositoryObjectHelper.getRepositoryAliasName(lastItemUsed) + ":" + lastItemUsed.getProperty().getLabel() + " - " + //$NON-NLS-1$
        tableName;
        //$NON-NLS-1$
        IElementParameter infoObjectTypeParam = param.getElement().getElementParameter("INFO_OBJECT_TYPE");
        if (infoObjectTypeParam != null) {
            String innerIOType = (String) infoObjectTypeParam.getValue();
            if (innerIOType != null) {
                //$NON-NLS-1$ //$NON-NLS-2$
                displayName = displayName + " (" + innerIOType + ")";
            }
        }
        param.setListItemsDisplayName(new String[] { displayName });
        param.setListItemsValue(new String[] { (String) param.getValue() });
    }
}
Also used : RulesItem(org.talend.core.model.properties.RulesItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) Item(org.talend.core.model.properties.Item) FileItem(org.talend.core.model.properties.FileItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 62 with IProxyRepositoryFactory

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

the class ControllerRepositoryValueHander method fastRepositoryUpdateProperty.

private void fastRepositoryUpdateProperty(IElementParameter param) {
    if (param != null && param.getValue() != null) {
        IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
        String linkedRepository = (String) param.getValue();
        // value stored is the id, so we can get this item directly
        Item item;
        String displayName = "";
        try {
            IRepositoryViewObject object = factory.getLastVersion(linkedRepository.split(" - ")[0]);
            if (object == null) {
                return;
            }
            item = object.getProperty().getItem();
            // Assert.isTrue(item instanceof ConnectionItem);
            IESBService service = null;
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
                service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
            }
            if (service != null && ERepositoryObjectType.getItemType(item) == service.getServicesType()) {
                lastItemUsed = (ConnectionItem) item;
                displayName = "Service:" + service.getServiceLabel(item, linkedRepository);
            } else if (item instanceof ConnectionItem) {
                lastItemUsed = (ConnectionItem) item;
                displayName = //$NON-NLS-1$
                RepositoryObjectHelper.getRepositoryAliasName(lastItemUsed) + ":" + lastItemUsed.getProperty().getLabel();
            }
            if (item instanceof FileItem) {
                // hywang add for 6484
                lastFileItemUsed = (FileItem) item;
                if (lastFileItemUsed instanceof RulesItem) {
                    displayName = //$NON-NLS-1$
                    "Rules:" + lastFileItemUsed.getProperty().getLabel();
                }
            }
            if (item instanceof LinkRulesItem) {
                lastLinkItem = (LinkRulesItem) item;
                displayName = //$NON-NLS-1$
                "Rules:" + lastLinkItem.getProperty().getLabel();
            }
            if (StringUtils.isEmpty(displayName)) {
                ITDQPatternService tdqService = null;
                try {
                    tdqService = (ITDQPatternService) GlobalServiceRegister.getDefault().getService(ITDQPatternService.class);
                    if (tdqService != null) {
                        displayName = tdqService.getPatternDisplayName(item);
                    }
                } catch (RuntimeException e) {
                // nothing to do
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
        param.setListItemsDisplayName(new String[] { displayName });
        param.setListItemsValue(new String[] { (String) param.getValue() });
    }
}
Also used : LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) RulesItem(org.talend.core.model.properties.RulesItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) Item(org.talend.core.model.properties.Item) FileItem(org.talend.core.model.properties.FileItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) FileItem(org.talend.core.model.properties.FileItem) IESBService(org.talend.core.IESBService) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) ITDQPatternService(org.talend.core.ITDQPatternService) RulesItem(org.talend.core.model.properties.RulesItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 63 with IProxyRepositoryFactory

use of org.talend.repository.model.IProxyRepositoryFactory 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 64 with IProxyRepositoryFactory

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

the class SetupProcessDependenciesRoutinesAction method init.

@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    boolean canWork = !selection.isEmpty() && selection.size() == 1;
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    if (factory.isUserReadOnlyOnCurrentProject()) {
        canWork = false;
    }
    if (canWork) {
        Object o = selection.getFirstElement();
        RepositoryNode node = (RepositoryNode) o;
        switch(node.getType()) {
            case REPOSITORY_ELEMENT:
                if (ERepositoryObjectType.PROCESS_STORM != null && node.getObjectType().equals(ERepositoryObjectType.PROCESS_STORM)) {
                    canWork = true;
                } else if (ERepositoryObjectType.PROCESS_MR != null && node.getObjectType().equals(ERepositoryObjectType.PROCESS_MR)) {
                    canWork = true;
                } else if (ERepositoryObjectType.SPARK_JOBLET != null && node.getObjectType().equals(ERepositoryObjectType.SPARK_JOBLET)) {
                    canWork = true;
                } else if (ERepositoryObjectType.SPARK_STREAMING_JOBLET != null && node.getObjectType().equals(ERepositoryObjectType.SPARK_STREAMING_JOBLET)) {
                    canWork = true;
                } else if (node.getObjectType() != ERepositoryObjectType.PROCESS && node.getObjectType() != ERepositoryObjectType.JOBLET) {
                    canWork = false;
                }
                break;
            default:
                canWork = false;
        }
        if (canWork && node.getObject() != null && ProxyRepositoryFactory.getInstance().getStatus(node.getObject()) == ERepositoryStatus.DELETED) {
            canWork = false;
        }
        if (canWork && !ProjectManager.getInstance().isInCurrentMainProject(node)) {
            canWork = false;
        }
        // If the editProcess action canwork is true, then detect that the job version is the latest verison or not.
        if (canWork) {
            canWork = isLastVersion(node);
        }
    }
    setEnabled(canWork);
}
Also used : RepositoryNode(org.talend.repository.model.RepositoryNode) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 65 with IProxyRepositoryFactory

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

the class SetupProcessDependenciesRoutinesAction method doRun.

@Override
protected void doRun() {
    ISelection selection = getSelection();
    Object obj = ((IStructuredSelection) selection).getFirstElement();
    if (obj == null) {
        return;
    }
    RepositoryNode node = (RepositoryNode) obj;
    boolean readonly = false;
    IRepositoryService service = DesignerPlugin.getDefault().getRepositoryService();
    IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    ERepositoryStatus status = repFactory.getStatus(node.getObject());
    if (!repFactory.isPotentiallyEditable(node.getObject()) || status == ERepositoryStatus.LOCK_BY_OTHER || status == ERepositoryStatus.LOCK_BY_USER) {
        readonly = true;
    }
    Item item = node.getObject().getProperty().getItem();
    if (item instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) item;
        ProcessType process = processItem.getProcess();
        SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
        if (dialog.open() == Window.OK && !readonly) {
            process.getParameters().getRoutinesParameter().clear();
            createRoutinesDependencies(process, dialog.getSystemRoutines());
            createRoutinesDependencies(process, dialog.getUserRoutines());
            try {
                CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(processItem);
                RelationshipItemBuilder.getInstance().addOrUpdateItem(processItem);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobProcessItem = (JobletProcessItem) item;
        ProcessType process = jobProcessItem.getJobletProcess();
        SetupProcessDependenciesRoutinesDialog dialog = new SetupProcessDependenciesRoutinesDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), process, readonly);
        if (dialog.open() == Window.OK && !readonly) {
            process.getParameters().getRoutinesParameter().clear();
            createRoutinesDependencies(process, dialog.getSystemRoutines());
            createRoutinesDependencies(process, dialog.getUserRoutines());
            try {
                CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(jobProcessItem);
                IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
                if (jobletService != null) {
                    jobletService.loadComponentsFromProviders();
                }
                RelationshipItemBuilder.getInstance().addOrUpdateItem(jobProcessItem);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryService(org.talend.repository.model.IRepositoryService) IJobletProviderService(org.talend.core.ui.IJobletProviderService) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) SetupProcessDependenciesRoutinesDialog(org.talend.designer.core.ui.routine.SetupProcessDependenciesRoutinesDialog) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ISelection(org.eclipse.jface.viewers.ISelection) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)251 PersistenceException (org.talend.commons.exception.PersistenceException)154 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)96 Item (org.talend.core.model.properties.Item)67 Property (org.talend.core.model.properties.Property)58 ArrayList (java.util.ArrayList)42 ConnectionItem (org.talend.core.model.properties.ConnectionItem)34 RepositoryNode (org.talend.repository.model.RepositoryNode)32 ProcessItem (org.talend.core.model.properties.ProcessItem)29 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)28 CoreException (org.eclipse.core.runtime.CoreException)23 LoginException (org.talend.commons.exception.LoginException)22 IRepositoryService (org.talend.repository.model.IRepositoryService)22 ERepositoryStatus (org.talend.commons.runtime.model.repository.ERepositoryStatus)21 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)21 IElementParameter (org.talend.core.model.process.IElementParameter)21 Connection (org.talend.core.model.metadata.builder.connection.Connection)20 List (java.util.List)18 IFile (org.eclipse.core.resources.IFile)18 Project (org.talend.core.model.general.Project)18