Commit d350daa4 authored by Romain Bioteau's avatar Romain Bioteau
Browse files

BS-10326

parent e0f7b517
......@@ -69,17 +69,17 @@ public class ExportBosArchiveHandler extends AbstractHandler {
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
public Object execute(final ExecutionEvent event) throws ExecutionException {
if(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(true)){
Set<Object> selectedFiles = new HashSet<Object>() ;
MainProcess diagram = getDiagramInEditor();
final MainProcess diagram = getDiagramInEditor();
if(diagram != null){
selectedFiles = getAllDiagramRelatedFiles(diagram);
}else{
for(IRepositoryStore<? extends IRepositoryFileStore> store : RepositoryManager.getInstance().getCurrentRepository().getAllExportableStores()){
List<? extends IRepositoryFileStore> files = store.getChildren() ;
for(final IRepositoryStore<? extends IRepositoryFileStore> store : RepositoryManager.getInstance().getCurrentRepository().getAllExportableStores()){
final List<? extends IRepositoryFileStore> files = store.getChildren() ;
if( files != null){
for(IRepositoryFileStore fStore : files){
for(final IRepositoryFileStore fStore : files){
if(fStore != null){
selectedFiles.add(fStore) ;
}
......@@ -89,10 +89,11 @@ public class ExportBosArchiveHandler extends AbstractHandler {
}
final ExportRepositoryWizard wizard = new ExportRepositoryWizard(RepositoryManager.getInstance().getCurrentRepository().getAllExportableStores(),true,selectedFiles,getDefaultName(),Messages.ExportButtonLabel) ;
WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(),wizard){
final WizardDialog dialog = new WizardDialog(Display.getDefault().getActiveShell(),wizard){
@Override
protected void initializeBounds() {
super.initializeBounds();
getShell().setSize(600, 500);
getShell().setSize(600, 500);
}
};
dialog.setTitle(Messages.ExportButtonLabel);
......@@ -109,36 +110,36 @@ public class ExportBosArchiveHandler extends AbstractHandler {
return NamingUtils.toDiagramFilename(diagram).replace(".proc", ".bos");
}
public Set<Object> getAllDiagramRelatedFiles(MainProcess diagram) {
public static Set<Object> getAllDiagramRelatedFiles(final MainProcess diagram) {
final Set<Object> result = new HashSet<Object>() ;
final List<Pool> processes = ModelHelper.getAllItemsOfType(diagram, ProcessPackage.Literals.POOL) ;
final List<IBOSArchiveFileStoreProvider> fileStoreProvider = getFileStoreProviders() ;
for(Pool p : processes){
Configuration conf = getConfiguration(p, ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON) ;
for(IBOSArchiveFileStoreProvider provider : fileStoreProvider){
for(final Pool p : processes){
final Configuration conf = getConfiguration(p, ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON) ;
for(final IBOSArchiveFileStoreProvider provider : fileStoreProvider){
result.addAll(provider.getFileStoreForConfiguration(p, conf)) ;
for(Configuration config : p.getConfigurations()){
for(final Configuration config : p.getConfigurations()){
result.addAll(provider.getFileStoreForConfiguration(p, config)) ;
}
}
}
if(processes.isEmpty()){
DiagramRepositoryStore dStore = (DiagramRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
final DiagramRepositoryStore dStore = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
result.add(dStore.getDiagram(diagram.getName(), diagram.getVersion()));
}
return result;
}
private List<IBOSArchiveFileStoreProvider> getFileStoreProviders() {
List<IBOSArchiveFileStoreProvider> res = new ArrayList<IBOSArchiveFileStoreProvider>();
IConfigurationElement[] extensions = BonitaStudioExtensionRegistryManager.getInstance().getConfigurationElements(BOS_ARCHIVE_PROVIDERS_EXTENSION_POINT);
for (IConfigurationElement extension : extensions) {
private static List<IBOSArchiveFileStoreProvider> getFileStoreProviders() {
final List<IBOSArchiveFileStoreProvider> res = new ArrayList<IBOSArchiveFileStoreProvider>();
final IConfigurationElement[] extensions = BonitaStudioExtensionRegistryManager.getInstance().getConfigurationElements(BOS_ARCHIVE_PROVIDERS_EXTENSION_POINT);
for (final IConfigurationElement extension : extensions) {
try {
res.add((IBOSArchiveFileStoreProvider)extension.createExecutableExtension("providerClass"));
} catch (Exception ex) {
} catch (final Exception ex) {
BonitaStudioLog.error(ex);
}
}
......@@ -149,35 +150,35 @@ public class ExportBosArchiveHandler extends AbstractHandler {
if( PlatformUI.getWorkbench().getWorkbenchWindows() == null || PlatformUI.getWorkbench().getWorkbenchWindows().length == 0){
return null ;
}
IEditorPart editor = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getActiveEditor() ;
boolean isADiagram = editor != null && editor instanceof DiagramEditor;
final IEditorPart editor = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getActiveEditor() ;
final boolean isADiagram = editor != null && editor instanceof DiagramEditor;
if(isADiagram){
EObject root = ((DiagramEditor)editor).getDiagramEditPart().resolveSemanticElement() ;
MainProcess mainProc = ModelHelper.getMainProcess(root) ;
final EObject root = ((DiagramEditor)editor).getDiagramEditPart().resolveSemanticElement() ;
final MainProcess mainProc = ModelHelper.getMainProcess(root) ;
return mainProc ;
}
return null;
}
public Configuration getConfiguration(final AbstractProcess process,String configurationId) {
public static Configuration getConfiguration(final AbstractProcess process, String configurationId) {
Configuration configuration = null ;
final ProcessConfigurationRepositoryStore processConfStore = (ProcessConfigurationRepositoryStore) RepositoryManager.getInstance().getRepositoryStore(ProcessConfigurationRepositoryStore.class) ;
final ProcessConfigurationRepositoryStore processConfStore = RepositoryManager.getInstance().getRepositoryStore(ProcessConfigurationRepositoryStore.class) ;
if(configurationId == null){
configurationId = ConfigurationPlugin.getDefault().getPreferenceStore().getString(ConfigurationPreferenceConstants.DEFAULT_CONFIGURATION) ;
}
if(configurationId.equals(ConfigurationPreferenceConstants.LOCAL_CONFIGURAITON)){
String id = ModelHelper.getEObjectID(process) ;
final String id = ModelHelper.getEObjectID(process) ;
IRepositoryFileStore file = processConfStore.getChild(id+".conf") ;
if(file == null){
file = processConfStore.createRepositoryFileStore(id+".conf") ;
Configuration conf = ConfigurationFactory.eINSTANCE.createConfiguration();
final Configuration conf = ConfigurationFactory.eINSTANCE.createConfiguration();
conf.setVersion(ModelVersion.CURRENT_VERSION);
file.save(conf);
}
configuration = (Configuration) file.getContent();
}else{
for(Configuration conf : process.getConfigurations()){
for(final Configuration conf : process.getConfigurations()){
if(configurationId.equals(conf.getName())){
configuration = conf ;
}
......
......@@ -7,6 +7,7 @@ Bundle-Activator: org.bonitasoft.studio.migration.tests.Activator
Bundle-Vendor: BonitaSoft S.A.
Require-Bundle: org.eclipse.core.runtime,
org.junit;bundle-version="4.8.2",
assertj-core;bundle-version="1.5.0",
org.bonitasoft.studio.importer;bundle-version="1.0.0",
org.bonitasoft.studio.common.repository;bundle-version="1.0.0",
org.bonitasoft.studio.common;bundle-version="1.0.0",
......@@ -22,7 +23,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.swtbot.junit4_x;bundle-version="2.0.5",
org.bonitasoft.studio.importer.bar.tests;bundle-version="1.0.0",
org.bonitasoft.studio.diagram.custom;bundle-version="1.0.0",
org.bonitasoft.studio.migration;bundle-version="1.0.0"
org.bonitasoft.studio.migration;bundle-version="1.0.0",
org.bonitasoft.studio.swtbot.framework;bundle-version="6.4.0",
org.bonitasoft.studio.exporter
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Export-Package: org.bonitasoft.studio.migration.tests
/**
* Copyright (C) 2012 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.migration.tests;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
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.ExportBosArchiveOperation;
import org.bonitasoft.studio.diagram.custom.repository.DiagramRepositoryStore;
import org.bonitasoft.studio.exporter.handler.ExportBosArchiveHandler;
import org.bonitasoft.studio.model.process.MainProcess;
import org.bonitasoft.studio.swtbot.framework.application.BotApplicationWorkbenchWindow;
import org.bonitasoft.studio.swtbot.framework.diagram.BotProcessDiagramPerspective;
import org.bonitasoft.studio.swtbot.framework.draw.BotGefProcessDiagramEditor;
import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.swtbot.eclipse.gef.finder.SWTBotGefTestCase;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
/**
* @author Romain Bioteau
*
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public class ExportImportWithoutMigrationIT extends SWTBotGefTestCase {
@Rule
public TemporaryFolder folder = new TemporaryFolder();
@Override
@Before
public void setUp() throws Exception{
bot.saveAllEditors();
bot.closeAllEditors();
}
@Override
@After
public void tearDown() throws Exception {
bot.saveAllEditors();
bot.closeAllEditors();
}
@Test
public void should_export_and_import_of_a_diagram_do_not_trigger_migration() throws Exception {
final BotApplicationWorkbenchWindow workbenchWindow = new BotApplicationWorkbenchWindow(bot);
final BotProcessDiagramPerspective newDiagram = workbenchWindow.createNewDiagram();
final BotGefProcessDiagramEditor diagramEditor = newDiagram.activeProcessDiagramEditor();
diagramEditor.selectDiagram();
final EObject originalSemanticElement = diagramEditor.getSelectedSemanticElement();
assertThat(originalSemanticElement).isInstanceOf(MainProcess.class);
final ExportBosArchiveOperation exportBosArchiveOperation = new ExportBosArchiveOperation();
final File destFolder = folder.newFolder();
destFolder.mkdirs();
final File bosFile = new File(destFolder,"test.bos");
exportBosArchiveOperation.setDestinationPath(bosFile.getAbsolutePath());
final Set<Object> allDiagramRelatedFiles = ExportBosArchiveHandler.getAllDiagramRelatedFiles((MainProcess) originalSemanticElement);
final Set<IResource> resources = new HashSet<IResource>();
for (final Object filestore : allDiagramRelatedFiles) {
if (filestore instanceof IRepositoryFileStore) {
resources.add(((IRepositoryFileStore) filestore).getResource());
}
}
assertThat(resources).isNotEmpty();
exportBosArchiveOperation.setResources(resources);
assertThat(bosFile.exists()).isFalse();
exportBosArchiveOperation.run(Repository.NULL_PROGRESS_MONITOR);
assertThat(bosFile.exists()).isTrue();
//delete diagram
final DiagramRepositoryStore diagramRepositoryStore = RepositoryManager.getInstance().getRepositoryStore(DiagramRepositoryStore.class);
diagramRepositoryStore.getDiagram(((MainProcess) originalSemanticElement).getName(), ((MainProcess) originalSemanticElement).getVersion());
}
}
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