Commit 8b6e3ba2 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-9737

Display import status with validation errors
parent 7b8067c2
......@@ -37,3 +37,6 @@ creatingStore=Loading {0} store...
initializingProjectClasspath=Initializing project classpath...
writePermission=Write permission is denied for {0}
exportFailed=Export failed
importResultTitle=Import result
issueFoundIn=issue found in
issuesFoundIn=issues found in
\ No newline at end of file
......@@ -67,6 +67,13 @@ public final class Messages extends NLS {
public static String writePermission;
public static String exportFailed;
public static String importResultTitle;
public static String importSucessfulMessage;
public static String issueFoundIn;
public static String issuesFoundIn;
private Messages() {
// Do not instantiate
}
......
......@@ -38,25 +38,18 @@ public class ImportArtifactsFromZip extends AbstractHandler {
public static final String FILE_EXTENSION = ".bos";
// private AbstractRepositoryArtifact[] importedArtifacts;
public ImportArtifactsFromZip() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
public Object execute(final ExecutionEvent event) throws ExecutionException {
final FileDialog dialog = new FileDialog(Display.getDefault().getActiveShell(), SWT.OPEN);
dialog.setText(Messages.importedRepository_title);
dialog.setFilterExtensions(new String[] { "*" + FILE_EXTENSION }); //$NON-NLS-1$
final String workspaceArchiveFile = dialog.open();
if (workspaceArchiveFile != null) {
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
final IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
final IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
final ImportBosArchiveOperation operation = new ImportBosArchiveOperation();
operation.setArchiveFile(workspaceArchiveFile);
operation.setCurrentRepository(RepositoryManager.getInstance().getCurrentRepository());
......@@ -66,7 +59,7 @@ public class ImportArtifactsFromZip extends AbstractHandler {
try {
progressService.run(true, false, runnable);
} catch (Exception e) {
} catch (final Exception e) {
new BonitaErrorDialog(Display.getDefault().getActiveShell(), Messages.importRepositoryFailedTitle, Messages.importRepositoryFailedMsg,
new org.eclipse.core.runtime.Status(IStatus.ERROR, "org.bonitasoft.studio.repository.ex", e.getMessage(), e), IStatus.ERROR).open();
BonitaStudioLog.error(e);
......
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.repository.operation;
import java.util.ArrayList;
import java.util.List;
import org.bonitasoft.studio.common.repository.CommonRepositoryPlugin;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
/**
* @author Romain Bioteau
*
*/
public class BosArchiveImportStatus extends MultiStatus {
public BosArchiveImportStatus() {
super(CommonRepositoryPlugin.PLUGIN_ID, 0, null, null);
}
public List<AbstractProcess> getProcessesWithErrors() {
final List<AbstractProcess> processes = new ArrayList<AbstractProcess>();
for (final IStatus child : getChildren()) {
if (child instanceof ProcessValidationStatus && !child.isOK()) {
processes.add(((ProcessValidationStatus) child).getProcess());
}
}
return processes;
}
}
......@@ -72,7 +72,6 @@ public class ImportBosArchiveOperation {
private static final String TMP_IMPORT_PROJECT = "tmpImport";
private IStatus status;
private String archiveFile;
......@@ -84,8 +83,9 @@ public class ImportBosArchiveOperation {
private final List<AbstractProcess> importedProcesses = new ArrayList<AbstractProcess>();
private BosArchiveImportStatus importStatus;
public IStatus run(final IProgressMonitor monitor) {
status = Status.OK_STATUS;
Assert.isNotNull(archiveFile);
Assert.isNotNull(currentRepository);
final File archive = new File(archiveFile);
......@@ -153,19 +153,29 @@ public class ImportBosArchiveOperation {
}
cleanTmpProject();
}
return status;
return Status.OK_STATUS;
}
public IStatus getValidationsStatus() {
return importStatus;
}
private void validateAllAfterImport() {
Display.getDefault().syncExec(new Runnable() {
final ImportBosArchiveStatusBuilder statusBuilder = new ImportBosArchiveStatusBuilder();
for (final AbstractProcess process : importedProcesses) {
final ProcessesValidationAction validationAction = new ProcessesValidationAction(Collections.singletonList(process));
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
final ProcessesValidationAction validationAction = new ProcessesValidationAction(importedProcesses);
validationAction.performValidation();
}
});
@Override
public void run() {
validationAction.performValidation();
}
});
statusBuilder.addStatus(process, validationAction.getStatus());
}
importStatus = statusBuilder.done();
}
public void setCurrentRepository(final IRepository currentRepository) {
......@@ -338,10 +348,6 @@ public class ImportBosArchiveOperation {
return null;
}
public IStatus getStatus() {
return status;
}
public void setArchiveFile(final String archiveFile) {
this.archiveFile = archiveFile;
}
......
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.repository.operation;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.eclipse.core.runtime.IStatus;
/**
* @author Romain Bioteau
*
*/
public class ImportBosArchiveStatusBuilder {
private final BosArchiveImportStatus status;
public ImportBosArchiveStatusBuilder() {
status = new BosArchiveImportStatus();
}
public ImportBosArchiveStatusBuilder addStatus(final AbstractProcess process, final IStatus status) {
this.status.add(new ProcessValidationStatus(process, status));
return this;
}
public BosArchiveImportStatus done() {
return status;
}
}
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.repository.operation;
import org.bonitasoft.studio.common.repository.Messages;
import org.bonitasoft.studio.model.process.AbstractProcess;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
* @author Romain Bioteau
*
*/
public class ProcessValidationStatus extends Status {
private final AbstractProcess process;
private final IStatus validationStatus;
public ProcessValidationStatus(final AbstractProcess process, final IStatus status) {
super(status.getSeverity(), status.getPlugin(), status.getMessage());
this.process = process;
validationStatus = status;
}
@Override
public String getMessage() {
if (validationStatus.isMultiStatus()) {
final int issues = countIssues();
if (issues == 1) {
return countIssues() + " " + Messages.issueFoundIn + " " + process.getName() + " (" + process.getVersion() + ") ";
}
return issues + " " + Messages.issuesFoundIn + " " + process.getName() + " (" + process.getVersion() + ") ";
}
return process.getName() + " (" + process.getVersion() + ")";
}
protected int countIssues() {
int count = validationStatus.getChildren().length;
for (final IStatus child : validationStatus.getChildren()) {
if (child.getSeverity() == INFO || child.isOK()) {
count--;
}
}
return count;
}
@Override
public boolean isOK() {
return getSeverity() == IStatus.OK || getSeverity() == IStatus.INFO;
}
public AbstractProcess getProcess() {
return process;
}
}
......@@ -81,7 +81,7 @@ public class ProcessesValidationAction {
return false;
} else {
if (result == ValidationDialog.SEE_DETAILS) {
activateValidationPart();
showValidationPart();
return false;
}
}
......@@ -97,14 +97,18 @@ public class ProcessesValidationAction {
final int result = new ValidationDialog(Display.getDefault().getActiveShell(), Messages.validationFailedTitle, errorMessage,
ValidationDialog.OK_SEEDETAILS).open();
if (result == ValidationDialog.SEE_DETAILS) {
activateValidationPart();
showValidationPart();
}
}
return true;
}
public IStatus getStatus() {
return status;
}
public void activateValidationPart(){
public static void showValidationPart() {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final IEditorPart part = activePage.getActiveEditor();
if (part != null && part instanceof DiagramEditor) {
......
......@@ -403,4 +403,8 @@ public class DiagramFileStore extends EMFFileStore implements IRepositoryFileSto
return values != null && values[0] != null;
}
public boolean isOpened() {
return getOpenedEditor() != null;
}
}
......@@ -41,7 +41,6 @@ import org.bonitasoft.studio.common.ProductVersion;
import org.bonitasoft.studio.common.ProjectUtil;
import org.bonitasoft.studio.common.emf.tools.EMFResourceUtil;
import org.bonitasoft.studio.common.emf.tools.ModelHelper;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.CopyInputStream;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
......@@ -60,7 +59,6 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.FeatureNotFoundException;
import org.eclipse.emf.edapt.history.Release;
import org.eclipse.emf.edapt.migration.MigrationException;
......@@ -71,7 +69,6 @@ import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.gmf.runtime.notation.util.NotationAdapterFactory;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
......@@ -230,18 +227,6 @@ public class DiagramRepositoryStore extends
return null;
}
private boolean processExistInList(final AbstractProcess ip,
final List<AbstractProcess> processes) {
for (final AbstractProcess p : processes) {
if (ip.getName().equals(p.getName())
&& ip.getVersion().equals(p.getVersion())
&& !EcoreUtil.equals(ip, p)) {
return true;
}
}
return false;
}
@Override
protected DiagramFileStore doImportIResource(final String fileName,
final IResource resource) {
......@@ -257,50 +242,9 @@ public class DiagramRepositoryStore extends
return null;
}
if (!FileActionDialog.getDisablePopup()) {
final List<AbstractProcess> importedProcess = ModelHelper
.getAllProcesses(content);
final List<AbstractProcess> duplicateProcess = findDuplicatedProcess(importedProcess);
if (!duplicateProcess.isEmpty()) {
openWarningForDuplicatedProcess(duplicateProcess);
}
}
return fileStore;
}
private List<AbstractProcess> findDuplicatedProcess(
final List<AbstractProcess> importedProcess) {
final List<AbstractProcess> processes = getAllProcesses();
final List<AbstractProcess> duplicateProcess = new ArrayList<AbstractProcess>();
for (final AbstractProcess p : importedProcess) {
if (processExistInList(p, processes)) {
duplicateProcess.add(p);
}
}
return duplicateProcess;
}
private void openWarningForDuplicatedProcess(
final List<AbstractProcess> duplicateProcess) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
final StringBuilder sb = new StringBuilder();
for (final AbstractProcess p : duplicateProcess) {
sb.append(SWT.CR);
sb.append(p.getName() + " " + "(" + p.getVersion() + ")");
}
MessageDialog.openWarning(
Display.getDefault().getActiveShell(),
Messages.warningDuplicateDialogTitle, Messages.bind(
Messages.poolAlreadyExistWarningMessage,
sb.toString()));
}
});
}
@Override
protected DiagramFileStore doImportInputStream(final String fileName,
final InputStream inputStream) {
......
......@@ -5,12 +5,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
......@@ -20,23 +20,23 @@ import java.io.File;
import java.net.URL;
import java.util.List;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.operation.ImportBosArchiveOperation;
import org.bonitasoft.studio.importer.processors.ToProcProcessor;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.URI;
/**
* @author Romain Bioteau
*
*
*/
public class BosArchiveProcessor extends ToProcProcessor {
private ImportBosArchiveOperation operation;
public BosArchiveProcessor(String resourceName) {
public BosArchiveProcessor(final String resourceName) {
}
......@@ -45,7 +45,7 @@ public class BosArchiveProcessor extends ToProcProcessor {
* @see org.bonitasoft.studio.importer.ToProcProcessor#createDiagram(java.net.URL, org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public File createDiagram(URL sourceFileURL, IProgressMonitor progressMonitor) throws Exception {
public File createDiagram(final URL sourceFileURL, final IProgressMonitor progressMonitor) throws Exception {
final File archiveFile = new File(URI.decode(sourceFileURL.getFile()));
operation = new ImportBosArchiveOperation();
operation.setArchiveFile(archiveFile.getAbsolutePath());
......@@ -54,6 +54,11 @@ public class BosArchiveProcessor extends ToProcProcessor {
return null;
}
@Override
public IStatus getStatus() {
return operation.getValidationsStatus();
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.importer.ToProcProcessor#getResources()
......
......@@ -13,3 +13,8 @@ importProcessProgressDialog=Importing diagram...
errorWhileImporting_message=An error occurred during import
errorWhileImporting_title=Error during import
ImportProcessButtonLabel=Import
importResultTitle=Import status
importSucessfulMessage=Import finish without errors.
processesWithErrorAfterImport=Imported processes contains validation errors:
openDiagramWithErrors=You can open diagrams with issues for the details.
openDiagram=Open diagrams
\ No newline at end of file
......@@ -47,6 +47,7 @@ import org.bonitasoft.studio.common.ExpressionConstants;
import org.bonitasoft.studio.common.NamingUtils;
import org.bonitasoft.studio.common.ProjectUtil;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.importer.ImporterPlugin;
import org.bonitasoft.studio.importer.builder.IProcBuilder;
import org.bonitasoft.studio.importer.builder.IProcBuilder.DataType;
import org.bonitasoft.studio.importer.builder.IProcBuilder.EventType;
......@@ -63,6 +64,9 @@ import org.bonitasoft.studio.model.process.Data;
import org.bonitasoft.studio.model.process.ProcessFactory;
import org.bonitasoft.studio.model.process.diagram.edit.parts.MainProcessEditPart;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
......@@ -162,7 +166,7 @@ public class BPMNToProc extends ToProcProcessor {
private List<BPMNPlane> bpmnProcessDiagrams;
private BPMNShape subProc;
private List<TProcess> bpmnProcess;
private final List<Object> errorElements = new ArrayList<Object>();
// private final List<Object> errorElements = new ArrayList<Object>();
private TDefinitions definitions;
private EList<TRootElement> rootElements;
protected Diagram diagram;
......@@ -236,6 +240,7 @@ public class BPMNToProc extends ToProcProcessor {
public File createDiagram(URL sourceBPMNUrl, final IProgressMonitor progressMonitor) {
progressMonitor.beginTask(Messages.importFromBPMN,
IProgressMonitor.UNKNOWN);
status = new MultiStatus(ImporterPlugin.PLUGIN_ID, 0, null, null);
builder = new ProcBuilder(progressMonitor);
InputStream stream = null;
......@@ -374,9 +379,9 @@ public class BPMNToProc extends ToProcProcessor {
*/
final String convertedQName = nodeValue.replace(
'/', '_').replace(':', '_');
errorElements.add("invalid QName of tagName "
status.add(new Status(IStatus.ERROR, ImporterPlugin.PLUGIN_ID, "invalid QName of tagName "
+ tagName + ": " + nodeValue
+ " converted to " + convertedQName);
+ " converted to " + convertedQName));
sourceNode.setNodeValue(convertedQName);
hadBeenPreProcessed = true;
<