Search in sources :

Example 6 with ResourcesManager

use of org.talend.repository.items.importexport.manager.ResourcesManager in project tdi-studio-se by Talend.

the class DemoImportTestUtil method getResourceManagers.

public static List<ResourcesManager> getResourceManagers(List<DemoProjectBean> checkedProjectBean) {
    List<ResourcesManager> resManagers = new ArrayList<ResourcesManager>();
    try {
        for (DemoProjectBean pro : checkedProjectBean) {
            ResourcesManager resManager = null;
            Bundle bundle = Platform.getBundle(pro.getPluginId());
            URL demoURL = FileLocator.find(bundle, new Path(pro.getDemoProjectFilePath()), null);
            demoURL = FileLocator.toFileURL(demoURL);
            String filePath = new Path(demoURL.getFile()).toOSString();
            File srcFile = new File(filePath);
            FileResourcesUnityManager fileUnityManager = ResourcesManagerFactory.getInstance().createFileUnityManager(srcFile);
            resManager = fileUnityManager.doUnify();
            if (resManager != null) {
                resManagers.add(resManager);
            }
        }
    } catch (ZipException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TarException e) {
        e.printStackTrace();
    }
    return resManagers;
}
Also used : Path(org.eclipse.core.runtime.Path) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileResourcesUnityManager(org.talend.repository.items.importexport.ui.managers.FileResourcesUnityManager) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) URL(java.net.URL) DemoProjectBean(org.talend.repository.ui.actions.importproject.DemoProjectBean) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) File(java.io.File)

Example 7 with ResourcesManager

use of org.talend.repository.items.importexport.manager.ResourcesManager 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

ResourcesManager (org.talend.repository.items.importexport.manager.ResourcesManager)7 IOException (java.io.IOException)6 FileNotFoundException (java.io.FileNotFoundException)5 ZipException (java.util.zip.ZipException)5 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)5 File (java.io.File)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Path (org.eclipse.core.runtime.Path)4 ImportItem (org.talend.repository.items.importexport.handlers.model.ImportItem)4 FileResourcesUnityManager (org.talend.repository.items.importexport.ui.managers.FileResourcesUnityManager)4 ZipFile (java.util.zip.ZipFile)3 Bundle (org.osgi.framework.Bundle)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Item (org.talend.core.model.properties.Item)2 ProcessItem (org.talend.core.model.properties.ProcessItem)2 ImportExportHandlersManager (org.talend.repository.items.importexport.handlers.ImportExportHandlersManager)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1