Compare commits

...

21 Commits

Author SHA1 Message Date
Chao MENG
eca572a31c feat(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-10-16 11:22:06 +08:00
Chao MENG
eff9e27f1b Merge remote-tracking branch 'origin/master' into cmeng/bugfix/TUP-23905-Duplicate_id 2019-10-16 10:37:56 +08:00
Chao MENG
74f44b59b5 feat(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-10-15 19:26:59 +08:00
Chao MENG
b2b40eb6db feat(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-10-14 18:27:22 +08:00
Chao MENG
8b28d1e29d Merge remote-tracking branch 'origin/master' into cmeng/bugfix/TUP-23905-Duplicate_id 2019-10-12 15:55:58 +08:00
Chao MENG
17e1a850a4 Merge remote-tracking branch 'origin/master' into cmeng/bugfix/TUP-23905-Duplicate_id 2019-09-26 10:40:27 +08:00
Chao MENG
1107b0b965 feat(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-23 15:18:36 +08:00
Chao MENG
df0a8bee78 Merge remote-tracking branch 'origin/master' into cmeng/bugfix/TUP-23905-Duplicate_id 2019-09-23 15:06:11 +08:00
Chao MENG
0174547321 fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-20 19:04:24 +08:00
Chao MENG
5cd2b0ce93 Revert "fix(TUP-23905): Job disappearing after merging git branches https://jira.talendforge.org/browse/TUP-23905"
This reverts commit 1edf4aca87.
2019-09-20 17:17:59 +08:00
Chao MENG
719d853b54 fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-20 16:55:34 +08:00
Chao MENG
4856cacafe fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-20 11:55:22 +08:00
Chao MENG
4b3d0ef42a Merge remote-tracking branch 'origin/master' into cmeng/bugfix/TUP-23905-Duplicate_id 2019-09-20 09:53:54 +08:00
Chao MENG
e21d814938 fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-19 20:21:34 +08:00
Chao MENG
b8117c2edc fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905

Temporary enable all to check junit
2019-09-19 18:13:36 +08:00
Chao MENG
1edf4aca87 fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905

Temporary enable all to check junit
2019-09-18 19:33:19 +08:00
Chao MENG
d2120b42ac fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-18 19:32:13 +08:00
Chao MENG
39e4894ff9 fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-18 17:33:50 +08:00
Chao MENG
5308b86769 fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-17 19:57:21 +08:00
Chao MENG
d4295792aa fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-12 19:53:09 +08:00
Chao MENG
63c8717271 fix(TUP-23905): Job disappearing after merging git branches
https://jira.talendforge.org/browse/TUP-23905
2019-09-11 18:34:38 +08:00
11 changed files with 552 additions and 430 deletions

View File

@@ -386,7 +386,8 @@ public class RelationshipItemBuilder {
if (id.indexOf(" - ") != -1) { //$NON-NLS-1$
try {
tmpRelatedItem = (Relation) relatedItem.clone();
tmpRelatedItem.setId(id.split(" - ")[0]); //$NON-NLS-1$
id = id.split(" - ")[0]; //$NON-NLS-1$
tmpRelatedItem.setId(id);
} catch (CloneNotSupportedException e) {
log.error(e);
}

View File

@@ -17,6 +17,10 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
@@ -342,4 +346,17 @@ public class ReflectionUtils {
}
return ownerClass;
}
public static Collection<Field> getAllDeclaredFields(Class clazz) {
if (clazz == Object.class) {
return Collections.EMPTY_LIST;
}
Collection<Field> allDeclaredFields = new LinkedList<>();
Field[] declaredFields = clazz.getDeclaredFields();
if (declaredFields != null && 0 < declaredFields.length) {
allDeclaredFields.addAll(Arrays.asList(declaredFields));
}
allDeclaredFields.addAll(getAllDeclaredFields(clazz.getSuperclass()));
return allDeclaredFields;
}
}

View File

@@ -27,6 +27,8 @@ ImportItemsWizardPage_ErrorsMessage=The item '{0}' with different version {1} ex
ImportItemsWizardPage_internalIdGroup=Internal id
ImportItemsWizardPage_internalIdGroup_alwaysRegenId=Always regenerate id when import
ImportItemsWizardPage_internalIdGroup_keepOrigId=Keep original internal id
ImportItemsWizardPage_cancelPressed_title=Confirm
ImportItemsWizardPage_cancelPressed_desc=Studio is still doing the import related actions, if you cancel now, some imported items may don't work correctly.\nAre you sure to cancel now?
ImportItemsAction_title=Import items

View File

@@ -520,10 +520,10 @@ public class ImportItemsWizardPage extends WizardPage {
regenIdBtn = new Button(internalIdGroup, SWT.RADIO);
regenIdBtn.setText(Messages.getString("ImportItemsWizardPage_internalIdGroup_alwaysRegenId"));
regenIdBtn.setSelection(true);
Button keepOrigIdBtn = new Button(internalIdGroup, SWT.RADIO);
keepOrigIdBtn.setText(Messages.getString("ImportItemsWizardPage_internalIdGroup_keepOrigId"));
keepOrigIdBtn.setSelection(true);
// see feature 3949
this.overwriteButton = new Button(optionsArea, SWT.CHECK);
@@ -543,7 +543,6 @@ public class ImportItemsWizardPage extends WizardPage {
overwriteLayoutData.left = new FormAttachment(internalIdGroup, 0, SWT.LEFT);
this.overwriteButton.setLayoutData(overwriteLayoutData);
internalIdGroup.setVisible(false);
}
protected boolean isEnableForExchange() {
@@ -1067,7 +1066,18 @@ public class ImportItemsWizardPage extends WizardPage {
}
};
new ProgressMonitorDialog(getShell()).run(true, true, iRunnableWithProgress);
new ProgressMonitorDialog(getShell()) {
@Override
protected void cancelPressed() {
boolean userAgreed = MessageDialog.openConfirm(getParentShell(),
Messages.getString("ImportItemsWizardPage_cancelPressed_title"),
Messages.getString("ImportItemsWizardPage_cancelPressed_desc"));
if (userAgreed) {
super.cancelPressed();
}
};
}.run(true, true, iRunnableWithProgress);
} catch (Exception e) {
ExceptionHandler.process(e);

View File

@@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -515,6 +514,8 @@ public class ImportExportHandlersManager {
RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit(
Messages.getString("ImportExportHandlersManager_importingItemsMessage")) { //$NON-NLS-1$
private boolean hasJoblet = false;
@Override
public void run() throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@@ -539,115 +540,25 @@ public class ImportExportHandlersManager {
final Set<String> overwriteDeletedItems = new HashSet<String>();
final Set<String> idDeletedBeforeImport = new HashSet<String>();
Map<String, String> nameToIdMap = new HashMap<String, String>();
for (ImportItem itemRecord : checkedItemRecords) {
if (monitor.isCanceled()) {
return;
}
if (itemRecord.isValid()) {
if (alwaysRegenId || itemRecord.getState() == State.ID_EXISTED
|| itemRecord.getState() == State.NAME_AND_ID_EXISTED_BOTH
|| itemRecord.getState() == State.NAME_EXISTED) {
String id = nameToIdMap.get(itemRecord.getProperty().getLabel()
+ ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem())
.toString());
if (id == null) {
try {
boolean reuseExistingId = false;
if (overwrite && (itemRecord.getState() == State.NAME_AND_ID_EXISTED_BOTH
|| itemRecord.getState() == State.NAME_EXISTED)) {
// just try to reuse the id of the item which will be overwrited
reuseExistingId = true;
} else if (alwaysRegenId) {
switch (itemRecord.getState()) {
case NAME_EXISTED:
case NAME_AND_ID_EXISTED:
case NAME_AND_ID_EXISTED_BOTH:
reuseExistingId = true;
break;
default:
break;
}
}
if (reuseExistingId) {
IRepositoryViewObject object = itemRecord.getExistingItemWithSameName();
if (object != null) {
if (ProjectManager.getInstance().isInCurrentMainProject(
object.getProperty())) {
// in case it is in reference project
id = object.getId();
}
}
}
} catch (Exception e) {
ExceptionHandler.process(e, Priority.WARN);
}
if (id == null) {
/*
* if id exsist then need to genrate new id for this job,in this case
* the job won't override the old one
*/
id = EcoreUtil.generateUUID();
}
nameToIdMap.put(itemRecord.getProperty().getLabel()
+ ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem())
.toString(), id);
}
String oldId = itemRecord.getProperty().getId();
itemRecord.getProperty().setId(id);
try {
changeIdManager.mapOldId2NewId(oldId, id);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
}
try {
importItemRecordsWithRelations(monitor, resManager, checkedItemRecords, overwrite,
allImportItemRecords, destinationPath, overwriteDeletedItems, idDeletedBeforeImport);
allImportItemRecords, destinationPath, overwriteDeletedItems, idDeletedBeforeImport,
alwaysRegenId);
} catch (Exception e) {
if (Platform.inDebugMode()) {
ExceptionHandler.process(e);
}
throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass())
.getSymbolicName(),
Messages.getString("ImportExportHandlersManager_importingItemsError"), e)); //$NON-NLS-1$
throw generateCoreException(e);
}
ImportCacheHelper.getInstance().checkDeletedFolders();
ImportCacheHelper.getInstance().checkDeletedItems();
monitor.done();
TimeMeasure.step("importItemRecords", "before save"); //$NON-NLS-1$ //$NON-NLS-2$
if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
RelationshipItemBuilder.getInstance().saveRelations();
TimeMeasure.step("importItemRecords", "save relations"); //$NON-NLS-1$ //$NON-NLS-2$
} else {
// only save the project here if no relation need to be saved, since project will
// already be
// saved
// with relations
try {
factory.saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (PersistenceException e) {
if (Platform.inDebugMode()) {
ExceptionHandler.process(e);
}
throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass())
.getSymbolicName(),
Messages.getString("ImportExportHandlersManager_importingItemsError"), e)); //$NON-NLS-1$
}
TimeMeasure.step("importItemRecords", "save project"); //$NON-NLS-1$//$NON-NLS-2$
}
// import empty folders
if (!checkedFolders.isEmpty()) {
for (EmptyFolderImportItem folder : checkedFolders) {
checkCancel(monitor);
boolean exist = false;
ERepositoryObjectType repositoryType = folder.getRepositoryType();
IPath path = folder.getPath();
@@ -678,57 +589,98 @@ public class ImportExportHandlersManager {
}
}
TimeMeasure.step("importItemRecords", "import empty folders"); //$NON-NLS-1$//$NON-NLS-2$
}
TimeMeasure.step("importItemRecords", "before allocate new ids"); //$NON-NLS-1$ //$NON-NLS-2$
try {
changeIdManager.changeIds(monitor);
} catch (InterruptedException e) {
throw generateCoreException(e);
} catch (Exception e) {
ExceptionHandler.process(e);
}
TimeMeasure.step("importItemRecords", "allocate new ids"); //$NON-NLS-1$//$NON-NLS-2$
if (hasJoblet && PluginChecker.isJobLetPluginLoaded()) {
checkCancel(monitor);
monitor.subTask(Messages.getString("ImportExportHandlersManager_progressReloadingJoblets"));
TimeMeasure.step("importItemRecords", "before reload joblets"); //$NON-NLS-1$//$NON-NLS-2$
IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister.getDefault()
.getService(IJobletProviderService.class);
if (jobletService != null) {
jobletService.loadComponentsFromProviders();
}
TimeMeasure.step("importItemRecords", "reload joblets"); //$NON-NLS-1$//$NON-NLS-2$
}
// post import
List<ImportItem> importedItemRecords = ImportCacheHelper.getInstance().getImportedItemRecords();
postImport(monitor, resManager, importedItemRecords.toArray(new ImportItem[0]));
try {
changeIdManager.changeIds();
} catch (Exception e) {
ExceptionHandler.process(e);
for (ImportItem importedItem : importedItemRecords) {
checkCancel(monitor);
String label = importedItem.getLabel();
IImportItemsHandler importHandler = importedItem.getImportHandler();
try {
monitor.subTask(
Messages.getString("ImportExportHandlersManager_progressApplyMigrationTasks", label));
importHandler.applyMigrationTasks(importedItem, progressMonitor);
TimeMeasure.step("importItemRecords", "applyMigrationTasks: " + label); //$NON-NLS-1$//$NON-NLS-2$
} catch (Exception e) {
ExceptionHandler.process(e);
}
try {
monitor.subTask(
Messages.getString("ImportExportHandlersManager_progressDoFinalCheck", label));
importHandler.afterImportingItems(progressMonitor, resManager, importedItem);
TimeMeasure.step("importItemRecords", "operation after importing item: " + label); //$NON-NLS-1$ //$NON-NLS-2$
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
TimeMeasure.step("importItemRecords", "before save"); //$NON-NLS-1$ //$NON-NLS-2$
if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
RelationshipItemBuilder.getInstance().saveRelations();
TimeMeasure.step("importItemRecords", "save relations"); //$NON-NLS-1$ //$NON-NLS-2$
} else {
// only save the project here if no relation need to be saved, since project will
// already be
// saved
// with relations
try {
monitor.subTask(Messages
.getString("ImportExportHandlersManager_progressSavingProjectConfigurations"));
factory.saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (PersistenceException e) {
if (Platform.inDebugMode()) {
ExceptionHandler.process(e);
}
throw new CoreException(
new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),
Messages.getString("ImportExportHandlersManager_importingItemsError"), e)); //$NON-NLS-1$
}
TimeMeasure.step("importItemRecords", "save project"); //$NON-NLS-1$//$NON-NLS-2$
}
postImport(monitor, resManager, importedItemRecords.toArray(new ImportItem[0]));
}
private void importItemRecordsWithRelations(final IProgressMonitor monitor,
final ResourcesManager manager, final List<ImportItem> processingItemRecords,
final boolean overwriting, ImportItem[] allPopulatedImportItemRecords, IPath destinationPath,
final Set<String> overwriteDeletedItems, final Set<String> idDeletedBeforeImport)
throws Exception {
boolean hasJoblet = false;
boolean jobletReloaded = false;
final Set<String> overwriteDeletedItems, final Set<String> idDeletedBeforeImport,
final boolean alwaysRegenId) throws Exception {
for (ImportItem itemRecord : processingItemRecords) {
if (monitor.isCanceled()) {
return;
}
changeIdManager.add(itemRecord);
allocateInternalId(itemRecord, false, overwrite, alwaysRegenId);
}
for (ImportItem itemRecord : processingItemRecords) {
checkCancel(monitor);
if (itemRecord.isImported()) {
continue; // have imported
}
if ((ERepositoryObjectType.JOBLET == itemRecord.getRepositoryType())
|| (ERepositoryObjectType.PROCESS_ROUTELET == itemRecord.getRepositoryType())
|| (ERepositoryObjectType.SPARK_JOBLET == itemRecord.getRepositoryType())
|| (ERepositoryObjectType.SPARK_STREAMING_JOBLET == itemRecord.getRepositoryType())) {
hasJoblet = true;
}
if (hasJoblet && !jobletReloaded) {
if (ERepositoryObjectType.JOBLET != itemRecord.getRepositoryType()
&& ERepositoryObjectType.PROCESS_ROUTELET != itemRecord.getRepositoryType()
&& ERepositoryObjectType.SPARK_JOBLET != itemRecord.getRepositoryType()
&& ERepositoryObjectType.SPARK_STREAMING_JOBLET != itemRecord.getRepositoryType()) {
// fix for TUP-3032 ,processingItemRecords is a sorted list with joblet before
// jobs . we should load joblet component before import jobs to build the
// relationship.
jobletReloaded = true;
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister
.getDefault().getService(IJobletProviderService.class);
if (jobletService != null) {
jobletService.loadComponentsFromProviders();
}
}
}
}
try {
final IImportItemsHandler importHandler = itemRecord.getImportHandler();
if (importHandler != null && itemRecord.isValid()) {
@@ -739,36 +691,43 @@ public class ImportExportHandlersManager {
if (!relatedItemRecord.isEmpty()) {
importItemRecordsWithRelations(monitor, manager, relatedItemRecord, overwriting,
allPopulatedImportItemRecords, destinationPath, overwriteDeletedItems,
idDeletedBeforeImport);
idDeletedBeforeImport, alwaysRegenId);
}
}
if (monitor.isCanceled()) {
return;
}
changeIdManager.add(itemRecord);
allocateInternalId(itemRecord, true, overwrite, alwaysRegenId);
if ((ERepositoryObjectType.JOBLET == itemRecord.getRepositoryType())
|| (ERepositoryObjectType.PROCESS_ROUTELET == itemRecord.getRepositoryType())
|| (ERepositoryObjectType.SPARK_JOBLET == itemRecord.getRepositoryType())
|| (ERepositoryObjectType.SPARK_STREAMING_JOBLET == itemRecord
.getRepositoryType())) {
hasJoblet = true;
} else if (ERepositoryObjectType.TEST_CONTAINER == itemRecord.getRepositoryType()) {
((ImportBasicHandler) itemRecord.getImportHandler()).resolveItem(manager, itemRecord);
changeIdManager.updateTestContainerParentId(monitor, itemRecord.getItem());
}
// will import
importHandler.doImport(monitor, manager, itemRecord, overwriting, destinationPath,
overwriteDeletedItems, idDeletedBeforeImport);
if (monitor.isCanceled()) {
return;
}
checkCancel(monitor);
// if import related items behind current item
if (!importHandler.isPriorImportRelatedItem()) {
if (!relatedItemRecord.isEmpty()) {
importItemRecordsWithRelations(monitor, manager, relatedItemRecord, overwriting,
allPopulatedImportItemRecords, destinationPath, overwriteDeletedItems,
idDeletedBeforeImport);
idDeletedBeforeImport, alwaysRegenId);
}
}
importHandler.afterImportingItems(monitor, manager, itemRecord);
// record the imported items with related items too.
ImportCacheHelper.getInstance().getImportedItemRecords().add(itemRecord);
monitor.worked(1);
}
} catch (InterruptedException e) {
throw e;
} catch (Exception e) {
// ???, PTODO if there one error, need throw error or not.
if (Platform.inDebugMode()) {
@@ -782,14 +741,6 @@ public class ImportExportHandlersManager {
}
if (hasJoblet && !jobletReloaded && PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService jobletService = (IJobletProviderService) GlobalServiceRegister
.getDefault().getService(IJobletProviderService.class);
if (jobletService != null) {
jobletService.loadComponentsFromProviders();
}
}
}
};
@@ -805,9 +756,26 @@ public class ImportExportHandlersManager {
ExceptionHandler.process(e);
}
}
progressMonitor.subTask(Messages.getString("ImportExportHandlersManager_progressFireImportChanges"));
// fire import event out of workspace runnable
fireImportChange(ImportCacheHelper.getInstance().getImportedItemRecords());
}
private void checkCancel(IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
return;
}
if (monitor.isCanceled() || Thread.currentThread().isInterrupted()) {
throw generateCoreException(
new InterruptedException(Messages.getString("IProgressMonitor_UserCancelled")));
}
}
private CoreException generateCoreException(Exception e) {
return new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(),
Messages.getString("ImportExportHandlersManager_importingItemsError"), e)); //$NON-NLS-1$
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
repositoryWorkUnit.setUnloadResourcesAfterRun(true);
@@ -952,4 +920,73 @@ public class ImportExportHandlersManager {
importItem.setProperty(null);
importItem.clear();
}
private void allocateInternalId(ImportItem itemRecord, final boolean updateProperty, final boolean overwrite,
final boolean alwaysRegenId) {
if (itemRecord.isImported()) {
return;
}
if (alwaysRegenId || itemRecord.getState() == State.ID_EXISTED || itemRecord.getState() == State.NAME_AND_ID_EXISTED_BOTH
|| itemRecord.getState() == State.NAME_EXISTED) {
Map<Object, String> itemToIdMap = changeIdManager.getItemToIdMap();
Property property = itemRecord.getProperty();
ERepositoryObjectType repObjType = ERepositoryObjectType.getItemType(property.getItem());
/**
* 1. Use path + label, because some repository type allow same name with different path<br/>
* 2. Don't use path from ImportItem, because there may be same item with different version<br/>
*/
final String key = repObjType.toString() + "#" + property.getItem().getState().getPath() + "#" + property.getLabel();
String id = itemToIdMap.get(key);
if (id == null) {
try {
boolean reuseExistingId = false;
if (overwrite && (itemRecord.getState() == State.NAME_AND_ID_EXISTED_BOTH
|| itemRecord.getState() == State.NAME_EXISTED)) {
// just try to reuse the id of the item which will be overwrited
reuseExistingId = true;
} else if (alwaysRegenId) {
switch (itemRecord.getState()) {
case NAME_EXISTED:
case NAME_AND_ID_EXISTED:
case NAME_AND_ID_EXISTED_BOTH:
reuseExistingId = true;
break;
default:
break;
}
}
if (reuseExistingId) {
IRepositoryViewObject object = itemRecord.getExistingItemWithSameName();
if (object != null) {
if (ProjectManager.getInstance().isInCurrentMainProject(object.getProperty())) {
// in case it is in reference project
id = object.getId();
}
}
}
} catch (Exception e) {
ExceptionHandler.process(e, Priority.WARN);
}
if (id == null) {
/*
* if id exsist then need to genrate new id for this job,in this case the job won't override the old
* one
*/
id = EcoreUtil.generateUUID();
}
itemToIdMap.put(key, id);
}
String oldId = itemRecord.getProperty().getId();
if (updateProperty) {
itemRecord.getProperty().setId(id);
}
try {
changeIdManager.mapOldId2NewId(oldId, id);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
}

View File

@@ -132,4 +132,6 @@ public interface IImportItemsHandler extends IExecutableExtension {
*
*/
void afterImportingItems(IProgressMonitor monitor, ResourcesManager resManager, ImportItem importItem) throws Exception;
void applyMigrationTasks(ImportItem importItem, IProgressMonitor monitor);
}

View File

@@ -765,9 +765,6 @@ public class ImportBasicHandler extends AbstractImportExecutableHandler {
String label = selectedImportItem.getLabel();
TimeMeasure.step("importItemRecords", "Import item: " + label); //$NON-NLS-1$ //$NON-NLS-2$
applyMigrationTasks(selectedImportItem, monitor);
TimeMeasure.step("importItemRecords", "applyMigrationTasks: " + label); //$NON-NLS-1$//$NON-NLS-2$
}
protected void doImportItem(IProgressMonitor monitor, ResourcesManager resManager, ImportItem selectedImportItem,
@@ -1265,7 +1262,8 @@ public class ImportBasicHandler extends AbstractImportExecutableHandler {
* @param importItem
* @param monitor
*/
protected void applyMigrationTasks(ImportItem importItem, IProgressMonitor monitor) {
@Override
public void applyMigrationTasks(ImportItem importItem, IProgressMonitor monitor) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IMigrationToolService.class)) {
IMigrationToolService migrationService = (IMigrationToolService) GlobalServiceRegister.getDefault().getService(
IMigrationToolService.class);

View File

@@ -12,28 +12,31 @@
// ============================================================================
package org.talend.repository.items.importexport.manager;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Stack;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Priority;
import org.eclipse.emf.common.util.EList;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.talend.commons.CommonsPlugin;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.core.GlobalServiceRegister;
import org.talend.core.model.metadata.builder.connection.Connection;
import org.talend.core.model.process.IContext;
import org.talend.core.model.process.IContextManager;
import org.talend.core.model.process.IContextParameter;
import org.talend.core.model.process.IElementParameter;
import org.talend.core.model.process.IGenericElementParameter;
import org.talend.core.model.process.INode;
import org.talend.core.model.process.IProcess;
import org.talend.core.model.process.IProcess2;
import org.talend.core.model.process.ProcessUtils;
@@ -48,13 +51,13 @@ import org.talend.core.model.relationship.RelationshipItemBuilder;
import org.talend.core.model.repository.ERepositoryObjectType;
import org.talend.core.model.repository.IRepositoryViewObject;
import org.talend.core.repository.model.ProxyRepositoryFactory;
import org.talend.core.utils.ReflectionUtils;
import org.talend.designer.core.IDesignerCoreService;
import org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType;
import org.talend.designer.core.model.utils.emf.talendfile.ContextType;
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
import org.talend.designer.joblet.model.JobletProcess;
import org.talend.repository.ProjectManager;
import org.talend.repository.items.importexport.handlers.model.ImportItem;
import org.talend.repository.items.importexport.i18n.Messages;
import org.talend.repository.model.IProxyRepositoryFactory;
/**
@@ -72,6 +75,8 @@ public class ChangeIdManager {
private Map<String, String> oldId2NewIdMap = new HashMap<String, String>();
private Map<Object, String> item2IdMap = new HashMap<>();
private Set<String> idsNeed2CheckRefs = new HashSet<String>();
private org.talend.core.model.general.Project currentProject;
@@ -87,10 +92,14 @@ public class ChangeIdManager {
refIds2ItemIdsMap.clear();
oldId2NewIdMap.clear();
idsNeed2CheckRefs.clear();
item2IdMap.clear();
currentProject = null;
}
public void add(ImportItem importItem) {
if (importItem.isImported()) {
return;
}
prepareRelationshipItemBuilder(importItem.getItemProject());
@@ -99,17 +108,22 @@ public class ChangeIdManager {
if (property != null) {
String id = property.getId();
// record all importing id
oldId2NewIdMap.put(id, null);
if (!oldId2NewIdMap.containsKey(id)) {
oldId2NewIdMap.put(id, null);
}
// same id with different versions
List<ImportItem> itemRecords = id2ImportItemsMap.get(id);
if (itemRecords == null) {
itemRecords = new ArrayList<ImportItem>();
id2ImportItemsMap.put(id, itemRecords);
}
itemRecords.add(importItem);
Item item = property.getItem();
if (item instanceof ConnectionItem) {
idsNeed2CheckRefs.add(id);
if (!itemRecords.contains(importItem)) {
itemRecords.add(importItem);
Item item = property.getItem();
if (item instanceof ConnectionItem) {
idsNeed2CheckRefs.add(id);
}
}
}
}
@@ -122,12 +136,13 @@ public class ChangeIdManager {
}
}
public void changeIds() throws Exception {
public void changeIds(IProgressMonitor monitor) throws Exception {
buildRefIds2ItemIdsMap();
Map<String, Set<String>> changeIdMap = buildChangeIdMap();
for (Map.Entry<String, Set<String>> entry : changeIdMap.entrySet()) {
checkCancel(monitor);
String oldEffectedId = entry.getKey();
if (!oldId2NewIdMap.containsKey(oldEffectedId)) {
// means didn't import this item
@@ -146,16 +161,21 @@ public class ChangeIdManager {
List<IRepositoryViewObject> repViewObjs = getAllVersion(newEffectedId, repType);
if (repViewObjs != null && !repViewObjs.isEmpty()) {
for (IRepositoryViewObject repViewObj : repViewObjs) {
checkCancel(monitor);
Map<String, String> old2NewMap = new HashMap<>();
for (String oldId : entry.getValue()) {
String newId = oldId2NewIdMap.get(oldId);
if (StringUtils.equals(newId, oldId)) {
if (newId == null || StringUtils.equals(newId, oldId)) {
continue;
}
old2NewMap.put(oldId, newId);
}
if (old2NewMap.isEmpty()) {
continue;
}
Property property = repViewObj.getProperty();
changeRelated(old2NewMap, property, getCurrentProject());
monitor.subTask(Messages.getString("ChangeIdManager_ApplyingNewIds", property.getDisplayName()));
changeRelated(monitor, old2NewMap, property, getCurrentProject());
String version = property.getVersion();
for (ImportItem importItem : importItems) {
if (StringUtils.equals(version, importItem.getItemVersion())) {
@@ -171,6 +191,7 @@ public class ChangeIdManager {
private Map<String, Set<String>> buildChangeIdMap() {
Map<String, Set<String>> effectedIdsMap = new HashMap<>();
Set<String> metadataItemOldIds = new HashSet<>();
for (Map.Entry<String, String> entry : oldId2NewIdMap.entrySet()) {
String oldId = entry.getKey();
@@ -179,18 +200,28 @@ public class ChangeIdManager {
continue;
}
Set<String> relationIds = new HashSet<String>();
Set<String> effectedRelationIds = new HashSet<String>();
Collection<String> itemIds = refIds2ItemIdsMap.get(oldId);
if (itemIds != null && !itemIds.isEmpty()) {
relationIds.addAll(itemIds);
effectedRelationIds.addAll(itemIds);
}
List<Relation> relations = getRelations(oldId);
for (Relation relation : relations) {
relationIds.add(ProcessUtils.getPureItemId(relation.getId()));
List<Relation> effectedRelations = getRelations(oldId);
for (Relation relation : effectedRelations) {
effectedRelationIds.add(ProcessUtils.getPureItemId(relation.getId()));
}
if (relationIds.isEmpty()) {
List<ImportItem> importItems = id2ImportItemsMap.get(oldId);
if (importItems != null && !importItems.isEmpty()) {
ImportItem importItem = importItems.get(0);
if (importItem != null) {
if (importItem.getItem() instanceof ConnectionItem) {
metadataItemOldIds.add(oldId);
}
}
}
if (effectedRelationIds.isEmpty()) {
continue;
}
@@ -199,7 +230,7 @@ public class ChangeIdManager {
idSet = new HashSet<>();
effectedIdsMap.put(oldId, idSet);
}
idSet.addAll(relationIds);
idSet.addAll(effectedRelationIds);
}
Map<String, Set<String>> changeIdMap = new HashMap<>();
@@ -216,6 +247,16 @@ public class ChangeIdManager {
changeSet.add(oldId);
}
}
// record all metadata connections, because some metadata doesn't record relationships, like hadoop cluster
for (String metadataOldId : metadataItemOldIds) {
Set<String> set = changeIdMap.get(metadataOldId);
if (set == null) {
set = new HashSet<>();
changeIdMap.put(metadataOldId, set);
}
set.addAll(metadataItemOldIds);
}
return changeIdMap;
}
@@ -287,114 +328,168 @@ public class ChangeIdManager {
return relations;
}
private void changeRelated(Map<String, String> old2NewMap, Property property,
private void changeRelated(IProgressMonitor monitor, Map<String, String> old2NewMap, Property property,
org.talend.core.model.general.Project project) throws Exception {
checkCancel(monitor);
Item item = property.getItem();
boolean modified = false;
if (item instanceof ProcessItem) {
modified = changeRelatedProcess(old2NewMap, item);
modified = changeRelatedProcess(monitor, old2NewMap, item);
} else if (item instanceof JobletProcessItem) {
modified = changeRelatedProcess(old2NewMap, item);
modified = changeRelatedProcess(monitor, old2NewMap, item);
} else if (item instanceof ConnectionItem) {
modified = changeRelatedConnection(old2NewMap, (ConnectionItem) item);
modified = changeRelatedConnection(monitor, old2NewMap, (ConnectionItem) item);
} else {
throw new Exception("Unsupported id change: id[" + property.getId() + "], name[" + property.getLabel() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
if (modified) {
ProxyRepositoryFactory.getInstance().save(project, item);
RelationshipItemBuilder.getInstance().addOrUpdateItem(property.getItem());
// RelationshipItemBuilder.getInstance().addOrUpdateItem(property.getItem());
}
}
private boolean changeRelatedConnection(Map<String, String> old2NewMap, ConnectionItem item) throws Exception {
boolean modified = false;
Connection conn = item.getConnection();
String ctxId = conn.getContextId();
private boolean changeRelatedConnection(IProgressMonitor monitor, Map<String, String> old2NewMap, ConnectionItem item)
throws Exception {
return changeRelatedObject(monitor, old2NewMap, item.getConnection(), new Stack<>(), new HashMap<>());
}
private boolean changeRelatedObject(IProgressMonitor monitor, Map<String, String> old2NewMap, Object conn,
Stack<Object> visitStack, Map<String, List<Object>> changedMap) throws Exception {
checkCancel(monitor);
if (conn == null) {
return false;
}
boolean isEmpty = true;
for (Map.Entry<String, String> entry : old2NewMap.entrySet()) {
if (StringUtils.equals(entry.getKey(), ctxId)) {
conn.setContextId(entry.getValue());
modified = true;
if (entry.getValue() != null) {
isEmpty = false;
break;
}
}
if (!modified) {
throw new Exception("Unhandled case for import: " + item.toString()); //$NON-NLS-1$
if (isEmpty) {
return false;
}
if (conn instanceof Collection || conn instanceof Map) {
throw new Exception("Bad usage of function, can't be Collection or Map here!");
}
boolean modified = false;
Collection<Field> fields = ReflectionUtils.getAllDeclaredFields(conn.getClass());
for (Field field : fields) {
if (field.isEnumConstant() || field.getType().isPrimitive()) {
continue;
}
field.setAccessible(true);
Object obj = field.get(conn);
if (obj != null) {
if (visitStack.contains(obj)) {
continue;
}
if (obj.getClass() == Object.class) {
continue;
} else if (isBasicType(obj.getClass())) {
continue;
} else if (field.getType() == String.class) {
if (Modifier.isFinal(field.getModifiers())) {
continue;
}
for (Map.Entry<String, String> entry : old2NewMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (value == null || StringUtils.equals(key, value)) {
continue;
}
// update latest value
obj = field.get(conn);
if (obj == null) {
break;
}
String newValue = doReplace(obj.toString(), key, value);
if (!StringUtils.equals(obj.toString(), newValue)) {
field.set(conn, newValue);
}
modified = true;
}
} else {
try {
for (Map.Entry<String, String> entry : old2NewMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (value == null || StringUtils.equals(key, value)) {
continue;
}
changeValue(monitor, obj, key, value, visitStack, changedMap);
modified = true;
}
} catch (InterruptedException e) {
throw e;
} catch (UnsupportedOperationException e) {
if (CommonsPlugin.isDebugMode()) {
ExceptionHandler.process(e);
}
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
}
return modified;
}
private boolean changeRelatedProcess(Map<String, String> old2NewMap, Item item) throws Exception {
boolean modified = false;
private boolean isBasicType(Class clz) {
List<Class> basicTypes = Arrays.asList(Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class,
Float.class, Double.class, Void.class);
return basicTypes.contains(clz);
}
ProcessItem processItem = (ProcessItem) item;
ProcessType processType = processItem.getProcess();
/**
* change context repository id
*/
if (processType != null) {
EList context = processType.getContext();
if (context != null) {
for (Map.Entry<String, String> entry : old2NewMap.entrySet()) {
changeValue(context, entry.getKey(), entry.getValue());
}
modified = true;
private void setStringValue(Object model, Field field, String newValue) throws Exception {
String fieldName = field.getName();
String setMethodName = "set" + ("" + fieldName.charAt(0)).toUpperCase()
+ (0 < fieldName.length() ? fieldName.substring(1) : "");
boolean hasSetMethod = false;
try {
Method method = model.getClass().getMethod(setMethodName, String.class);
hasSetMethod = (method != null);
} catch (Exception e) {
if (CommonsPlugin.isDebugMode()) {
ExceptionHandler.process(e);
}
}
if (hasSetMethod) {
ReflectionUtils.invokeMethod(model, setMethodName, new Object[] { newValue }, String.class);
} else {
field.set(model, newValue);
}
}
/**
* designerCoreService must not be null
*/
IDesignerCoreService designerCoreService = (IDesignerCoreService) GlobalServiceRegister.getDefault()
.getService(IDesignerCoreService.class);
IProcess process = designerCoreService.getProcessFromItem(item);
if (process == null) {
throw new Exception("Can't get process of item: id[" + item.getProperty().getId() + "], name[" //$NON-NLS-1$ //$NON-NLS-2$
private boolean changeRelatedProcess(IProgressMonitor monitor, Map<String, String> old2NewMap, Item item) throws Exception {
checkCancel(monitor);
ProcessType processType = null;
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
processType = processItem.getProcess();
} else if (item instanceof JobletProcessItem) {
JobletProcessItem processItem = (JobletProcessItem) item;
processType = processItem.getJobletProcess();
} else {
throw new Exception("Unhandled process type: id[" + item.getProperty().getId() + "], name[" //$NON-NLS-1$ //$NON-NLS-2$
+ item.getProperty().getLabel() + "]"); //$NON-NLS-1$
}
/**
* 1. change context
*/
// List contexts = item.getProcess().getContext();
// if (contexts != null && !contexts.isEmpty()) {
// changeValue(contexts, oldId, newId);
// modified = true;
// }
IContextManager contextManager = process.getContextManager();
if (contextManager != null) {
for (Map.Entry<String, String> entry : old2NewMap.entrySet()) {
changeValue(contextManager.getListContext(), entry.getKey(), entry.getValue());
}
modified = true;
}
/**
* 2. change elementParameters
*/
for (Map.Entry<String, String> entry : old2NewMap.entrySet()) {
changeValue(process.getElementParameters(), entry.getKey(), entry.getValue());
}
modified = true;
/**
* 3. change the nodes like tRunjob, tMysql
*/
List<? extends INode> nodes = process.getGraphicalNodes();
if (nodes != null && !nodes.isEmpty()) {
Iterator<? extends INode> nodeIter = nodes.iterator();
while (nodeIter.hasNext()) {
INode node = nodeIter.next();
if (node != null) {
for (Map.Entry<String, String> entry : old2NewMap.entrySet()) {
changeParamValueOfNode(node, entry.getKey(), entry.getValue());
}
}
}
modified = true;
}
boolean modified = changeRelatedObject(monitor, old2NewMap, processType, new Stack<>(), new HashMap<>());
if (modified) {
/**
* designerCoreService must not be null
*/
IDesignerCoreService designerCoreService = (IDesignerCoreService) GlobalServiceRegister.getDefault()
.getService(IDesignerCoreService.class);
IProcess process = designerCoreService.getProcessFromItem(item);
if (process == null) {
throw new Exception("Can't get process of item: id[" + item.getProperty().getId() + "], name[" //$NON-NLS-1$ //$NON-NLS-2$
+ item.getProperty().getLabel() + "]"); //$NON-NLS-1$
}
if (process instanceof IProcess2) {
processType = ((IProcess2) process).saveXmlFile();
if (item instanceof ProcessItem) {
@@ -414,167 +509,105 @@ public class ChangeIdManager {
}
private boolean changeParamValueOfNode(INode node, String fromValue, String toValue) throws Exception {
boolean changed = false;
List<? extends IElementParameter> elementParameters = node.getElementParameters();
if (elementParameters != null && !elementParameters.isEmpty()) {
changeValue(elementParameters, fromValue, toValue);
changed = true;
private void changeValue(IProgressMonitor monitor, Object aim, String fromValue, String toValue, Stack<Object> visitStack,
Map<String, List<Object>> changedMap) throws Exception {
checkCancel(monitor);
if (toValue == null) {
/**
* toValue must be a string, do you need ""?
*/
throw new IllegalArgumentException();
}
return changed;
}
private void changeValue(Object aim, String fromValue, String toValue) throws Exception {
if (aim == null) {
return;
}
if (aim instanceof IElementParameter) {
if (aim instanceof IGenericElementParameter) {
((IGenericElementParameter) aim).setAskPropagate(Boolean.TRUE);
}
IElementParameter elemParameter = (IElementParameter) aim;
Object elementParamValue = elemParameter.getValue();
if (elementParamValue != null) {
if (elementParamValue instanceof String) {
elemParameter.setValue(doReplace(elementParamValue.toString(), fromValue, toValue));
} else {
changeValue(elementParamValue, fromValue, toValue);
}
}
Map<String, IElementParameter> childParameters = elemParameter.getChildParameters();
if (childParameters != null && !childParameters.isEmpty()) {
changeValue(childParameters, fromValue, toValue);
}
} else if (aim instanceof ContextType) {
changeValue(((ContextType) aim).getContextParameter(), fromValue, toValue);
} else if (aim instanceof ContextParameterType) {
ContextParameterType ctxParamType = (ContextParameterType) aim;
String comment = ctxParamType.getComment();
if (comment != null) {
ctxParamType.setComment(doReplace(comment, fromValue, toValue));
}
String name = ctxParamType.getName();
if (name != null) {
ctxParamType.setName(doReplace(name, fromValue, toValue));
}
String prompt = ctxParamType.getPrompt();
if (prompt != null) {
ctxParamType.setPrompt(doReplace(prompt, fromValue, toValue));
}
// String rawValue = ctxParamType.getRawValue();
// if (rawValue != null) {
// ctxParamType.setRawValue(doReplace(rawValue, fromValue, toValue));
// }
String repCtxId = ctxParamType.getRepositoryContextId();
if (repCtxId != null) {
ctxParamType.setRepositoryContextId(doReplace(repCtxId, fromValue, toValue));
}
// String type = ctxParamType.getType();
// if (type != null) {
// ctxParamType.setType(doReplace(type, fromValue, toValue));
// }
String value = ctxParamType.getValue();
if (value != null) {
ctxParamType.setValue(doReplace(value, fromValue, toValue));
}
} else if (aim instanceof IContext) {
changeValue(((IContext) aim).getContextParameterList(), fromValue, toValue);
} else if (aim instanceof IContextParameter) {
IContextParameter contextParameter = (IContextParameter) aim;
String comment = contextParameter.getComment();
if (comment != null) {
contextParameter.setComment(doReplace(comment, fromValue, toValue));
}
String name = contextParameter.getName();
if (name != null) {
contextParameter.setName(doReplace(name, fromValue, toValue));
}
String prompt = contextParameter.getPrompt();
if (prompt != null) {
contextParameter.setPrompt(doReplace(prompt, fromValue, toValue));
}
String scriptCode = contextParameter.getScriptCode();
if (scriptCode != null) {
contextParameter.setScriptCode(doReplace(scriptCode, fromValue, toValue));
}
String source = contextParameter.getSource();
if (source != null) {
contextParameter.setSource(doReplace(source, fromValue, toValue));
}
// // reset type will clear the value
// String type = contextParameter.getType();
// if (type != null) {
// contextParameter.setType(doReplace(type, fromValue, toValue));
// }
String value = contextParameter.getValue();
if (value != null) {
contextParameter.setValue(doReplace(value, fromValue, toValue));
}
String[] values = contextParameter.getValueList();
if (values != null && 0 < values.length) {
List<String> list = Arrays.asList(values);
for (int i = 0; i < list.size(); i++) {
list.set(i, doReplace(list.get(i), fromValue, toValue));
}
contextParameter.setValueList(list.toArray(values));
}
} else if (aim instanceof String) {
throw new Exception("Uncatched value type case!"); //$NON-NLS-1$
} else if (aim instanceof List) {
List aimList = (List) aim;
for (int i = 0; i < aimList.size(); i++) {
Object obj = aimList.get(i);
if (obj instanceof String) {
aimList.set(i, doReplace(obj.toString(), fromValue, toValue));
} else {
changeValue(obj, fromValue, toValue);
}
}
} else if (aim instanceof Map) {
Map aimMap = (Map) aim;
if (aimMap != null && !aimMap.isEmpty()) {
Object key1 = aimMap.keySet().iterator().next();
if (key1 instanceof String) {
// maybe need to consider the order like LinkedHashMap
Object value = aimMap.get(fromValue);
if (value != null) {
aimMap.remove(fromValue);
aimMap.put(toValue, value);
}
}
Iterator<Map.Entry> iter = aimMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = iter.next();
Object value = entry.getValue();
if (value instanceof String) {
entry.setValue(doReplace(value.toString(), fromValue, toValue));
} else {
changeValue(value, fromValue, toValue);
}
}
}
} else if (aim instanceof Iterable) {
Iterator iter = ((Iterable) aim).iterator();
while (iter.hasNext()) {
// maybe not good
changeValue(iter.next(), fromValue, toValue);
}
ExceptionHandler.process(new Exception("Unchecked id change type: " + aim.getClass().toString()), Priority.WARN); //$NON-NLS-1$
} else if (aim instanceof Object[]) {
Object[] objs = (Object[]) aim;
for (Object obj : objs) {
changeValue(obj, fromValue, toValue);
}
} else if (visitStack.contains(aim)) {
return;
} else {
// some types no need to be changed like Boolean
// throw new Exception("Unhandled type: " + aim.getClass().getName()); //$NON-NLS-1$
visitStack.push(aim);
}
List<Object> changedListForKey = changedMap.get(fromValue);
if (changedListForKey == null) {
changedListForKey = new LinkedList<>();
changedMap.put(fromValue, changedListForKey);
}
try {
if (changedListForKey.contains(aim)) {
return;
}
if (aim instanceof IElementParameter) {
if (aim instanceof IGenericElementParameter) {
((IGenericElementParameter) aim).setAskPropagate(Boolean.TRUE);
}
Map<String, String> old2NewMap = new HashMap<>();
old2NewMap.put(fromValue, toValue);
changeRelatedObject(monitor, old2NewMap, aim, visitStack, changedMap);
} else if (aim instanceof EObject) {
Map<String, String> old2NewMap = new HashMap<>();
old2NewMap.put(fromValue, toValue);
changeRelatedObject(monitor, old2NewMap, aim, visitStack, changedMap);
} else if (aim instanceof List) {
List aimList = (List) aim;
for (int i = 0; i < aimList.size(); i++) {
Object obj = aimList.get(i);
if (obj instanceof String) {
aimList.set(i, doReplace(obj.toString(), fromValue, toValue));
} else {
changeValue(monitor, obj, fromValue, toValue, visitStack, changedMap);
}
}
} else if (aim instanceof Map) {
Map aimMap = (Map) aim;
if (aimMap != null && !aimMap.isEmpty()) {
Object key1 = aimMap.keySet().iterator().next();
if (key1 instanceof String) {
// maybe need to consider the order like LinkedHashMap
Object value = aimMap.get(fromValue);
if (value != null) {
aimMap.remove(fromValue);
aimMap.put(toValue, value);
}
}
Iterator<Map.Entry> iter = aimMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = iter.next();
Object value = entry.getValue();
if (value instanceof String) {
entry.setValue(doReplace(value.toString(), fromValue, toValue));
} else {
changeValue(monitor, value, fromValue, toValue, visitStack, changedMap);
}
}
}
} else if (aim instanceof Map.Entry) {
Map.Entry aimEntry = (Entry) aim;
Object value = aimEntry.getValue();
if (value instanceof String) {
aimEntry.setValue(doReplace((String) value, fromValue, toValue));
} else {
changeValue(monitor, value, fromValue, toValue, visitStack, changedMap);
}
} else if (aim instanceof Iterable) {
Iterator iter = ((Iterable) aim).iterator();
while (iter.hasNext()) {
// maybe not good
changeValue(monitor, iter.next(), fromValue, toValue, visitStack, changedMap);
}
ExceptionHandler.process(new Exception("Unchecked id change type: " + aim.getClass().toString()), Priority.WARN); //$NON-NLS-1$
} else if (aim instanceof Object[]) {
Object[] objs = (Object[]) aim;
for (Object obj : objs) {
changeValue(monitor, obj, fromValue, toValue, visitStack, changedMap);
}
}
} finally {
visitStack.pop();
changedListForKey.add(aim);
}
}
public void updateTestContainerParentId(IProgressMonitor monitor, Item testContainerItem) throws Exception {
changeRelatedObject(monitor, this.oldId2NewIdMap, testContainerItem, new Stack<>(), new HashMap<>());
}
private String doReplace(String aimString, String from, String to) {
@@ -596,4 +629,18 @@ public class ChangeIdManager {
}
return currentProject;
}
public Map<Object, String> getItemToIdMap() {
return item2IdMap;
}
private void checkCancel(IProgressMonitor monitor) throws Exception {
if (monitor == null) {
return;
}
if (monitor.isCanceled() || Thread.currentThread().isInterrupted()) {
throw new InterruptedException(Messages.getString("IProgressMonitor_UserCancelled"));
}
}
}

View File

@@ -11,9 +11,17 @@ ImportExportHandlersManager_populatingItemsMessage=Populate items to import
ImportExportHandlersManager_importingItemsMessage=Importing items...
ImportExportHandlersManager_deletingItemsMessage=Delete items...
ImportExportHandlersManager_importingItemsError=Import errors
ImportExportHandlersManager_progressReloadingJoblets=reloading joblets...
ImportExportHandlersManager_progressApplyMigrationTasks=Apply migration tasks for {0} ...
ImportExportHandlersManager_progressDoFinalCheck=Do final check for imported: {0} ...
ImportExportHandlersManager_progressSavingProjectConfigurations=Saving project configurations...
ImportExportHandlersManager_progressFireImportChanges=Notifying project of changes related to imported items...
ImportBasicHandler_ErrorCreateEmfResource=Load EMF Resource failed.
ImportBasicHandler_MissingItemFile=missing item file.
ImportBasicHandler_NotHrefCurrentItemFile=original item file has some errors, it has been recovered from file name, please recheck.
ImportBasicHandler_MissingItemError={0};Missing '{1}' file!;{2}
ImportBasicHandler_LoadEMFResourceError={0};Load EMF Resource failed;{1}
ImportBasicHandler_LoadEMFResourceError={0};Load EMF Resource failed;{1}
IProgressMonitor_UserCancelled=User cancelled.
ChangeIdManager_ApplyingNewIds=Applying new ids into {0} ...

View File

@@ -47,7 +47,7 @@ public class InternalNodeComponentHandlerTest {
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);
projectRecords.toArray(new ImportItem[0]), null, false);
IRepositoryViewObject obj = ProxyRepositoryFactory.getInstance().getLastVersion("_bFW5AAU9Eeagf6XEimuCGw");
Item item = obj.getProperty().getItem();

View File

@@ -209,7 +209,7 @@ public class ImportIntegrationTest {
private void initialize() throws Exception {
List<ImportItem> importItems = getImportItems1();
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, true,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
}
@Test
@@ -234,7 +234,7 @@ public class ImportIntegrationTest {
boolean wrongImport = true;
try {
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, false,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
} catch (Exception e) {
wrongImport = false;
}
@@ -271,7 +271,7 @@ public class ImportIntegrationTest {
}
}
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, true,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
// test result.
// we should have item we imported replace the old one (so the test component added should be present).
@@ -326,7 +326,7 @@ public class ImportIntegrationTest {
boolean wrongImport = false;
try {
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, false,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
} catch (Exception e) {
wrongImport = true;
}
@@ -378,7 +378,7 @@ public class ImportIntegrationTest {
boolean wrongImport = true;
try {
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, false,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
} catch (Exception e) {
wrongImport = false;
}
@@ -395,7 +395,7 @@ public class ImportIntegrationTest {
}
}
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, true,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
// test result.
// we should have item we imported replace the old one (so the test component added should be present).
@@ -436,7 +436,7 @@ public class ImportIntegrationTest {
// this one is directly test case of bug TDI-29063
List<ImportItem> importItems = getImportItems4();
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, true,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
importItems = getImportItems1();
int nbFound = 0;
@@ -460,7 +460,7 @@ public class ImportIntegrationTest {
throw new Exception("Items in the zip maybe changed, ids not found");
}
manager.importItemRecords(new NullProgressMonitor(), resManager, checkedItems, true,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
String newItemId = testedItem.getItemId();
ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
@@ -524,7 +524,7 @@ public class ImportIntegrationTest {
public void testItemDifferentNameSameIdWithDep2() throws Exception {
List<ImportItem> importItems = getImportItems5();
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, true,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
importItems = getImportItems1();
int nbFound = 0;
@@ -557,7 +557,7 @@ public class ImportIntegrationTest {
boolean wrongImport = false;
try {
manager.importItemRecords(new NullProgressMonitor(), resManager, checkedItems, false,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
} catch (Exception e) {
wrongImport = true;
}
@@ -662,7 +662,7 @@ public class ImportIntegrationTest {
public void testItemSameNameDifferentIdWithDep() throws Exception {
List<ImportItem> importItems = getImportItems6();
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, true,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
importItems = getImportItems1();
int nbFound = 0;
@@ -705,7 +705,7 @@ public class ImportIntegrationTest {
throw new Exception("Items in the zip maybe changed, ids not found");
}
manager.importItemRecords(new NullProgressMonitor(), resManager, checkedItems, true,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
@@ -828,7 +828,7 @@ public class ImportIntegrationTest {
public void testDuplicateIdInSameImport() throws Exception {
List<ImportItem> importItems = getImportItems7();
manager.importItemRecords(new NullProgressMonitor(), resManager, importItems, false,
importItems.toArray(new ImportItem[0]), new Path(""));
importItems.toArray(new ImportItem[0]), new Path(""), false);
String originalId = "_A7WlgP9BEeOBFtZnw6gdMg";
ImportItem itemWithOrigId = null;