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