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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations