Commit 6a421ff4 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

feat(deploy) Deploy after import if no error detected (#1851)

Covers BST-457
parent 4f3dbc06
......@@ -46,7 +46,8 @@ Require-Bundle: org.eclipse.ui,
org.bonitasoft.studio.designer,
org.eclipse.jdt.launching,
org.eclipse.core.databinding.property;bundle-version="1.6.100",
org.bonitasoft.studio.businessobject
org.bonitasoft.studio.businessobject,
org.eclipse.e4.core.commands
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: org.bonitasoft.engine.bpm.bar,
......
......@@ -14,19 +14,23 @@
*/
package org.bonitasoft.studio.importer.bos.status;
import java.util.HashMap;
import org.bonitasoft.studio.diagram.custom.repository.DiagramFileStore;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.importer.handler.DefaultImportStatusDialogHandler;
import org.bonitasoft.studio.importer.handler.ImportStatusDialog;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.validation.common.operation.RunProcessesValidationOperation;
import org.eclipse.core.commands.ParameterizedCommand;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.e4.core.commands.ECommandService;
import org.eclipse.e4.core.commands.EHandlerService;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
/**
* @author Romain Bioteau
*/
public class BosImportStatusDialogHandler extends DefaultImportStatusDialogHandler {
private final DiagramRepositoryStore store;
......@@ -48,11 +52,22 @@ public class BosImportStatusDialogHandler extends DefaultImportStatusDialogHandl
importStatus instanceof BosArchiveImportStatus
&& !((BosArchiveImportStatus) importStatus).getProcessesWithErrors().isEmpty());
final int result = messageDialog.open();
if (importStatus instanceof BosArchiveImportStatus && result == IDialogConstants.OPEN_ID) {
openDiagrams((BosArchiveImportStatus) importStatus);
if (importStatus instanceof BosArchiveImportStatus) {
if (result == IDialogConstants.OPEN_ID) {
openDiagrams((BosArchiveImportStatus) importStatus);
} else if (result == IDialogConstants.PROCEED_ID) {
executeCommand("org.bonitasoft.studio.application.command.deployArtifacts");
}
}
}
private void executeCommand(String command) {
ECommandService eCommandService = PlatformUI.getWorkbench().getService(ECommandService.class);
EHandlerService eHandlerService = PlatformUI.getWorkbench().getService(EHandlerService.class);
ParameterizedCommand parameterizedCommand = eCommandService.createCommand(command, new HashMap<>());
eHandlerService.executeHandler(parameterizedCommand);
}
protected void openDiagrams(final BosArchiveImportStatus bosArchiveStatus) {
for (final AbstractProcess process : bosArchiveStatus.getProcessesWithErrors()) {
final DiagramFileStore diagramFileStore = store.getDiagram(process.getName(), process.getVersion());
......
......@@ -47,7 +47,7 @@ public class DiagramValidator implements BosImporterStatusProvider {
new ValidationMarkerProvider()));
validationAction.addProcess(process);
validationAction.run(monitor);
if (validationAction.getStatus() != null && validationAction.getStatus().isOK()) {
if (validationAction.getStatus() != null && !validationAction.getStatus().isOK()) {
statusBuilder.addStatus(process, validationAction.getStatus());
}
} catch (final ReadFileStoreException | InvocationTargetException | InterruptedException e) {
......
......@@ -19,4 +19,5 @@ seeDetails=See details
skipValidation=Skip validation >>
importStatusMsg=Problems have been detected in imported content.
copyToClipboard=Copy to clipboard
invalidFilePath=Invalid file path
\ No newline at end of file
invalidFilePath=Invalid file path
deploy=Deploy...
\ No newline at end of file
......@@ -49,10 +49,7 @@ public class DefaultImportStatusDialogHandler implements ImportStatusDialogHandl
} else {
switch (importStatus.getSeverity()) {
case IStatus.OK:
MessageDialog.openInformation(parentShell,
org.bonitasoft.studio.importer.i18n.Messages.importResultTitle,
customSuccessMessage
.orElse(org.bonitasoft.studio.importer.i18n.Messages.importSucessfulMessage));
openImportStatus(parentShell, customSuccessMessage.orElse(org.bonitasoft.studio.importer.i18n.Messages.importSucessfulMessage));
break;
case IStatus.INFO:
openImportStatus(parentShell, customSuccessMessage
......
......@@ -17,6 +17,9 @@ package org.bonitasoft.studio.importer.handler;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Lists.newArrayList;
import java.util.ArrayList;
import java.util.List;
import org.bonitasoft.studio.importer.i18n.Messages;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
......@@ -53,25 +56,30 @@ public class ImportStatusDialog extends MessageDialog {
public ImportStatusDialog(final Shell parentShell, final IStatus importStatus, String message, final boolean canOpen) {
super(parentShell, org.bonitasoft.studio.importer.i18n.Messages.importResultTitle, null,
message,
NONE,
getLabels(canOpen), 0);
importStatus.isOK() ? MessageDialog.INFORMATION : NONE,
getLabels(canOpen,importStatus), 0);
this.importStatus = importStatus;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#getInitialSize()
*/
@Override
protected Point getInitialSize() {
return getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
}
protected static String[] getLabels(final boolean canOpen) {
if (canOpen) {
return new String[] { Messages.seeDetails, IDialogConstants.OK_LABEL, Messages.copyToClipboard };
protected static String[] getLabels(final boolean canOpen, IStatus status) {
List<String> buttons =new ArrayList<>();
if(canOpen) {
buttons.add(Messages.seeDetails);
}
if(status.getSeverity() != IStatus.ERROR) {
buttons.add(Messages.deploy);
}
return new String[] { IDialogConstants.OK_LABEL, Messages.copyToClipboard };
buttons.add(IDialogConstants.OK_LABEL);
if(!status.isOK()) {
buttons.add( Messages.copyToClipboard);
}
return buttons.toArray(new String[] {});
}
@Override
......@@ -83,11 +91,6 @@ public class ImportStatusDialog extends MessageDialog {
problemsViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).indent(0, 10).create());
problemsViewer.setContentProvider(ArrayContentProvider.getInstance());
problemsViewer.setComparator(new ViewerComparator() {
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
return Integer.compare(((IStatus) e2).getSeverity(), ((IStatus) e1).getSeverity());
......@@ -95,19 +98,11 @@ public class ImportStatusDialog extends MessageDialog {
});
problemsViewer.setLabelProvider(new LabelProvider() {
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
return ((IStatus) element).getMessage();
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
*/
@Override
public Image getImage(Object element) {
switch (((IStatus) element).getSeverity()) {
......@@ -156,6 +151,9 @@ public class ImportStatusDialog extends MessageDialog {
if (Messages.seeDetails.equals(label)) {
return super.createButton(parent, IDialogConstants.OPEN_ID, label, defaultButton);
}
if (Messages.deploy.equals(label)) {
return super.createButton(parent, IDialogConstants.PROCEED_ID, label, defaultButton);
}
if (Messages.copyToClipboard.equals(label)) {
final Button copyButton = super.createButton(parent, IDialogConstants.NO_ID, label, defaultButton);
copyButton.addSelectionListener(new SelectionAdapter() {
......
......@@ -47,5 +47,6 @@ public class Messages extends NLS {
public static String importStatusMsg;
public static String copyToClipboard;
public static String invalidFilePath;
public static String deploy;
}
......@@ -180,8 +180,6 @@ public class BatchValidationOperation extends WorkspaceModifyOperation {
String fileName = target.getName();
fileName = fileName.substring(0, fileName.lastIndexOf("."));
addStatusForMarkerType(target, result, fileName, ProcessMarkerNavigationProvider.MARKER_TYPE);
addStatusForMarkerType(target, result, fileName,
org.bonitasoft.studio.model.process.diagram.providers.ProcessMarkerNavigationProvider.MARKER_TYPE);
fileProcessed.add(target);
}
......
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