Search in sources :

Example 26 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem 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 27 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem 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 28 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class ImportItemUtil method importItemRecord.

private void importItemRecord(ResourcesManager manager, ItemRecord itemRecord, boolean overwrite, IPath destinationPath, final Set<String> overwriteDeletedItems, final Set<String> idDeletedBeforeImport, String contentType, final IProgressMonitor monitor) {
    //$NON-NLS-1$
    monitor.subTask(Messages.getString("ImportItemWizardPage.Importing") + itemRecord.getItemName());
    resolveItem(manager, itemRecord);
    if (!itemRecord.isValid()) {
        return;
    }
    int num = 0;
    for (Object obj : itemRecord.getResourceSet().getResources()) {
        if (!(obj instanceof PropertiesProjectResourceImpl)) {
            if (obj instanceof XMIResourceImpl) {
                num++;
                if (num > 2) {
                    // 2 so that metadata migration for 4.1 works
                    try {
                        throw new InvocationTargetException(new PersistenceException("The source file of " + itemRecord.getLabel() + " has error,Please check it!"));
                    } catch (InvocationTargetException e) {
                        ExceptionHandler.process(e);
                    }
                    return;
                }
            }
        }
    }
    final Item item = itemRecord.getItem();
    if (item != null) {
        ProxyRepositoryFactory repFactory = ProxyRepositoryFactory.getInstance();
        ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
        IPath path = new Path(item.getState().getPath());
        if (destinationPath != null && itemType.name().equals(contentType)) {
            path = destinationPath.append(path);
        }
        try {
            FolderItem folderItem = repFactory.getFolderItem(ProjectManager.getInstance().getCurrentProject(), itemType, path);
            if (folderItem == null) {
                // if this folder does not exists (and it's parents), it will check if the folder was originally
                // deleted in source project.
                // if yes, it will set back the delete status to the folder, to keep the same as the original
                // project when import.
                // Without this code, deleted folders of items imported will not be in the recycle bin after import.
                // delete status is set finally in the function checkDeletedFolders
                IPath curPath = path;
                EList deletedFoldersFromOriginalProject = itemRecord.getItemProject().getDeletedFolders();
                while (folderItem == null && !curPath.isEmpty() && !curPath.isRoot()) {
                    if (deletedFoldersFromOriginalProject.contains(new Path(itemType.getFolder()).append(curPath.toPortableString()).toPortableString())) {
                        if (!foldersCreated.containsKey(itemType)) {
                            foldersCreated.put(itemType, new HashSet<String>());
                        }
                        foldersCreated.get(itemType).add(curPath.toPortableString());
                    }
                    if (curPath.segments().length > 0) {
                        curPath = curPath.removeLastSegments(1);
                        folderItem = repFactory.getFolderItem(ProjectManager.getInstance().getCurrentProject(), itemType, curPath);
                    }
                }
            }
            repFactory.createParentFoldersRecursively(ProjectManager.getInstance().getCurrentProject(), itemType, path, true);
        } catch (Exception e) {
            logError(e);
            //$NON-NLS-1$
            path = new Path("");
        }
        try {
            Item tmpItem = item;
            // delete existing items before importing, this should be done
            // once for a different id
            String id = itemRecord.getProperty().getId();
            IRepositoryViewObject lastVersion = itemRecord.getExistingItemWithSameId();
            if (lastVersion != null && overwrite && !itemRecord.isLocked() && (itemRecord.getState() == State.ID_EXISTED || itemRecord.getState() == State.NAME_EXISTED || itemRecord.getState() == State.NAME_AND_ID_EXISTED) && !deletedItems.contains(id)) {
                if (!overwriteDeletedItems.contains(id)) {
                    // bug 10520.
                    ERepositoryStatus status = repFactory.getStatus(lastVersion);
                    if (status == ERepositoryStatus.DELETED) {
                        // restore first.
                        repFactory.restoreObject(lastVersion, path);
                    }
                    overwriteDeletedItems.add(id);
                }
                /* only delete when name exsit rather than id exist */
                if (itemRecord.getState().equals(ItemRecord.State.NAME_EXISTED) || itemRecord.getState().equals(ItemRecord.State.NAME_AND_ID_EXISTED)) {
                    if (!idDeletedBeforeImport.contains(id)) {
                        // TDI-19535 (check if exists, delete all items with same id)
                        List<IRepositoryViewObject> allVersionToDelete = repFactory.getAllVersion(ProjectManager.getInstance().getCurrentProject(), lastVersion.getId(), false);
                        String importingLabel = itemRecord.getProperty().getLabel();
                        String existLabel = lastVersion.getProperty().getLabel();
                        for (IRepositoryViewObject currentVersion : allVersionToDelete) {
                            repFactory.forceDeleteObjectPhysical(lastVersion, currentVersion.getVersion(), isNeedDeleteOnRemote(importingLabel, existLabel));
                        }
                        idDeletedBeforeImport.add(id);
                    }
                }
                lastVersion = null;
            // List<IRepositoryObject> list = cache.findObjectsByItem(itemRecord);
            // if (!list.isEmpty()) {
            // // this code will delete all version of item with same
            // // id
            // repFactory.forceDeleteObjectPhysical(list.get(0));
            // deletedItems.add(id);
            // }
            }
            User author = itemRecord.getProperty().getAuthor();
            if (author != null) {
                if (!repFactory.setAuthorByLogin(tmpItem, author.getLogin())) {
                    // author will be
                    tmpItem.getProperty().setAuthor(null);
                // the logged
                // user in
                // create method
                }
            }
            if (item instanceof JobletProcessItem) {
                hasJoblets = true;
            }
            if (tmpItem instanceof ProcessItem && !statAndLogsSettingsReloaded && !implicitSettingsReloaded) {
                ProcessItem processItem = (ProcessItem) tmpItem;
                ParametersType paType = processItem.getProcess().getParameters();
                boolean statsPSettingRemoved = false;
                // for commanline import project setting
                if (itemRecord.isRemoveProjectStatslog()) {
                    if (paType != null) {
                        String paramName = "STATANDLOG_USE_PROJECT_SETTINGS";
                        EList listParamType = paType.getElementParameter();
                        for (int j = 0; j < listParamType.size(); j++) {
                            ElementParameterType pType = (ElementParameterType) listParamType.get(j);
                            if (pType != null && paramName.equals(pType.getName())) {
                                pType.setValue(Boolean.FALSE.toString());
                                statsPSettingRemoved = true;
                                break;
                            }
                        }
                    }
                }
                // 14446: item apply project setting param if use project setting
                String statslogUsePSetting = null;
                String implicitUsePSetting = null;
                if (paType != null) {
                    EList listParamType = paType.getElementParameter();
                    for (int j = 0; j < listParamType.size(); j++) {
                        ElementParameterType pType = (ElementParameterType) listParamType.get(j);
                        if (pType != null) {
                            if (!statsPSettingRemoved && "STATANDLOG_USE_PROJECT_SETTINGS".equals(pType.getName())) {
                                statslogUsePSetting = pType.getValue();
                            }
                            if ("IMPLICITCONTEXT_USE_PROJECT_SETTINGS".equals(pType.getName())) {
                                implicitUsePSetting = pType.getValue();
                            }
                            if (statsPSettingRemoved && implicitUsePSetting != null || !statsPSettingRemoved && implicitUsePSetting != null && statslogUsePSetting != null) {
                                break;
                            }
                        }
                    }
                }
                if (statslogUsePSetting != null && Boolean.parseBoolean(statslogUsePSetting) && !statAndLogsSettingsReloaded) {
                    CorePlugin.getDefault().getDesignerCoreService().reloadParamFromProjectSettings(paType, "STATANDLOG_USE_PROJECT_SETTINGS");
                    statAndLogsSettingsReloaded = true;
                }
                if (implicitUsePSetting != null && Boolean.parseBoolean(implicitUsePSetting) && !implicitSettingsReloaded) {
                    CorePlugin.getDefault().getDesignerCoreService().reloadParamFromProjectSettings(paType, "IMPLICITCONTEXT_USE_PROJECT_SETTINGS");
                    implicitSettingsReloaded = true;
                }
            }
            if (lastVersion == null || itemRecord.getState().equals(ItemRecord.State.ID_EXISTED)) {
                // import has not been developed to cope with migration in mind
                // so some model may not be able to load like the ConnectionItems
                // in that case items needs to be copied before migration
                // here we check that the loading of the item failed before calling the create method
                boolean isConnectionEmptyBeforeMigration = tmpItem instanceof ConnectionItem && ((ConnectionItem) tmpItem).getConnection().eResource() == null && !itemRecord.getMigrationTasksToApply().isEmpty();
                repFactory.create(tmpItem, path, true);
                if (isConnectionEmptyBeforeMigration) {
                    // copy the file before migration, this is bad because it
                    // should not refer to Filesytem
                    // but this is a quick hack and anyway the migration task only works on files
                    // IPath itemPath = itemRecord.getPath().removeFileExtension().addFileExtension(
                    // FileConstants.ITEM_EXTENSION);
                    InputStream is = manager.getStream(itemRecord.getPath().removeFileExtension().addFileExtension(FileConstants.ITEM_EXTENSION));
                    try {
                        URI propertyResourceURI = EcoreUtil.getURI(((ConnectionItem) tmpItem).getProperty());
                        URI relativePlateformDestUri = propertyResourceURI.trimFileExtension().appendFileExtension(FileConstants.ITEM_EXTENSION);
                        URL fileURL = FileLocator.toFileURL(new java.net.URL(//$NON-NLS-1$
                        "platform:/resource" + relativePlateformDestUri.toPlatformString(true)));
                        OutputStream os = new FileOutputStream(fileURL.getFile());
                        try {
                            FileCopyUtils.copyStreams(is, os);
                        } finally {
                            os.close();
                        }
                    } finally {
                        is.close();
                    }
                    repFactory.unloadResources(tmpItem.getProperty());
                } else {
                    // connections from migrations (from 4.0.x or previous version) doesn't support reference or
                    // screenshots
                    // so no need to call this code.
                    // It's needed to avoid to call the save method mainly just before or after the copy of the old
                    // connection since it will
                    copyScreenshotFile(manager, itemRecord);
                    boolean haveRef = copyReferenceFiles(manager, tmpItem, itemRecord.getPath());
                    if (haveRef) {
                        repFactory.save(tmpItem, true);
                    }
                }
                itemRecord.setImportPath(path.toPortableString());
                itemRecord.setRepositoryType(itemType);
                itemRecord.setItemId(itemRecord.getProperty().getId());
                itemRecord.setItemVersion(itemRecord.getProperty().getVersion());
                itemRecord.setImported(true);
                cache.addToCache(tmpItem);
            } else if (VersionUtils.compareTo(lastVersion.getProperty().getVersion(), tmpItem.getProperty().getVersion()) < 0) {
                repFactory.forceCreate(tmpItem, path);
                itemRecord.setImportPath(path.toPortableString());
                itemRecord.setItemId(itemRecord.getProperty().getId());
                itemRecord.setRepositoryType(itemType);
                itemRecord.setItemVersion(itemRecord.getProperty().getVersion());
                itemRecord.setImported(true);
                cache.addToCache(tmpItem);
            } else {
                PersistenceException e = new PersistenceException(Messages.getString("ImportItemUtil.persistenceException", //$NON-NLS-1$
                tmpItem.getProperty()));
                itemRecord.addError(e.getMessage());
                logError(e);
            }
            if (tmpItem != null) {
                // RelationshipItemBuilder.getInstance().addOrUpdateItem(tmpItem, true);
                if (tmpItem.getState() != null) {
                    if (itemType != null) {
                        final Set<String> folders = restoreFolder.getFolders(itemType);
                        if (folders != null) {
                            for (String folderPath : folders) {
                                if (folderPath != null && folderPath.equals(path.toString())) {
                                    FolderItem folderItem = repFactory.getFolderItem(ProjectManager.getInstance().getCurrentProject(), itemType, path);
                                    if (folderItem != null) {
                                        folderItem.getState().setDeleted(false);
                                        while (!(folderItem.getParent() instanceof Project)) {
                                            folderItem = (FolderItem) folderItem.getParent();
                                            if (folderItem.getType() == FolderType.SYSTEM_FOLDER_LITERAL) {
                                                break;
                                            }
                                            folderItem.getState().setDeleted(false);
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            itemRecord.addError(e.getMessage());
            logError(e);
        }
    }
    String label = itemRecord.getLabel();
    EList<Resource> resources = itemRecord.getResourceSet().getResources();
    Iterator<Resource> iterator = resources.iterator();
    while (iterator.hasNext()) {
        Resource res = iterator.next();
        // it can't be unloaded just after create the item.
        if (res != null && !(res instanceof ByteArrayResource)) {
            res.unload();
            iterator.remove();
        }
    }
    TimeMeasure.step("importItemRecords", "Import item: " + label);
    applyMigrationTasks(itemRecord, monitor);
    TimeMeasure.step("importItemRecords", "applyMigrationTasks: " + label);
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) User(org.talend.core.model.properties.User) ConnectionItem(org.talend.core.model.properties.ConnectionItem) URL(java.net.URL) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) URI(org.eclipse.emf.common.util.URI) PropertiesProjectResourceImpl(org.talend.core.repository.model.PropertiesProjectResourceImpl) URL(java.net.URL) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) SnippetItem(org.talend.core.model.properties.SnippetItem) Item(org.talend.core.model.properties.Item) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) FolderItem(org.talend.core.model.properties.FolderItem) RoutineItem(org.talend.core.model.properties.RoutineItem) TDQItem(org.talend.core.model.properties.TDQItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileItem(org.talend.core.model.properties.FileItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CwmResource(org.talend.model.emf.CwmResource) TalendXMIResource(org.talend.commons.runtime.model.emf.TalendXMIResource) ByteArrayResource(org.talend.core.model.properties.helper.ByteArrayResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayResource(org.talend.core.model.properties.helper.ByteArrayResource) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Project(org.talend.core.model.properties.Project) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) FolderItem(org.talend.core.model.properties.FolderItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileOutputStream(java.io.FileOutputStream) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType) XMIResourceImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)

Example 29 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class ImportItemUtil method resetItemReference.

/**
     * 
     * cLi Comment method "resetItemReference".
     * 
     * resolve the encode some special character(bug 6252), maybe, It's not better to resolve this by manually.
     * 
     * such as, "[" is "%5B", "]" is "%5D", etc.
     */
@SuppressWarnings("unchecked")
private void resetItemReference(ItemRecord itemRecord, Resource resource) {
    Item item = itemRecord.getItem();
    EList<EObject> contents = resource.getContents();
    /*
         * ignore job. no need, because it can't be allowed input special char for name.
         */
    if (item instanceof ProcessItem) {
    // ((ProcessItem) item).setProcess((ProcessType) EcoreUtil.getObjectByType(contents,
    // TalendFilePackage.eINSTANCE
    // .getProcessType()));
    } else /*
         * ignore joblet. no need, because it can't be allowed input special char for name.
         */
    if (item instanceof JobletProcessItem) {
    // JobletProcessItem jobletProcessItem = (JobletProcessItem) item;
    //
    // jobletProcessItem.setJobletProcess((JobletProcess) EcoreUtil.getObjectByType(contents,
    // JobletPackage.eINSTANCE
    // .getJobletProcess()));
    // jobletProcessItem
    // .setIcon((ByteArray) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getByteArray()));
    } else // connectionItem
    if (item instanceof ConnectionItem) {
        ((ConnectionItem) item).setConnection((Connection) EcoreUtil.getObjectByType(contents, ConnectionPackage.eINSTANCE.getConnection()));
    } else // context
    if (item instanceof ContextItem) {
        EList contexts = ((ContextItem) item).getContext();
        contexts.clear();
        contexts.addAll(EcoreUtil.getObjectsByType(contents, TalendFilePackage.eINSTANCE.getContextType()));
    } else // file
    if (item instanceof FileItem) {
        /*
             * ignore routine, no need, because it can't be allowed input special char for name.
             */
        if (item instanceof RoutineItem) {
            return;
        }
        FileItem fileItem = (FileItem) item;
        fileItem.setContent((ByteArray) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getByteArray()));
    } else // snippet
    if (item instanceof SnippetItem) {
        EList variables = ((SnippetItem) item).getVariables();
        variables.clear();
        variables.addAll(EcoreUtil.getObjectsByType(contents, PropertiesPackage.eINSTANCE.getSnippetVariable()));
    } else // link doc
    if (item instanceof LinkDocumentationItem) {
        ((LinkDocumentationItem) item).setLink((LinkType) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getLinkType()));
    } else // business
    if (item instanceof BusinessProcessItem) {
        BusinessProcessItem businessProcessItem = (BusinessProcessItem) item;
        businessProcessItem.setSemantic((BusinessProcess) EcoreUtil.getObjectByType(contents, BusinessPackage.eINSTANCE.getBusinessProcess()));
        businessProcessItem.setNotationHolder((NotationHolder) EcoreUtil.getObjectByType(contents, PropertiesPackage.eINSTANCE.getNotationHolder()));
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) RoutineItem(org.talend.core.model.properties.RoutineItem) NotationHolder(org.talend.core.model.properties.NotationHolder) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) SnippetItem(org.talend.core.model.properties.SnippetItem) Item(org.talend.core.model.properties.Item) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) FolderItem(org.talend.core.model.properties.FolderItem) RoutineItem(org.talend.core.model.properties.RoutineItem) TDQItem(org.talend.core.model.properties.TDQItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileItem(org.talend.core.model.properties.FileItem) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) FileItem(org.talend.core.model.properties.FileItem) SnippetItem(org.talend.core.model.properties.SnippetItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) BusinessProcess(org.talend.designer.business.model.business.BusinessProcess)

Example 30 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class ComponentChooseDialog method createSchema.

/**
     * DOC bqian Comment method "createSchema".
     *
     * @param firstElement
     * @param targetEditPart
     */
private void createSchema(Object dragModel, EditPart targetEditPart) {
    if (!(dragModel instanceof RepositoryNode && targetEditPart instanceof NodeContainerPart)) {
        return;
    }
    RepositoryNode dragNode = (RepositoryNode) dragModel;
    NodeContainerPart nodePart = (NodeContainerPart) targetEditPart;
    Node node = (Node) nodePart.getNodePart().getModel();
    IRepositoryViewObject object = dragNode.getObject();
    if (dragNode.getObject().getProperty().getItem() instanceof ConnectionItem) {
        CompoundCommand cc = new CompoundCommand();
        boolean isValRulesLost = false;
        if (dragNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE) {
            IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(node);
            if (currentValRuleObj != null) {
                //$NON-NLS-1$
                String schema = object.getProperty().getId() + " - " + object.getLabel();
                List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(schema);
                if (!ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, currentValRuleObj)) {
                    if (!MessageDialog.openConfirm(editor.getSite().getShell(), //$NON-NLS-1$
                    Messages.getString("SchemaTypeController.validationrule.title.confirm"), Messages.getString("SchemaTypeController.validationrule.selectMetadataMsg"))) {
                        //$NON-NLS-1$
                        isValRulesLost = false;
                        return;
                    } else {
                        isValRulesLost = true;
                    }
                }
            }
        }
        ConnectionItem connectionItem = (ConnectionItem) dragNode.getObject().getProperty().getItem();
        getChangeMetadataCommand(cc, dragNode, node, connectionItem);
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, node);
        }
        if (cc.getCommands().size() > 0) {
            execCommandStack(cc);
        }
    }
}
Also used : NodeContainerPart(org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) MapperExternalNode(org.talend.core.model.process.node.MapperExternalNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

ConnectionItem (org.talend.core.model.properties.ConnectionItem)79 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)44 PersistenceException (org.talend.commons.exception.PersistenceException)38 Connection (org.talend.core.model.metadata.builder.connection.Connection)38 IElementParameter (org.talend.core.model.process.IElementParameter)38 Item (org.talend.core.model.properties.Item)34 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)31 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)27 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)20 ArrayList (java.util.ArrayList)19 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)19 Property (org.talend.core.model.properties.Property)17 ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)17 RepositoryNode (org.talend.repository.model.RepositoryNode)17 INode (org.talend.core.model.process.INode)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 List (java.util.List)14 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)13 ProcessItem (org.talend.core.model.properties.ProcessItem)12