Search in sources :

Example 1 with ResourcesManager

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

the class ImportDemoProjectItemsPage method populateExistItemRecords.

private String populateExistItemRecords(final List<ResourcesManager> manager) {
    //$NON-NLS-1$
    String messageInfo = "";
    final Collection<ImportItem> items = new ArrayList<ImportItem>();
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                for (ResourcesManager rm : manager) {
                    items.addAll(importManager.populateImportingItems(rm, true, monitor));
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    };
    try {
        new ProgressMonitorDialog(getShell()).run(true, true, op);
    } catch (Exception e) {
    // ignore me
    }
    for (ImportItem itemRecord : items) {
        if (itemRecord.getExistingItemWithSameId() != null && itemRecord.getExistingItemWithSameId() instanceof RepositoryViewObject) {
            RepositoryViewObject reObject = (RepositoryViewObject) itemRecord.getExistingItemWithSameId();
            if (itemRecord.getProperty() != null && reObject != null) {
                if (!itemRecord.getProperty().getId().equals(reObject.getId()) && itemRecord.getProperty().getLabel().equalsIgnoreCase(reObject.getLabel())) {
                    messageInfo = Messages.getString("ImportDemoProjectPage.loseItems", reObject.getLabel());
                }
                if (itemRecord.getProperty().getId().equals(reObject.getId()) && itemRecord.getProperty().getLabel().equals(reObject.getLabel())) {
                    messageInfo = Messages.getString("ImportDemoProjectPage.overwriteItems");
                }
            }
        }
    }
    return messageInfo;
}
Also used : ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) ZipException(java.util.zip.ZipException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject)

Example 2 with ResourcesManager

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

the class DemoImportTestUtil method getResourceManager.

public static ResourcesManager getResourceManager(DemoProjectBean checkedProjectBean) {
    ResourcesManager resManager = null;
    try {
        Bundle bundle = Platform.getBundle(checkedProjectBean.getPluginId());
        URL demoURL = FileLocator.find(bundle, new Path(checkedProjectBean.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();
    } catch (ZipException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TarException e) {
        e.printStackTrace();
    }
    return resManager;
}
Also used : Path(org.eclipse.core.runtime.Path) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) Bundle(org.osgi.framework.Bundle) FileNotFoundException(java.io.FileNotFoundException) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) FileResourcesUnityManager(org.talend.repository.items.importexport.ui.managers.FileResourcesUnityManager) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL)

Example 3 with ResourcesManager

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

the class BuildJobHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    // Fix the NPE for org.talend.designer.core.ui.editor.process.Process.createMainParameters(Process.java:401)
    bridgeProject = ReponsitoryContextBridge.getProject();
    ReponsitoryContextBridge.setProject(ProjectManager.getInstance().getCurrentProject().getEmfProject());
    ImportExportHandlersManager importManager = new ImportExportHandlersManager();
    // job with tdm and tdq component.
    URL testJobURL = FileLocator.find(Platform.getBundle("org.talend.repository.test"), new Path("/resources/testBuildJob.zip"), null);
    if (testJobURL != null) {
        testJobURL = FileLocator.toFileURL(testJobURL);
    }
    File srcFile = new File(testJobURL.getFile());
    FileResourcesUnityManager fileUnityManager = ResourcesManagerFactory.getInstance().createFileUnityManager(srcFile);
    ResourcesManager resManager = fileUnityManager.doUnify();
    List<ImportItem> projectRecords = importManager.populateImportingItems(resManager, true, new NullProgressMonitor());
    assertTrue(projectRecords.size() > 0);
    importManager.importItemRecords(new NullProgressMonitor(), resManager, projectRecords, true, projectRecords.toArray(new ImportItem[0]), null);
    IRepositoryViewObject obj = ProxyRepositoryFactory.getInstance().getLastVersion("_bWyBUAYbEeapTZ0aKwL_YA");
    Item item = obj.getProperty().getItem();
    assertTrue(item instanceof ProcessItem);
    processItem = (ProcessItem) item;
}
Also used : ImportExportHandlersManager(org.talend.repository.items.importexport.handlers.ImportExportHandlersManager) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) FileResourcesUnityManager(org.talend.repository.items.importexport.ui.managers.FileResourcesUnityManager) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL) Before(org.junit.Before)

Example 4 with ResourcesManager

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

the class ImportDemoProjectItemsPage method performFinish.

public boolean performFinish() {
    List<DemoProjectBean> checkedElements = getCheckedElements();
    final List<ResourcesManager> finalCheckManagers = getResourceManagers(checkedElements);
    String warnMessage = populateExistItemRecords(finalCheckManagers);
    if (!warnMessage.equals("")) {
        MessageDialog dialog = new MessageDialog(getShell(), Messages.getString("ImportDemoProjectPage.overwrite"), null, warnMessage, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
        dialog.open();
        int result = dialog.getReturnCode();
        if (result != MessageDialog.OK) {
            return false;
        }
    }
    ProgressDialog progressDialog = new ProgressDialog(getShell()) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitorWrap = new EventLoopProgressMonitor(monitor);
            try {
                for (ResourcesManager resManager : finalCheckManagers) {
                    List<ImportItem> projectRecords = importManager.populateImportingItems(resManager, true, monitorWrap);
                    // clearOverWriteErrorMessages(projectRecords, overwrite);
                    importManager.importItemRecords(monitorWrap, resManager, projectRecords, true, projectRecords.toArray(new ImportItem[0]), null);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
            monitorWrap.done();
            if (monitor.isCanceled()) {
                MessageDialog.openInformation(getShell(), Messages.getString("ImportDemoProjectAction.messageDialogTitle.demoProjectCancel"), Messages.getString("ImportDemoProjectAction.messageDialogContent.demoProjectImportedIncompletely"));
                return;
            } else {
                MessageDialog.openInformation(getShell(), //$NON-NLS-1$
                Messages.getString("ImportDemoProjectAction.messageDialogTitle.demoProject"), //$NON-NLS-1$
                Messages.getString("ImportDemoProjectAction.messageDialogContent.demoProjectImportedSuccessfully"));
            }
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
    } catch (InterruptedException e) {
    // Nothing to do
    }
    return true;
}
Also used : ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) ZipException(java.util.zip.ZipException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 5 with ResourcesManager

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

the class ImportDemoProjectItemsPage method getResourceManagers.

private 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);
            // TUP-1924:use UnityManager here ,same with import normal items.
            FileResourcesUnityManager fileUnityManager = ResourcesManagerFactory.getInstance().createFileUnityManager(srcFile);
            resManager = fileUnityManager.doUnify();
            if (resManager != null) {
                resManagers.add(resManager);
            }
        }
    } catch (ZipException e) {
        //$NON-NLS-1$ 
        displayErrorDialog(Messages.getString("ImportItemsWizardPage_ZipImport_badFormat"));
    } catch (TarException e) {
        //$NON-NLS-1$ 
        displayErrorDialog(Messages.getString("ImportItemsWizardPage_TarImport_badFormat"));
    } catch (FileNotFoundException e) {
        ExceptionHandler.process(e);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    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) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File)

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