TUP-3179:When duplicating a Job, it does not duplicate the associated

test cases

Conflicts:
	main/plugins/org.talend.core.runtime/src/main/java/org/talend/core/ui/ITestContainerProviderService.java
This commit is contained in:
hwang
2015-08-07 11:14:19 +08:00
parent 764500ba3c
commit a0e0ef0246
3 changed files with 44 additions and 70 deletions

View File

@@ -27,9 +27,7 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -387,12 +385,21 @@ public class CopyObjectAction {
return;
}
final IPath path = getTestCasePath(newItem, sourceNode);
for (IRepositoryNode testNode : sourceNode.getChildren()) {
Item testItem = testNode.getObject().getProperty().getItem();
if (!(testItem instanceof ProcessItem)) {
continue;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister
.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
testContainerService.copyDataFiles(newItem, sourceNode);
for (IRepositoryNode testNode : sourceNode.getChildren()) {
Item testItem = testNode.getObject().getProperty().getItem();
if (!(testItem instanceof ProcessItem)) {
continue;
}
// testContainerService.copyTestCase(testItem, path, null, false);
testContainerService.copyTestCase(newItem, testItem, path, null, false);
}
}
copyTestCase(testItem, path, null, false);
}
}
@@ -427,53 +434,6 @@ public class CopyObjectAction {
return true;
}
public void copyTestCase(final Item item, final IPath path, final String newName, final boolean isDuplicate) {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
try {
Item newItem = null;
if (isDuplicate) {
newItem = factory.copy(item, path, newName);
} else {
newItem = factory.copy(item, path, true);
}
if (newItem instanceof ProcessItem) {
RelationshipItemBuilder.getInstance().addOrUpdateItem(newItem);
}
factory.save(newItem);
} catch (PersistenceException e) {
throw new CoreException(new Status(IStatus.ERROR, "org.talend.core.repository", "", e));
} catch (BusinessException e) {
throw new CoreException(new Status(IStatus.ERROR, "org.talend.core.repository", "", e));
}
}
};
IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
};
try {
new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
//
}
}
private String getLastestVersion(Set<IRepositoryViewObject> set) {
if (set.isEmpty()) {
return null;

View File

@@ -277,24 +277,31 @@ public class DuplicateAction extends AContextualAction {
return;
}
final IPath path = copyObjectAction.getTestCasePath(newItem, sourceNode);
for (IRepositoryNode testNode : this.sourceNode.getChildren()) {
Item testItem = testNode.getObject().getProperty().getItem();
if (!(testItem instanceof ProcessItem)) {
continue;
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
ITestContainerProviderService testContainerService = (ITestContainerProviderService) GlobalServiceRegister
.getDefault().getService(ITestContainerProviderService.class);
if (testContainerService != null) {
testContainerService.copyDataFiles(newItem, sourceNode);
for (IRepositoryNode testNode : this.sourceNode.getChildren()) {
Item testItem = testNode.getObject().getProperty().getItem();
if (!(testItem instanceof ProcessItem)) {
continue;
}
String initNameValue = "Copy_of_" + testItem.getProperty().getDisplayName(); //$NON-NLS-1$
String jobNameValue = null;
final TreeSelection selectionInClipboard = (TreeSelection) selection;
ERepositoryObjectType type = ((RepositoryNode) selectionInClipboard.toArray()[0]).getObject()
.getRepositoryObjectType();
try {
jobNameValue = getDuplicateName((RepositoryNode) testNode, initNameValue, type, selectionInClipboard);
} catch (BusinessException e) {
jobNameValue = ""; //$NON-NLS-1$
}
testContainerService.copyTestCase(newItem, testItem, path, jobNameValue, true);
}
}
String initNameValue = "Copy_of_" + testItem.getProperty().getDisplayName(); //$NON-NLS-1$
String jobNameValue = null;
final TreeSelection selectionInClipboard = (TreeSelection) selection;
ERepositoryObjectType type = ((RepositoryNode) selectionInClipboard.toArray()[0]).getObject()
.getRepositoryObjectType();
try {
jobNameValue = getDuplicateName((RepositoryNode) testNode, initNameValue, type, selectionInClipboard);
} catch (BusinessException e) {
jobNameValue = ""; //$NON-NLS-1$
}
copyObjectAction.copyTestCase(testItem, path, jobNameValue, true);
}
}
public String getDuplicateName(RepositoryNode node, String value, ERepositoryObjectType type,

View File

@@ -27,6 +27,7 @@ import org.talend.core.model.properties.ProcessItem;
import org.talend.core.model.repository.ERepositoryObjectType;
import org.talend.core.model.repository.IRepositoryViewObject;
import org.talend.designer.core.model.utils.emf.talendfile.ProcessType;
import org.talend.repository.model.RepositoryNode;
/**
* created by hwang on Jan 7, 2015 Detailled comment
@@ -79,4 +80,10 @@ public interface ITestContainerProviderService extends IService {
public List<IRepositoryViewObject> listExistingTestCases();
public boolean isDuplicateTestCaseOptionSelected();
public IPath getWorkspaceTopNodePath(RepositoryNode topLevelNode);
public void copyTestCase(Item jobItem, Item testItem, IPath path, String newName, boolean isDuplicate);
public void copyDataFiles(Item newItem, RepositoryNode sourceNode);
}