Search in sources :

Example 11 with FolderItem

use of org.talend.core.model.properties.FolderItem in project tdq-studio-se by Talend.

the class RecycleBinRepNode method getFolderContentType.

private ERepositoryObjectType getFolderContentType(FolderItem folderItem) {
    if (!folderItem.getType().equals(FolderType.SYSTEM_FOLDER_LITERAL)) {
        if (!(folderItem.getParent() instanceof FolderItem)) {
            // appears only for a folder for expression builder !
            return null;
        }
        return getFolderContentType((FolderItem) folderItem.getParent());
    }
    for (ERepositoryObjectType objectType : (ERepositoryObjectType[]) ERepositoryObjectType.values()) {
        String folderName;
        try {
            folderName = ERepositoryObjectType.getFolderName(objectType);
        } catch (Exception e) {
            // just catch exception to avoid the types who don't have folders
            continue;
        }
        if (folderName.contains("/")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String[] folders = folderName.split("/");
            FolderItem currentFolderItem = folderItem;
            boolean found = true;
            for (int i = folders.length - 1; i >= 0; i--) {
                if (!currentFolderItem.getProperty().getLabel().equals(folders[i])) {
                    found = false;
                    break;
                }
                if (i > 0) {
                    if (!(currentFolderItem.getParent() instanceof FolderItem)) {
                        found = false;
                        break;
                    }
                    currentFolderItem = (FolderItem) currentFolderItem.getParent();
                }
            }
            if (found) {
                return objectType;
            }
        } else {
            if (folderName.equals(folderItem.getProperty().getLabel())) {
                return objectType;
            }
        }
    }
    if (folderItem.getParent() instanceof FolderItem) {
        return getFolderContentType((FolderItem) folderItem.getParent());
    }
    return null;
}
Also used : FolderItem(org.talend.core.model.properties.FolderItem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 12 with FolderItem

use of org.talend.core.model.properties.FolderItem in project tdq-studio-se by Talend.

the class DQStructureManager method copyFilesToFolder.

/**
 * DOC klliu Comment method "copyFilesToFolder".
 *
 * @param plugin
 * @param srcPath
 * @param recurse
 * @param desFolder
 * @param suffix
 * @param type
 * @throws IOException
 * @throws CoreException
 */
public void copyFilesToFolder(Plugin plugin, String srcPath, boolean recurse, Folder desFolder, String suffix, ERepositoryObjectType type) throws IOException, CoreException {
    if (plugin == null) {
        return;
    }
    IProject project = ResourceManager.getRootProject();
    Enumeration<?> paths = null;
    paths = plugin.getBundle().getEntryPaths(srcPath);
    if (paths == null) {
        return;
    }
    while (paths.hasMoreElements()) {
        String nextElement = (String) paths.nextElement();
        // $NON-NLS-1$
        String currentPath = "/" + nextElement;
        URL resourceURL = plugin.getBundle().getEntry(currentPath);
        URL fileURL = null;
        File file = null;
        try {
            fileURL = FileLocator.toFileURL(resourceURL);
            file = new File(fileURL.getFile());
            if (file.isDirectory() && recurse) {
                if (file.getName().startsWith(".")) {
                    // $NON-NLS-1$
                    continue;
                }
                Folder sourcefolder = null;
                IFolder targetfolder = WorkbenchUtils.folder2IFolder(desFolder);
                if (!targetfolder.getFolder(file.getName()).exists()) {
                    sourcefolder = ProxyRepositoryFactory.getInstance().createFolder(type, Path.EMPTY, file.getName());
                } else {
                    FolderItem folderItem = ProxyRepositoryFactory.getInstance().getFolderItem(ProjectManager.getInstance().getCurrentProject(), type, new Path(file.getName()));
                    if (folderItem == null) {
                        sourcefolder = ProxyRepositoryFactory.getInstance().createFolder(type, Path.EMPTY, file.getName());
                        // $NON-NLS-1$
                        String subSourceFolder = type.getFolder().concat("/").concat(file.getName());
                        sourcefolder.getProperty().getItem().getState().setPath(subSourceFolder);
                    } else {
                        // $NON-NLS-1$
                        String subSourceFolder = type.getFolder().concat("/").concat(file.getName());
                        sourcefolder = new Folder(folderItem.getProperty(), type);
                        sourcefolder.getProperty().getItem().getState().setPath(subSourceFolder);
                    }
                }
                copyFilesToFolder(plugin, currentPath, recurse, sourcefolder, suffix, type);
                continue;
            }
            if (suffix != null && !file.getName().endsWith(suffix)) {
                continue;
            }
            String fileName = new Path(fileURL.getPath()).lastSegment();
            InputStream openStream = fileURL.openStream();
            String folderName = null;
            if (type.equals(ERepositoryObjectType.TDQ_PATTERN_ELEMENT)) {
                folderName = ERepositoryObjectType.getFolderName(type);
            }
            if (type.equals(ERepositoryObjectType.TDQ_RULES_SQL) || type.equals(ERepositoryObjectType.TDQ_RULES_PARSER)) {
                folderName = ERepositoryObjectType.getFolderName(type);
            } else if (type.equals(ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT)) {
                folderName = ERepositoryObjectType.getFolderName(type);
            } else {
                // $NON-NLS-1$
                folderName = ERepositoryObjectType.getFolderName(type) + "/" + desFolder.getLabel();
            }
            if (folderName.equals("date")) {
                // $NON-NLS-1$
                continue;
            }
            IFolder folder = project.getFolder(folderName);
            if (type.equals(ERepositoryObjectType.TDQ_SOURCE_FILE_ELEMENT)) {
                String name = file.getName();
                // $NON-NLS-1$
                int indexOf = name.indexOf(".");
                String label = name.substring(0, indexOf);
                String extendtion = name.substring(indexOf + 1);
                createSourceFileItem(file, Path.EMPTY, label, extendtion);
            } else {
                copyFileToFolder(openStream, fileName, folder);
            }
            openStream.close();
        } catch (IOException e) {
            log.error(e, e);
        } catch (PersistenceException e) {
            log.error(e, e);
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) InputStream(java.io.InputStream) IOException(java.io.IOException) Folder(org.talend.core.model.repository.Folder) IFolder(org.eclipse.core.resources.IFolder) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) FolderItem(org.talend.core.model.properties.FolderItem) PersistenceException(org.talend.commons.exception.PersistenceException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 13 with FolderItem

use of org.talend.core.model.properties.FolderItem in project tdq-studio-se by Talend.

the class WorkspaceResourceHelper method computeFileFromPlugin.

/**
 * DOC bZhou Comment method "computeFileFromPlugin".
 *
 * @param plugin
 * @param srcPath
 * @param recurse
 * @param desFolder
 * @param suffix
 * @param type
 * @param resultMap
 * @throws Exception
 */
public static void computeFileFromPlugin(Plugin plugin, String srcPath, boolean recurse, Folder desFolder, Set<String> suffix, ERepositoryObjectType type, Map<File, IPath> resultMap) throws Exception {
    if (plugin == null || srcPath == null) {
        return;
    }
    IProject project = ResourceManager.getRootProject();
    Enumeration<String> paths = plugin.getBundle().getEntryPaths(srcPath);
    while (paths != null && paths.hasMoreElements()) {
        String nextElement = paths.nextElement();
        // $NON-NLS-1$
        String currentPath = "/" + nextElement;
        URL resourceURL = plugin.getBundle().getEntry(currentPath);
        URL fileURL = null;
        File file = null;
        fileURL = FileLocator.toFileURL(resourceURL);
        file = new File(fileURL.getFile());
        String fileName = file.getName();
        if (file.isDirectory() && recurse) {
            if (fileName.startsWith(".")) {
                // $NON-NLS-1$
                continue;
            }
            Folder folder = null;
            if (!project.getFolder(fileName).exists()) {
                folder = ProxyRepositoryFactory.getInstance().createFolder(type, Path.EMPTY, fileName);
            } else {
                IPath fullPath = new Path(file.getPath());
                int count = fullPath.segmentCount();
                FolderItem folderItem = ProxyRepositoryFactory.getInstance().getFolderItem(ProjectManager.getInstance().getCurrentProject(), type, fullPath.removeFirstSegments(count - 1));
                if (folderItem == null) {
                    folder = ProxyRepositoryFactory.getInstance().createFolder(type, Path.EMPTY, fileName);
                } else {
                    folder = new Folder(folderItem.getProperty(), type);
                }
            }
            computeFileFromPlugin(plugin, currentPath, recurse, folder, suffix, type, resultMap);
            continue;
        }
        // MOD msjian TDQ-4608 2012-3-6: deal with the *.jasper file
        if (suffix != null && !suffix.contains(FileUtils.getExtension(file))) {
            continue;
        }
        String folderName = null;
        folderName = file.getParentFile().getName();
        // TDQ-4608 ~
        IFolder folder = project.getFolder(folderName);
        int segmentCount = folder.getFullPath().segmentCount();
        IPath parentPath = folder.getFullPath().removeFirstSegments(segmentCount - 1);
        resultMap.put(file, parentPath);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) FolderItem(org.talend.core.model.properties.FolderItem) IPath(org.eclipse.core.runtime.IPath) IFolder(org.eclipse.core.resources.IFolder) Folder(org.talend.core.model.repository.Folder) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with FolderItem

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

the class DatabaseTypeFilter method isSupportNode.

private boolean isSupportNode(IRepositoryNode node, String[] items) {
    if (filterItems == null) {
        return true;
    }
    List<String> asList = Arrays.asList(items);
    if (node.getObject() == null) {
        if (node.getType() == ENodeType.REFERENCED_PROJECT || node.getType() == ENodeType.SYSTEM_FOLDER) {
            return true;
        }
        if (node.getContentType() != null && node.getContentType().equals(ERepositoryObjectType.METADATA)) {
            return true;
        }
    } else {
        Item item = node.getObject().getProperty().getItem();
        if (item instanceof DatabaseConnectionItem) {
            DatabaseConnectionItem connItem = (DatabaseConnectionItem) item;
            DatabaseConnection connection = (DatabaseConnection) connItem.getConnection();
            if (connection != null) {
                String databaseType = connection.getDatabaseType();
                if (databaseType.equals(EDatabaseTypeName.ORACLEFORSID.getDisplayName())) {
                    databaseType = EDatabaseTypeName.ORACLEFORSID.getXmlName();
                } else if (databaseType.equals(EDatabaseTypeName.ORACLESN.getDisplayName())) {
                    databaseType = EDatabaseTypeName.ORACLESN.getXmlName();
                } else if (databaseType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName())) {
                    databaseType = EDatabaseTypeName.ORACLE_OCI.getXmlName();
                } else if (databaseType.equals(EDatabaseTypeName.MSSQL.getDisplayName())) {
                    // for component
                    databaseType = EDatabaseTypeName.MSSQL.getXmlName();
                } else {
                    databaseType = EDatabaseTypeName.getTypeFromDbType(databaseType).getProduct();
                }
                if (asList.contains(databaseType)) {
                    return true;
                }
            }
        } else if (item instanceof FolderItem) {
            return true;
        }
    }
    return false;
}
Also used : Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem)

Example 15 with FolderItem

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

the class JobScriptsExportWizardPage method getProcessItem.

protected ProcessItem getProcessItem() {
    if ((processItem == null) && (nodes != null) && (nodes.length >= 1)) {
        IRepositoryViewObject repositoryObject = nodes[0].getObject();
        // add for bug TDI-20132
        List<IRepositoryNode> nodesChildren = nodes[0].getChildren();
        IRepositoryViewObject childObject = null;
        if ((nodesChildren != null) && (nodesChildren.size() >= 1)) {
            childObject = nodesChildren.get(0).getObject();
        }
        if (repositoryObject == null && childObject != null && childObject.getProperty().getItem() instanceof ProcessItem) {
            processItem = (ProcessItem) childObject.getProperty().getItem();
        }
        if (repositoryObject != null && repositoryObject.getProperty().getItem() instanceof ProcessItem) {
            processItem = (ProcessItem) repositoryObject.getProperty().getItem();
        } else if (repositoryObject != null && repositoryObject.getProperty().getItem() instanceof FolderItem) {
            processItem = getProcessItemIfSelectFolder(repositoryObject);
        }
    }
    return processItem;
}
Also used : FolderItem(org.talend.core.model.properties.FolderItem) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Aggregations

FolderItem (org.talend.core.model.properties.FolderItem)31 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)12 Item (org.talend.core.model.properties.Item)11 IFolder (org.eclipse.core.resources.IFolder)10 Folder (org.talend.core.model.repository.Folder)10 Property (org.talend.core.model.properties.Property)6 ArrayList (java.util.ArrayList)5 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 PersistenceException (org.talend.commons.exception.PersistenceException)5 IFile (org.eclipse.core.resources.IFile)4 IProject (org.eclipse.core.resources.IProject)4 ConnectionItem (org.talend.core.model.properties.ConnectionItem)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4 RepositoryViewObject (org.talend.core.model.repository.RepositoryViewObject)4 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)4 URL (java.net.URL)3 EObject (org.eclipse.emf.ecore.EObject)3 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)3