Commit efb089e6 authored by Adrien's avatar Adrien Committed by Romain Bioteau

feat(export bar) warning and errors messages (#1532)

* When validation processes before bar export, we do  not say anymore
'errors' if there is only warnings on the diagram
* Add validation before build when the action is done from the explorer
parent 539e0ea2
......@@ -44,6 +44,7 @@ updatingServerPort = Updating server port
exportErrorOccuredMsg = Build has failed with the following errors
errorValidationContinueAnywayMessage = \n Do you want to continue anyway?
errorValidationInDiagramToExport=Some errors have been found in diagrams below\:
warningValidationInDiagramToExport=Some warnings have been found in diagrams below\:
loginFailed=Attempt to login with user {0} has failed! Please check that this user exists in the active organization and/or that the password is correct in your run configuration of {1} ({2}).
errorActorMappingGroup = Error in Group definition of following Actor Mapping
running = Running...
......
......@@ -113,6 +113,8 @@ public class Messages extends NLS {
public static String errorValidationInDiagramToExport;
public static String warningValidationInDiagramToExport;
public static String loginFailed;
public static String errorActorMappingGroup;
......@@ -179,7 +181,6 @@ public class Messages extends NLS {
public static String startingEngineServer;
public static String deployingProcessesFrom;
static {
NLS.initializeMessages("messages", Messages.class); //$NON-NLS-1$
}
......
/*******************************************************************************
* Copyright (C) 2018 BonitaSoft S.A.
* BonitaSoft is a trademark of BonitaSoft SA.
* This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
* For commercial licensing information, contact:
* BonitaSoft, 32 rue Gustave Eiffel – 38000 Grenoble
* or BonitaSoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
*******************************************************************************/
package org.bonitasoft.studio.engine.operation;
import java.util.HashSet;
import java.util.Set;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.Parameterization;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
public class ProcessValidationOperation {
private static final String PROCESS_VALIDATION_CMD = "org.bonitasoft.studio.validation.batchValidation";
public IStatus status = ValidationStatus.ok();
private Set<AbstractProcess> processes;
public ProcessValidationOperation(Set<AbstractProcess> processes) {
this.processes = processes;
}
public ProcessValidationOperation(AbstractProcess process) {
processes = new HashSet<>();
processes.add(process);
}
public IStatus getStatus() {
return status;
}
public void run() {
ICommandService cmdService = PlatformUI.getWorkbench().getService(ICommandService.class);
Command cmd = cmdService.getCommand(PROCESS_VALIDATION_CMD);
if (cmd.isEnabled()) {
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
Set<String> procFiles = new HashSet<>();
for (AbstractProcess p : processes) {
Resource eResource = p.eResource();
if (eResource != null) {
procFiles.add(URI.decode(eResource.getURI().lastSegment()));
}
}
Parameterization showReportParam;
try {
showReportParam = new Parameterization(cmd.getParameter("showReport"),
Boolean.FALSE.toString());
Parameterization filesParam = new Parameterization(cmd.getParameter("diagrams"), procFiles.toString());
status = (IStatus) handlerService.executeCommand(
new ParameterizedCommand(cmd, new Parameterization[] { showReportParam, filesParam }), null);
} catch (NotDefinedException | ExecutionException | NotEnabledException | NotHandledException e) {
throw new RuntimeException("An error occured during porocess validation", e);
}
}
}
}
......@@ -17,9 +17,12 @@ package org.bonitasoft.studio.engine.ui.contributionItem;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.jface.ValidationDialog;
import org.bonitasoft.studio.diagram.custom.contributionItem.ListProcessContributionItem;
import org.bonitasoft.studio.engine.i18n.Messages;
import org.bonitasoft.studio.engine.operation.ExportBarOperation;
import org.bonitasoft.studio.engine.operation.ProcessValidationOperation;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
......@@ -37,20 +40,41 @@ public class BuildProcessContributionItem extends ListProcessContributionItem {
protected Listener createSelectionListener(AbstractProcess process) {
return e -> {
getPath(Display.getDefault().getActiveShell()).ifPresent(path -> {
ExportBarOperation exportBarOperation = getExportOperation();
exportBarOperation.addProcessToDeploy(process);
exportBarOperation.setTargetFolder(path);
try {
PlatformUI.getWorkbench().getProgressService().run(true, false, exportBarOperation);
displayOperatonStatus(exportBarOperation, path, process.getName());
} catch (InvocationTargetException | InterruptedException e1) {
throw new RuntimeException(
String.format("An error occurred while building bar for process %s", process.getName()), e1);
if (validateBeforExport(process)) {
ExportBarOperation exportBarOperation = getExportOperation();
exportBarOperation.addProcessToDeploy(process);
exportBarOperation.setTargetFolder(path);
try {
PlatformUI.getWorkbench().getProgressService().run(true, false, exportBarOperation);
displayOperatonStatus(exportBarOperation, path, process.getName());
} catch (InvocationTargetException | InterruptedException e1) {
throw new RuntimeException(
String.format("An error occurred while building bar for process %s", process.getName()), e1);
}
}
});
};
}
private boolean validateBeforExport(AbstractProcess process) {
ProcessValidationOperation processValidationOperation = new ProcessValidationOperation(process);
processValidationOperation.run();
IStatus status = processValidationOperation.getStatus();
if (status.getSeverity() == IStatus.ERROR || status.getSeverity() == IStatus.WARNING) {
if (!FileActionDialog.getDisablePopup()) {
String generalMessage = status.getSeverity() == IStatus.ERROR ? Messages.errorValidationInDiagramToExport
: Messages.warningValidationInDiagramToExport;
String errorMessage = String.format("%s\n%s%s", generalMessage, process.getName(),
Messages.errorValidationContinueAnywayMessage);
return new ValidationDialog(Display.getDefault().getActiveShell(),
Messages.validationFailedTitle, errorMessage,
ValidationDialog.YES_NO).open() != ValidationDialog.NO;
}
}
return true;
}
protected ExportBarOperation getExportOperation() {
return new ExportBarOperation();
}
......
Markdown is supported
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