Commit 15147865 authored by azara's avatar azara
Browse files

BS-9145

At the bottom of the migration report, redirect to validation status

refactor runProcessCommand to extract methods for validation call.
create class for validation
add validation when click  exit import mode
parent d07b168c
......@@ -303,5 +303,7 @@ dataListViewerTitle=Data
searchIndexListViewerTitle=Search index
parameterListTitle=Parameter
widgetListViewerTitle=Widget
outlineDialogRefactoringText=Here are the references found for the {0}\:
removalConfirmationDialogTitle=Removal confirmation
outlineDialogRefactoringText=Here are the references found for theerrorValidationMessage=Some errors have been found in the diagram
errorValidationContinueAnywayMessage=\n Do you want to continue anyway? {0}\:
errorValidationMessage = Some errors have been found in the diagram
validationFailedTitle=Some errors have been found in the diagram
\ No newline at end of file
......@@ -346,4 +346,9 @@ public class Messages extends NLS {
public static String widgetListViewerTitle;
public static String outlineDialogRefactoringText;
public static String removalConfirmationDialogTitle;
public static String errorValidationMessage;
public static String errorValidationContinueAnywayMessage;
public static String validationFailedTitle;
}
......@@ -19,12 +19,14 @@ package org.bonitasoft.studio.engine.command;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.bonitasoft.studio.common.ProcessesValidationAction;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.jface.FileActionDialog;
......@@ -137,66 +139,72 @@ public class RunProcessCommand extends AbstractHandler implements IHandler {
final Set<AbstractProcess> executableProcesses = getProcessesToDeploy(event);
if (BonitaStudioPreferencesPlugin.getDefault().getPreferenceStore().getBoolean(BonitaPreferenceConstants.VALIDATION_BEFORE_RUN)) {
List<AbstractProcess> processes = new ArrayList<AbstractProcess>(executableProcesses);
ProcessesValidationAction validationOperation = new ProcessesValidationAction( processes);
validationOperation.performValidation();
if (!validationOperation.displayConfirmationDialog()){
return null;
}
// Validate before run
final ICommandService cmdService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
Command cmd = cmdService.getCommand("org.bonitasoft.studio.validation.batchValidation");
if (cmd.isEnabled()) {
final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
Set<String> procFiles = new HashSet<String>();
for (AbstractProcess p : executableProcesses) {
Resource eResource = p.eResource();
if (eResource != null) {
procFiles.add(URI.decode(eResource.getURI().lastSegment()));
}
}
try {
Parameterization showReportParam = new Parameterization(cmd.getParameter("showReport"), Boolean.FALSE.toString());
Parameterization filesParam = new Parameterization(cmd.getParameter("diagrams"), procFiles.toString());
final IStatus status = (IStatus) handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[] { showReportParam,
filesParam }), null);
if (statusContainsError(status)) {
if (!FileActionDialog.getDisablePopup()) {
String errorMessage = Messages.errorValidationMessage
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getTitle()
+ Messages.errorValidationContinueAnywayMessage;
int result = new ValidationDialog(Display.getDefault().getActiveShell(), Messages.validationFailedTitle, errorMessage,
ValidationDialog.YES_NO_SEEDETAILS).open();
if (result == ValidationDialog.NO) {
return null;
} else if (result == ValidationDialog.SEE_DETAILS) {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart part = activePage.getActiveEditor();
if (part != null && part instanceof DiagramEditor) {
MainProcess proc = ModelHelper.getMainProcess(((DiagramEditor) part).getDiagramEditPart().resolveSemanticElement());
String partName = proc.getName() + " (" + proc.getVersion() + ")";
for (IEditorReference ref : activePage.getEditorReferences()) {
if (partName.equals(ref.getPartName())) {
activePage.activate(ref.getPart(true));
break;
}
}
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
activePage.showView("org.bonitasoft.studio.validation.view");
} catch (PartInitException e) {
BonitaStudioLog.error(e);
}
}
});
return null;
}
}
}
} catch (Exception e) {
BonitaStudioLog.error(e);
}
}
// final ICommandService cmdService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
// Command cmd = cmdService.getCommand("org.bonitasoft.studio.validation.batchValidation");
// if (cmd.isEnabled()) {
// final IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
// Set<String> procFiles = new HashSet<String>();
// for (AbstractProcess p : executableProcesses) {
// Resource eResource = p.eResource();
// if (eResource != null) {
// procFiles.add(URI.decode(eResource.getURI().lastSegment()));
// }
// }
// try {
// Parameterization showReportParam = new Parameterization(cmd.getParameter("showReport"), Boolean.FALSE.toString());
// Parameterization filesParam = new Parameterization(cmd.getParameter("diagrams"), procFiles.toString());
// final IStatus status = (IStatus) handlerService.executeCommand(new ParameterizedCommand(cmd, new Parameterization[] { showReportParam,
// filesParam }), null);
// if (statusContainsError(status)) {
// if (!FileActionDialog.getDisablePopup()) {
// String errorMessage = Messages.errorValidationMessage
// + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getTitle()
// + Messages.errorValidationContinueAnywayMessage;
// int result = new ValidationDialog(Display.getDefault().getActiveShell(), Messages.validationFailedTitle, errorMessage,
// ValidationDialog.YES_NO_SEEDETAILS).open();
// if (result == ValidationDialog.NO) {
// return null;
// } else if (result == ValidationDialog.SEE_DETAILS) {
// final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
// IEditorPart part = activePage.getActiveEditor();
// if (part != null && part instanceof DiagramEditor) {
// MainProcess proc = ModelHelper.getMainProcess(((DiagramEditor) part).getDiagramEditPart().resolveSemanticElement());
// String partName = proc.getName() + " (" + proc.getVersion() + ")";
// for (IEditorReference ref : activePage.getEditorReferences()) {
// if (partName.equals(ref.getPartName())) {
// activePage.activate(ref.getPart(true));
// break;
// }
// }
//
// }
// Display.getDefault().asyncExec(new Runnable() {
//
// @Override
// public void run() {
// try {
// activePage.showView("org.bonitasoft.studio.validation.view");
// } catch (PartInitException e) {
// BonitaStudioLog.error(e);
// }
// }
// });
// return null;
// }
//
// }
// }
// } catch (Exception e) {
// BonitaStudioLog.error(e);
// }
// }
}
IRunnableWithProgress runnable = new IRunnableWithProgress() {
......
......@@ -18,8 +18,15 @@
package org.bonitasoft.studio.migration.ui.view;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bonitasoft.studio.common.ProcessesValidationAction;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.jface.TableColumnSorter;
import org.bonitasoft.studio.common.jface.ValidationDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.perspectives.BonitaPerspectivesUtils;
import org.bonitasoft.studio.migration.MigrationPlugin;
......@@ -32,8 +39,14 @@ import org.bonitasoft.studio.migration.ui.action.HideReviewedAction;
import org.bonitasoft.studio.migration.ui.action.HideValidStatusAction;
import org.bonitasoft.studio.migration.ui.action.ToggleLinkingAction;
import org.bonitasoft.studio.migration.ui.wizard.MigrationWarningWizard;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.MainProcess;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.command.SetCommand;
......@@ -90,11 +103,15 @@ import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.views.properties.IPropertySheetPage;
......@@ -207,8 +224,13 @@ public class MigrationStatusView extends ViewPart implements ISelectionListener,
"toggleStateForImportExportStatus");
if(IDialogConstants.OK_ID== mdwt.getReturnCode()){
if(mdwt.getToggleState()){
exportAction.run();
exportAction.run();
}
IEditorPart editorPart = getSite().getPage().getActiveEditor();
List<AbstractProcess> processes = getProcesses(editorPart);
ProcessesValidationAction validation = new ProcessesValidationAction(processes);
validation.performValidation();
validation.displayOkSeeMoreDetailsDialog();
try {
clearMigrationReport(true);
} catch (IOException e1) {
......@@ -223,6 +245,9 @@ public class MigrationStatusView extends ViewPart implements ISelectionListener,
}
});
}
private void clearMigrationReport(boolean save) throws IOException{
final IEditorPart editorPart = (IEditorPart) tableViewer.getInput();
......@@ -588,6 +613,16 @@ public class MigrationStatusView extends ViewPart implements ISelectionListener,
return null;
}
private List<AbstractProcess> getProcesses(IEditorPart editorPart){
if(editorPart instanceof DiagramEditor){
DiagramEditor diagramEditor = (DiagramEditor)editorPart;
MainProcess diagram = (MainProcess)diagramEditor.getDiagramEditPart().resolveSemanticElement();
List<AbstractProcess> procs = ModelHelper.getAllProcesses(diagram);
return procs;
}
return null;
}
@SuppressWarnings("rawtypes")
@Override
public Object getAdapter(Class adapter) {
......
......@@ -75,7 +75,8 @@ public class MigrationReporTest extends SWTBotGefTestCase {
bot.waitUntil(Conditions.shellIsActive(Messages.completeImport));
bot.checkBox().deselect();
bot.button(IDialogConstants.OK_LABEL).click();
bot.waitUntil(Conditions.shellIsActive(org.bonitasoft.studio.common.Messages.validationFailedTitle));
bot.button(IDialogConstants.OK_LABEL).click();
assertEquals("Invalid perspective for process without migration report", "org.bonitasoft.studio.perspective.process",
BonitaPerspectivesUtils.getPerspectiveId(bot.activeEditor().getReference().getEditor(false)));
EObject mainProcess = (EObject) bot.gefEditor(bot.activeEditor().getTitle()).mainEditPart().part().getModel();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment