Commit 13dc22c8 authored by Adrien's avatar Adrien Committed by Romain Bioteau
Browse files

feat(bos_import) wording + integration test (#280)

* wording
* integration test

closes BS-16134
parent 9a7a6adc
......@@ -28,6 +28,7 @@ import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
......@@ -52,6 +53,7 @@ import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.bonitasoft.studio.common.repository.operation.ExportBosArchiveOperation;
import org.bonitasoft.studio.common.repository.preferences.RepositoryPreferenceConstant;
import org.bonitasoft.studio.common.repository.store.RepositoryStoreComparator;
import org.bonitasoft.studio.common.repository.ui.ShellNameController;
import org.bonitasoft.studio.pics.Pics;
import org.eclipse.core.internal.resources.ProjectDescriptionReader;
import org.eclipse.core.resources.IContainer;
......@@ -83,7 +85,6 @@ import org.eclipse.jdt.internal.core.ClasspathValidation;
import org.eclipse.jdt.internal.core.JavaProject;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.xml.sax.InputSource;
......@@ -222,7 +223,7 @@ public class Repository implements IRepository, IJavaContainer {
project.open(NULL_PROGRESS_MONITOR);//Open anyway
}
}
updateStudioShellText();
Display.getDefault().asyncExec(this::updateStudioShellText);
} catch (final CoreException e) {
BonitaStudioLog.error(e);
}
......@@ -237,25 +238,12 @@ public class Repository implements IRepository, IJavaContainer {
return this;
}
protected void updateStudioShellText() {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (PlatformUI.isWorkbenchRunning() && PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null) {
final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
final String currentName = shell.getText();
final int index = currentName.indexOf(" - ");
String newName = index > 0 ? currentName.substring(0, index)
: currentName;
if (!getName()
.equals(RepositoryPreferenceConstant.DEFAULT_REPOSITORY_NAME)) {
newName = newName + " - " + getName();
}
shell.setText(newName);
}
}
});
private void updateStudioShellText() {
if (PlatformUI.isWorkbenchRunning()) {
Optional.ofNullable(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell())
.map(ShellNameController::new)
.ifPresent(controller -> controller.update(RepositoryManager.getInstance().getCurrentRepository()));
}
}
/*
......
/*******************************************************************************
* Copyright (C) 2017 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.common.repository.ui;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.preferences.RepositoryPreferenceConstant;
import org.eclipse.swt.widgets.Shell;
public class ShellNameController {
private Shell shell;
public ShellNameController(Shell shell) {
this.shell = shell;
}
public void update(Repository activeRepository) {
String shellTitle = shell.getText();
final int index = shellTitle.indexOf(" - ");
shellTitle = index > 0 ? shellTitle.substring(0, index)
: shellTitle;
if (!activeRepository.getName()
.equals(RepositoryPreferenceConstant.DEFAULT_REPOSITORY_NAME)) {
shellTitle = shellTitle + " - " + activeRepository.getName();
}
shell.setText(shellTitle);
}
}
......@@ -18,25 +18,32 @@ import org.eclipse.core.databinding.UpdateValueStrategy;
/**
* @author Romain Bioteau
* @deprecated use {@link org.bonitasoft.studio.ui.databinding.UpdateStrategyFactory} instead
*/
@Deprecated
public class UpdateStrategyFactory {
@Deprecated
public static UpdateValueStrategyFactory updateValueStrategy() {
return new UpdateValueStrategyFactory(UpdateValueStrategy.POLICY_UPDATE);
}
@Deprecated
public static UpdateSetStrategyFactory updateSetStrategy() {
return new UpdateSetStrategyFactory(UpdateValueStrategy.POLICY_UPDATE);
}
@Deprecated
public static UpdateValueStrategyFactory neverUpdateValueStrategy() {
return new UpdateValueStrategyFactory(UpdateValueStrategy.POLICY_NEVER);
}
@Deprecated
public static UpdateValueStrategyFactory onRequestUpdateValueStrategy() {
return new UpdateValueStrategyFactory(UpdateValueStrategy.POLICY_ON_REQUEST);
}
@Deprecated
public static UpdateValueStrategyFactory convertUpdateValueStrategy() {
return new UpdateValueStrategyFactory(UpdateValueStrategy.POLICY_CONVERT);
}
......
......@@ -22,7 +22,9 @@ import org.eclipse.core.databinding.validation.IValidator;
/**
* @author Romain Bioteau
* @deprecated use {@link org.bonitasoft.studio.ui.databinding.UpdateValueStrategyFactory} instead
*/
@Deprecated
public class UpdateValueStrategyFactory {
private final UpdateValueStrategy updateValueStrategy;
......
......@@ -37,7 +37,8 @@ Require-Bundle: org.eclipse.ui,
org.bonitasoft.studio.tests-utils;resolution:=optional,
org.eclipse.e4.ui.model.workbench;bundle-version="1.1.0.v20140512-1820",
org.eclipse.e4.core.di,
org.json
org.json,
org.eclipse.jface.databinding
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: org.bonitasoft.engine.bpm.bar,
......
......@@ -4,25 +4,28 @@ skippedValidationMessage=Import successfully completed.\nHowever, diagram valida
importButtonLabel=Import
errorWhileImporting_message=An error occurred during import
errorWhileImporting_title=Error during import
archiveAnalysis=Parsing BOS Archive...
parsingArchive=Parsing BOS Archive...
importFileTitle=Import file
importFileDescription=Import file from another {0}, or from another BPM application
importFileDescription=Import .bos file (6.x and above) from another {0}
selectFileToImport=Select file
browseButton_label=Browse...
invalidFilePath=Invalid file path
importProcessTitle=Import a process
importDetails=Import details
importAll=Import all
overwriteAll=Overwrite all
keepAll = Keep all
archiveColumn=Archive
actionColumn=Action
conflictMessage=Some .bos artifacts conflict with artifacts of the target repository. Manage conflicts by setting the right action to perform for each conflicting artifact.
noConflictMessage=There is no conflicts. It is safe ton import.
conflictMessage=Conflicts have been detected between the archive and the target repository. Manage conflicts by choosing the right actions.
noConflictMessage=There is no conflict. You can import safely
analyseBosArchive=Analysing BOS archive...
importBosArchive=Importing BOS archive...
importBosArchiveTitle=Import BOS archive
overwriteMessage=Import new
overwriteMessage=Overwrite
keepMessage=Keep existing
retrivingDataToImport=Retriving data to import
importing=Importing: {0}
bosArchiveName=Bos archive to import:
\ No newline at end of file
bosArchiveName=Bos archive to import:
skipped=Already exists
alreadyPresent=The content of this archive already exists in your repository. Importing wouldn't have any effect.
errorOccuredWhileParsingBosArchive=An error occurred while parsing the BOS archive content.
import_BOS_desc=Import processes designed with Bonita BPM Studio 6.x and 7.x (.bos)
import_BOS_Name=Bonita 6.x and 7.x
importBosCommandLabel=Import BOS archive...
\ No newline at end of file
importBosCommandLabel=BOS archive...
\ No newline at end of file
......@@ -31,6 +31,7 @@ import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.common.repository.model.IRepositoryStore;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
......@@ -81,7 +82,7 @@ public class BosArchiveTest {
final BosArchive bosArchive = newBosArchive(loadArchiveFile("/customer_support_2.0.bos"));
final ImportArchiveModel importArchiveModel = bosArchive
.toImportModel(createRepository());
.toImportModel(createRepository(), new NullProgressMonitor());
assertThat(importArchiveModel).isNotNull();
assertThat(
......
/**
* 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.importer.bos.operation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import org.eclipse.core.resources.IResource;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
/**
* @author Romain Bioteau
*
*/
@RunWith(MockitoJUnitRunner.class)
public class ImportFolderComparatorTest {
private ImportFolderComparator comparator;
@Mock
private IResource diagramResource;
@Mock
private IResource otherResource;
@Mock
private IResource libResource;
@Mock
private IResource srcResource;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
comparator = new ImportFolderComparator();
when(diagramResource.getName()).thenReturn("diagrams");
when(otherResource.getName()).thenReturn("other");
when(libResource.getName()).thenReturn("lib");
when(srcResource.getName()).thenReturn("src-filter");
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void shoud_diagram_folder_be_in_first_position() throws Exception {
assertThat(comparator.compare(diagramResource, otherResource)).isEqualTo(-1);
assertThat(comparator.compare(otherResource, diagramResource)).isEqualTo(1);
assertThat(comparator.compare(diagramResource, libResource)).isEqualTo(-1);
assertThat(comparator.compare(libResource, diagramResource)).isEqualTo(1);
assertThat(comparator.compare(diagramResource, srcResource)).isEqualTo(-1);
assertThat(comparator.compare(srcResource, diagramResource)).isEqualTo(1);
}
@Test
public void shoud_lib_folder_be_in_second_position() throws Exception {
assertThat(comparator.compare(libResource, otherResource)).isEqualTo(-1);
assertThat(comparator.compare(otherResource, libResource)).isEqualTo(1);
assertThat(comparator.compare(diagramResource, libResource)).isEqualTo(-1);
assertThat(comparator.compare(libResource, diagramResource)).isEqualTo(1);
assertThat(comparator.compare(libResource, srcResource)).isEqualTo(-1);
assertThat(comparator.compare(srcResource, libResource)).isEqualTo(1);
}
@Test
public void shoud_folder_containg_src_be_in_third_position() throws Exception {
assertThat(comparator.compare(srcResource, otherResource)).isEqualTo(-1);
assertThat(comparator.compare(otherResource, srcResource)).isEqualTo(1);
assertThat(comparator.compare(diagramResource, srcResource)).isEqualTo(-1);
assertThat(comparator.compare(srcResource, diagramResource)).isEqualTo(1);
assertThat(comparator.compare(libResource, srcResource)).isEqualTo(-1);
assertThat(comparator.compare(srcResource, libResource)).isEqualTo(1);
}
}
......@@ -18,7 +18,6 @@ import org.bonitasoft.studio.importer.bos.model.AbstractFileModel;
import org.bonitasoft.studio.importer.bos.model.ConflictStatus;
import org.bonitasoft.studio.importer.bos.model.ImportFileStoreModel;
import org.bonitasoft.studio.importer.bos.model.ImportStoreModel;
import org.bonitasoft.studio.importer.bos.provider.ImportModelLabelProvider.ConflictStyler;
import org.eclipse.jface.viewers.StyledString;
import org.junit.Test;
......@@ -26,8 +25,7 @@ public class ImportModelLabelProviderTest {
@Test
public void should_display_folder_name() throws Exception {
final ConflictStyler conflictStyler = mock(ConflictStyler.class);
final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(conflictStyler);
final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(new ImportModelStyler());
final String text = labelProvider.getText(new ImportStoreModel("myRepo", repositoryStore("myRepo")));
......@@ -36,14 +34,28 @@ public class ImportModelLabelProviderTest {
@Test
public void should_apply_conflict_style() throws Exception {
final ConflictStyler conflictStyler = mock(ConflictStyler.class);
final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(conflictStyler);
final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(new ImportModelStyler());
final StyledString styledText = labelProvider.getStyledText(conflictingImportFileModel());
assertThat(styledText.getStyleRanges()).hasSize(1);
}
@Test
public void should_apply_same_content_style() throws Exception {
final ImportModelLabelProvider labelProvider = new ImportModelLabelProvider(new ImportModelStyler());
final StyledString styledText = labelProvider.getStyledText(sameContentImportFileModel());
assertThat(styledText.getStyleRanges()).hasSize(1);
}
private Object sameContentImportFileModel() {
return new ImportFileStoreModel("myArchive/myRepo/myConflictingFile",
new ImportStoreModel("myRepo", null, repositoryStore("myRepo")),
ConflictStatus.SAME_CONTENT);
}
private AbstractFileModel conflictingImportFileModel() {
return new ImportFileStoreModel("myArchive/myRepo/myConflictingFile",
new ImportStoreModel("myRepo", null, repositoryStore("myRepo")),
......
package org.bonitasoft.studio.importer.bos.handler;
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.bonitasoft.studio.common.Messages.bonitaStudioModuleName;
import static org.bonitasoft.studio.ui.wizard.WizardPageBuilder.newPage;
......@@ -8,8 +7,6 @@ import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.platform.tools.PlatformUtil;
import org.bonitasoft.studio.common.repository.Repository;
import org.bonitasoft.studio.common.repository.RepositoryAccessor;
......@@ -20,40 +17,42 @@ import org.bonitasoft.studio.importer.bos.operation.ImportBosArchiveOperation;
import org.bonitasoft.studio.importer.bos.status.BosImportStatusDialogHandler;
import org.bonitasoft.studio.importer.bos.wizard.ImportBosArchiveControlSupplier;
import org.bonitasoft.studio.importer.ui.dialog.SkippableProgressMonitorJobsDialog;
import org.bonitasoft.studio.ui.dialog.ExceptionDialogHandler;
import org.bonitasoft.studio.ui.wizard.WizardBuilder;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.swt.widgets.Display;
import org.eclipse.jface.wizard.IWizardContainer;
import org.eclipse.swt.widgets.Shell;
public class ImportBosHandler {
@Execute
public void execute(Shell activeShell, RepositoryAccessor repositoryAccessor) {
try {
final ImportBosArchiveControlSupplier bosArchiveControlSupplier = newImportBosArchiveControlSupplier(
repositoryAccessor);
final Optional<ImportArchiveModel> archiveModel = WizardBuilder.<ImportArchiveModel> newWizard()
.withTitle(Messages.importBosArchiveTitle)
.needProgress()
.havingPage(newPage()
.withTitle(Messages.importFileTitle)
.withDescription(
Messages.bind(Messages.importFileDescription, new Object[] { bonitaStudioModuleName }))
.withControl(bosArchiveControlSupplier))
.onFinish(() -> onFinishOperation(bosArchiveControlSupplier, repositoryAccessor))
.open(activeShell, Messages.importButtonLabel);
public void execute(Shell activeShell, RepositoryAccessor repositoryAccessor,
ExceptionDialogHandler exceptionDialogHandler) {
final ImportBosArchiveControlSupplier bosArchiveControlSupplier = newImportBosArchiveControlSupplier(
repositoryAccessor, exceptionDialogHandler);
final Optional<ImportArchiveModel> archiveModel = WizardBuilder.<ImportArchiveModel> newWizard()
.withTitle(Messages.importBosArchiveTitle)
.needProgress()
.havingPage(newPage()
.withTitle(Messages.importBosArchiveTitle)
.withDescription(
Messages.bind(Messages.importFileDescription, new Object[] { bonitaStudioModuleName }))
.withControl(bosArchiveControlSupplier))
.onFinish(container -> onFinishOperation(bosArchiveControlSupplier, repositoryAccessor, container))
.open(activeShell, Messages.importButtonLabel);
try {
archiveModel
.ifPresent(model -> importArchive(activeShell, model, new File(bosArchiveControlSupplier.getFilePath()),
repositoryAccessor));
} catch (final RuntimeException re) {
new BonitaErrorDialog(Display.getCurrent().getActiveShell(), "Runtime Exception",
re.getMessage(), re).open();
} catch (final Throwable t) {
exceptionDialogHandler.openErrorDialog(activeShell, Messages.errorWhileImporting_message, t);
}
}
protected Optional<ImportArchiveModel> onFinishOperation(ImportBosArchiveControlSupplier bosArchiveControlSupplier,
RepositoryAccessor repositoryAccessor) {
RepositoryAccessor repositoryAccessor, IWizardContainer container) {
return Optional.ofNullable(bosArchiveControlSupplier.getArchiveModel());
}
......@@ -65,29 +64,27 @@ public class ImportBosHandler {
try {
progressManager.run(true, false, operation);
} catch (final InvocationTargetException | InterruptedException e) {
final Throwable t = e instanceof InvocationTargetException
? ((InvocationTargetException) e).getTargetException() : e;
BonitaStudioLog.error("Import has failed.", e);
String message = Messages.errorWhileImporting_message;
if (t != null && !isNullOrEmpty(t.getMessage())) {
message = t.getMessage();
}
new BonitaErrorDialog(activeShell, Messages.errorWhileImporting_title, message, e)
.open();
throw new RuntimeException(e);
}
operation.openFilesToOpen();
PlatformUtil.openIntroIfNoOtherEditorOpen();
activeShell.getDisplay().asyncExec(() -> new BosImportStatusDialogHandler(operation.getStatus(),
repositoryAccessor.getRepositoryStore(DiagramRepositoryStore.class))
.open(activeShell));
activeShell.getDisplay().asyncExec(() -> openEndImportDialog(operation.getStatus(),
repositoryAccessor.getRepositoryStore(DiagramRepositoryStore.class), activeShell,
repositoryAccessor.getCurrentRepository().getName()));
}
protected void openEndImportDialog(IStatus status, DiagramRepositoryStore store, Shell activeShell,
String repositoryName) {
new BosImportStatusDialogHandler(status, store).open(activeShell);
}
protected Repository getTargetRepository(RepositoryAccessor repositoryAccessor) {
return repositoryAccessor.getCurrentRepository();
}
protected ImportBosArchiveControlSupplier newImportBosArchiveControlSupplier(RepositoryAccessor repositoryAccessor) {
return new ImportBosArchiveControlSupplier(repositoryAccessor);
protected ImportBosArchiveControlSupplier newImportBosArchiveControlSupplier(RepositoryAccessor repositoryAccessor,
ExceptionDialogHandler exceptionDialogHandler) {
return new ImportBosArchiveControlSupplier(repositoryAccessor, exceptionDialogHandler);
}
}
......@@ -38,7 +38,7 @@ public class Messages extends NLS {
public static String invalidFilePath;
public static String importProcessTitle;
public static String importDetails;
public static String importAll;
public static String overwriteAll;
public static String keepAll;
public static String archiveColumn;
public static String actionColumn;
......@@ -49,9 +49,12 @@ public class Messages extends NLS {
public static String importBosArchiveTitle;
public static String overwriteMessage;
public static String keepMessage;
public static String archiveAnalysis;
public static String parsingArchive;
public static String retrivingDataToImport;
public static String importing;
public static Object bosArchiveName;
public static String bosArchiveName;
public static String skipped;
public static String alreadyPresent;
public static String errorOccuredWhileParsingBosArchive;
}
......@@ -41,12 +41,22 @@ public abstract class AbstractImportModel {
if (parent.isPresent() && isConflicting() && !parent.get().isConflicting()) {
parent.get().setStatus(status);
}
if (parent.isPresent() && hasSameContent()) {
if (parent.get().getFiles().stream().allMatch(AbstractFileModel::hasSameContent)
&& parent.get().getFolders().stream().allMatch(AbstractFolderModel::hasSameContent)) {
parent.get().setStatus(status);
}
}
}
public boolean isConflicting() {
return status == ConflictStatus.CONFLICTING;
}
public boolean hasSameContent() {
return status == ConflictStatus.SAME_CONTENT;
}
protected Optional<IRepositoryStore<IRepositoryFileStore>> getParentRepositoryStore() {
final Optional<AbstractFolderModel> folder = getParent();
return folder.flatMap(this::getParentStoreModel);
......