Search in sources :

Example 1 with TarFileExporterFullPath

use of org.talend.core.ui.export.TarFileExporterFullPath in project tdi-studio-se by Talend.

the class ExportItemUtil method exportItems.

public void exportItems(File destination, final Collection<Item> items, List<String> folders, boolean exportAllVersions, IProgressMonitor progressMonitor) throws Exception {
    // bug 11301 :export 0 items
    Collection<Item> workItems = items;
    if (workItems == null) {
        workItems = new ArrayList<Item>();
    }
    Collection<Item> otherVersions = new ArrayList<Item>();
    // get all versions of the exported items if wanted
    if (exportAllVersions) {
        otherVersions = getOtherVersions(workItems);
        workItems.addAll(otherVersions);
        otherVersions.clear();
    }
    // else keep current items version only
    try {
        File tmpDirectory = null;
        Map<File, IPath> toExport;
        // TDI-27660:if not give the path of export file,get its default parent path.
        File parentDesFile = checkAndGetDesParentFile(destination);
        if (destination.getName().endsWith(FileConstants.TAR_FILE_SUFFIX)) {
            createFolder(parentDesFile);
            exporter = new TarFileExporterFullPath(destination.getAbsolutePath(), false);
        } else if (destination.getName().endsWith(FileConstants.TAR_GZ_FILE_SUFFIX)) {
            createFolder(parentDesFile);
            exporter = new TarFileExporterFullPath(destination.getAbsolutePath(), true);
        } else if (destination.getName().endsWith(FileConstants.ZIP_FILE_SUFFIX)) {
            createFolder(parentDesFile);
            exporter = new ZipFileExporterFullPath(destination.getAbsolutePath(), true);
        } else {
            createFolder(destination);
        }
        if (exporter != null) {
            tmpDirectory = createTmpDirectory();
        }
        try {
            if (exporter != null) {
                toExport = exportItems2(workItems, tmpDirectory, true, progressMonitor);
                // IPath rootPath = new Path(destination.getName()).removeFileExtension().removeFileExtension();
                for (File file : toExport.keySet()) {
                    IPath path = toExport.get(file);
                    // exporter.write(file.getAbsolutePath(), rootPath.append(path).toString());
                    exporter.write(file.getAbsolutePath(), path.toString());
                }
                if (folders != null) {
                    // filter folders that already created
                    List<String> toRemove = new ArrayList<String>();
                    for (String folderPath : folders) {
                        for (IPath resourcePath : toExport.values()) {
                            if (resourcePath.toPortableString().contains(folderPath)) {
                                toRemove.add(folderPath);
                                break;
                            }
                        }
                    }
                    folders.removeAll(toRemove);
                    for (String folderPath : folders) {
                        exporter.writeFolder(folderPath);
                    }
                }
            } else {
                toExport = exportItems2(workItems, destination, true, progressMonitor);
                if (folders != null) {
                    // filter folders that already created
                    List<String> toRemove = new ArrayList<String>();
                    for (String folderPath : folders) {
                        for (IPath resourcePath : toExport.values()) {
                            if (resourcePath.toPortableString().contains(folderPath)) {
                                toRemove.add(folderPath);
                                break;
                            }
                        }
                    }
                    folders.removeAll(toRemove);
                    for (String folderPath : folders) {
                        IPath fullPath = new Path(destination.getAbsolutePath());
                        fullPath = fullPath.append(folderPath);
                        FilesUtils.createFoldersIfNotExists(fullPath.toPortableString(), false);
                    }
                }
            }
        } catch (Exception e) {
            throw e;
        } finally {
            if (exporter != null) {
                deleteTmpDirectory(tmpDirectory);
            }
        }
    } finally {
        if (exporter != null) {
            try {
                exporter.finished();
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
}
Also used : TarFileExporterFullPath(org.talend.core.ui.export.TarFileExporterFullPath) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ZipFileExporterFullPath(org.talend.core.ui.export.ZipFileExporterFullPath) IFileExporterFullPath(org.talend.core.ui.export.IFileExporterFullPath) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) RoutineItem(org.talend.core.model.properties.RoutineItem) TarFileExporterFullPath(org.talend.core.ui.export.TarFileExporterFullPath) ZipFileExporterFullPath(org.talend.core.ui.export.ZipFileExporterFullPath) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 Item (org.talend.core.model.properties.Item)1 RoutineItem (org.talend.core.model.properties.RoutineItem)1 IFileExporterFullPath (org.talend.core.ui.export.IFileExporterFullPath)1 TarFileExporterFullPath (org.talend.core.ui.export.TarFileExporterFullPath)1 ZipFileExporterFullPath (org.talend.core.ui.export.ZipFileExporterFullPath)1