Search in sources :

Example 16 with ImportItem

use of org.talend.repository.items.importexport.handlers.model.ImportItem in project tdi-studio-se by Talend.

the class TalendImportUtil method importItems.

public static boolean importItems(String zipPath, IProgressMonitor monitor, final boolean overwrite, final boolean openThem, boolean needMigrationTask) throws IOException {
    // File srcFile = new File(zipPath);
    ZipFile srcZipFile = new ZipFile(zipPath);
    final ImportExportHandlersManager importManager = new ImportExportHandlersManager();
    final ResourcesManager resourcesManager = ResourcesManagerFactory.getInstance().createResourcesManager(srcZipFile);
    // resourcesManager.collectPath2Object(srcFile);
    resourcesManager.collectPath2Object(srcZipFile);
    final List<ImportItem> items = populateItems(importManager, resourcesManager, monitor, overwrite);
    final List<String> itemIds = new ArrayList<String>();
    try {
        for (ImportItem itemRecord : items) {
            Item item = itemRecord.getProperty().getItem();
            if (item instanceof ProcessItem) {
                // only select jobs
                itemIds.add(item.getProperty().getId());
            }
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            if (item.getState().isLocked()) {
                factory.unlock(item);
            }
            ERepositoryStatus status = factory.getStatus(item);
            if (status != null && status == ERepositoryStatus.LOCK_BY_USER) {
                factory.unlock(item);
            }
            if (!needMigrationTask) {
                itemRecord.setMigrationTasksToApply(null);
            }
        }
        // nodesBuilder.getAllImportItemRecords(), null);
        if (items != null && !items.isEmpty()) {
            importManager.importItemRecords(monitor, resourcesManager, items, overwrite, nodesBuilder.getAllImportItemRecords(), null);
        }
    } catch (Exception e) {
        CommonExceptionHandler.process(e);
    } finally {
        // clean
        if (resourcesManager != null) {
            resourcesManager.closeResource();
        }
        nodesBuilder.clear();
    }
    return true;
}
Also used : ImportExportHandlersManager(org.talend.repository.items.importexport.handlers.ImportExportHandlersManager) ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) ZipFile(java.util.zip.ZipFile) ProcessItem(org.talend.core.model.properties.ProcessItem) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

ImportItem (org.talend.repository.items.importexport.handlers.model.ImportItem)16 ImportExportHandlersManager (org.talend.repository.items.importexport.handlers.ImportExportHandlersManager)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 Before (org.junit.Before)7 Item (org.talend.core.model.properties.Item)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ResourcesManager (org.talend.repository.items.importexport.manager.ResourcesManager)4 ProcessItem (org.talend.core.model.properties.ProcessItem)3 FileNotFoundException (java.io.FileNotFoundException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ZipException (java.util.zip.ZipException)2 ZipFile (java.util.zip.ZipFile)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 RoutineItem (org.talend.core.model.properties.RoutineItem)2 File (java.io.File)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1